Laravel 4 PHPUnit Sqlite Database, delete items before every test -


i have laravel 4 application sqlite db configured testing.

i working in workbench package

i have problem testing models in phpunit test, because defined unique properties on model. run artisan::call('migrate', array('--bench' => 'vendor/webshop')); basic test class extend other tests.

i think runs database migrations, in opinion not delete models in database.

because if

public function setup() {      parent::setup();      $this->order = order::create(array(         "uniquekey" = "123"     )); } 

i error saying, can not insert model because of violation of unique key rule.

how should clean database before every test?

you should define environment testing purposes.

actually laravel have 1 - notice testing folder inside app/config.

create app/config/testing/database.php (or modify if exists) , place this:

return array(      'default' => 'sqlite',      'connections' => array(          'sqlite' => array(             'driver'   => 'sqlite',             'database' => ':memory:', // trick ;)             'prefix'   => '',         ),     ), ); 

when run tests, laravel sets it's environment 'testing' automaticaly - no need play this. sqlite in-memory db memory stored withing ram, it's fast - , yes, tests start empty database well.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -