I am trying to add records to a database with my models and then check if data exists in a database with DB module with seeInDatabase()
If I use cleanup: true in the unit.yml config for Yii2 module, I can't access inserted data using seeInDatabase()
Provide test source code if related
$I = $this->tester;
BlogCategoriesModel::save(['name' => 'new_test', 'is_active' => 1]); // OK
BlogCategoriesModel::save(['name' => 'new_test2', 'is_active' => 1]); // OK
$I->seeInDatabase('blog_categories', ['name' => 'new_test', 'is_active' => 1]); // FAILS
$I->assertEquals(count(BlogCategoriesModel::getAll()), 2); // OK
composer show)# Codeception Test Suite Configuration
# suite for unit (internal) tests.
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: UnitTester
modules:
enabled: [Db, Asserts, Yii2]
config:
Db:
dsn: 'pgsql:host=postgres;dbname=database'
user: 'user'
password: 'password'
#dump: 'tests/_output/dump.sql'
populate: true
cleanup: true
reconnect: true
Yii2:
cleanup: true
configFile: 'codeception/config/unit.php'
If I use cleanup: true in the unit.yml config for Yii2 module, I can't access inserted data using seeInDatabase()
yep. That's right.
Probably you don't need Db module at all here, use Yii2 module which works great with Yii activerecord. Just use seeRecord instead of seeInDatabase, in this case you will use the same db connection as your application do and this allows Yii2 cleanup to work.
Most helpful comment
yep. That's right.
Probably you don't need Db module at all here, use Yii2 module which works great with Yii activerecord. Just use
seeRecordinstead ofseeInDatabase, in this case you will use the same db connection as your application do and this allows Yii2 cleanup to work.