-
Notifications
You must be signed in to change notification settings - Fork 19
Testing
Testing is a way of ensuring your code works and that when it breaks you will know. Ideally you should test all your methods, code coverage should be 100% percento.
The tests have been hooked up to Travis which is a service that pulls our repo, runs the commands on travis.yaml and runs the test. If the tests don't pass an email will be sent to whoever made the commit (configurable).
The DB is in memory sqlite, its harder, better, faster stronger. Access just as you would mysql as eloquent abstracts the dirty details.
Currently we are testing controllers, since most of the functionality lives there.
- To do: Test models and views
Here are a few steps to follow when testing, this is not exhaustive please experiment with other ways.
- Create your test class and extend Testcase.
- Initialize you variable and other stuff in
setup( )
i.e
Artisan::call('migrate')
and Artisan::call('db:seed')
- For sending POST to a controller method do
$this->action('POST', 'HomeController@index', array('name'=>'Vito Corleone'))
- Does the controller method require a parameter, no worries just put the named parameter to your array, laravel magically handles that.
$this->action('POST', 'HomeController@index', array('name'=>'Vito Corleone', 'id'=>'235'))
- Some of the things to test for
-
assertRedirectedToRoute()
test that your function redirected properly -
assertSessionHasErrors('email')
check that the session has errors for a particular key.
Generally create the test then make the functionality, if you get an error create a test that fails, fix the error and make sure the test passes.
More info in the laravel docs here