codeception does not see dump.sql
codeception, mysql, php, yii
Solution
Make sure that Db module is enabled for your suit configuration.
Then you need to run `codecept build` before using methods of Db module.
Generally you should run it every time you enable or disable modules in test suit configuration.
Problem
I'm using Yii2 with Codeception. The problem is that Codeception seems to not see the database dump. For simplicity, I consider only LoginCept acceptance tests: ``` use tests\_pages\LoginPage; $I = new WebGuy($scenario); $I->wantTo('ensure that login works'); $loginPage = LoginPage::openBy($I); $I->see('Login', 'h1'); $I->amGoingTo('try to login with empty credentials'); $loginPage->login('', ''); $I->expectTo('see validations errors'); $I->see('Username cannot be blank.'); $I->see('Password cannot be blank.'); ... ``` So, when I run ``` ./vendor/bin/codecept run tests/acceptance/LoginCept.php ``` everything runs without errors: ``` Acceptance Tests (1) ---------------------------------------- Trying to ensure that login works (LoginCept.php) Ok ------------------------------------------------------------- ``` But as soon as I add the following line ``` echo $I->grabFromDatabase('user', 'name', ['id' => 1]); ``` the test starts to fail: ``` Acceptance Tests (1) ---------------------------------------- Trying to ensure that login works (LoginCept.php) Error ------------------------------------------------------------- Time: 2.11 seconds, Memory: 9.75Mb There was 1 error: --------- 1) Failed to ensure that login works in LoginCept.php #1 F:\site\tests\acceptance\LoginCept.php:8 <-- 8 is the number of added line #2 F:\site\tests\acceptance\LoginCept.php:8 FAILURES! ``` Below I put the detailed info from config files. codeception.yml file has the following content: ``` paths: tests: tests log: tests/_log data: tests/_data helpers: tests/_helpers settings: bootstrap: _bootstrap.php suite_class: \PHPUnit_Framework_TestSuite memory_limit: 1024M log: true colors: true modules: enabled: [Db] config: Db: dsn: 'mysql:host=localhost;dbname=site_test' user: 'daemon' password: 'HsqyJSAbZC3q3KJa' dump: 'tests/_data/dump.sql' populate: true cleanup: true ``` The print out of \Yii::$app->db gives: ``` yii\db\Connection Object ( [dsn] => mysql:host=localhost;dbname=site_test [username] => daemon [password] => HsqyJSAbZC3q3KJa [attributes] => [pdo] => [enableSchemaCache] => [schemaCacheDuration] => 3600 ... ) ``` With the credentials above, I can log in manually to my database (in phpmyadmin). The database dump is located in `F:\site\tests\_data\dump.sql`. I've created it from my working database called site and made some modification inside it: ``` CREATE DATABASE IF NOT EXISTS `site_test` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; USE `site_test`; DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` smallint(5), `name` varchar(50) ); INSERT INTO `user` VALUES (1,'admin'); ``` Codeception build command everytime I run it, gives: ``` $ ./vendor/bin/codecept build Building Guy classes for suites: acceptance, functional, unit WebGuy includes modules: WebHelper, PhpBrowser WebGuy.php generated successfully. 48 methods added TestGuy includes modules: Filesystem, TestHelper, Yii2 TestGuy.php generated successfully. 53 methods added CodeGuy includes modules: CodeHelper CodeGuy.php generated successfully. 1 methods added ```