Home » Php » php – CakePHP 3: Unable to insert fixtures when running phpunit

php – CakePHP 3: Unable to insert fixtures when running phpunit

Posted by: admin July 12, 2020 Leave a comment

Questions:

I just baked some Fixtures and some TestCases and whenever I run vendor/bin/phpunit I get a version of the following error:

$ vendor/bin/phpunit
PHPUnit 4.7.7 by Sebastian Bergmann and contributors.

IException: Unable to insert fixtures for "App\Test\TestCase\Controller\ScreensControllerTest" test case. SQLSTATE[HY000] [2002] No such file or directory in [/Applications/MAMP/htdocs/myapp/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureManager.php, line 254]

The fixtures and tests were baked automatically using the bake tools. I checked that each item in the $fixtures property corresponds to a file in tests/Fixture/. If I comment out the $fixtures declaration in any of the test classes the error just moves to the next class. So it’s not bad syntax in any specific fixture/test.

How to&Answers:

This error means that PHP is not able to connect to the database. If you are using a SQLite database, make sure the directory is writable and exists.