slimphp / Slim-Skeleton

Slim Framework 4 Skeleton Application
http://www.slimframework.com
MIT License
1.59k stars 478 forks source link

Add `tests` directory and example for test #24

Closed oanhnn closed 8 years ago

oanhnn commented 8 years ago

Should we add tests directory and an example for test

class \ExampleTest extends \PHPUnit_Framework_TestCase
{
    public function testBasicExample()
    {
        $this->markTestSkipped('This is an example basic test');
    }
}
oanhnn commented 8 years ago

Like https://github.com/laravel/lumen/blob/master/tests/ExampleTest.php

barrystaes commented 8 years ago

IMHO yes, its always good to include a test that people can use as a reference design.

Run tests on the API codebase? I have no test experience with Slim (or API's for that matter) and i wonder how to test the API endpoints, if their backend is stateful? (a filesystem, a database, and in my case both and then some)

I know of no easy way to facilitate this without actually spawning a DB instance. Another thing is that each test (or battery of tests) should be able to start out with a given dataset. Creating all these DB instances might not be performant or practical..

Run API tests on a contained environment as a whole? This brings me back to the idea that perhaps most testing would take place not on this API codebase, but on the environment that its used in as a whole. I'm not there yet, but i can imagine there's people doing this using visualization they already use for production. (e.g. VM's or Docker containers?)

Insights welcome!

adambro commented 8 years ago

I've made an attempt to write WebTestCase, inspired by Silex. It's actually possible since Slim 3.1 version fixes slimphp/Slim#1688 issue. Would you be interested if I open-source that?

Raistlfiren commented 8 years ago

I agree. I think this would be beneficial for everyone. I don't see any reason to not include it. I do believe that an example functional test would also be useful to extend off of as well. Similar to what @adambro mentioned, creating a WebTestCase.

oanhnn commented 8 years ago

Like https://akrabat.com/testing-slim-framework-actions/

Jovian commented 8 years ago

And..? As a newbie, I vote for this too!

maccath commented 8 years ago

I have taken a stab at this, and will send a pull request imminently. :)