Mar 29, 2015
0
Level 1
Unit Test Models with Sqlite
Hi folks,
I am newbie php and Laravel developer. I am trying to do unit testing of my models but I'm not sure about what configuration I need for Laravel 5.
I followed this guide but is not working for me: (https://laracasts.com/lessons/test-databases-in-memory)
This is my test (at the moment is not doing anything):
class UserModelTest extends TestCase {
/**
* A basic functional test example.
*
* @return void
*/
public function testBasicExample()
{
User::create([
'name' => 'me',
'email' => 'email'
]);
}
}
And I've put under config/testing a new database.php file:
return [
'default' => 'sqlite',
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => ':memory',
'prefix' => '',
],
],
];
But when I ran phpunit I got:
PDOException: SQLSTATE[HY000] [2002] No such file or directory
/laravel-example/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:47
/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:20
/laravel-example/vendor/compiled.php:10742
/laravel-example/vendor/compiled.php:10738
I presume that is not picking the right environment.
Any idea?
Thanks in advance!
Please or to participate in this conversation.