Hope Everyone is doing great.
I have a problem. I need to get my fixtures loaded in db before running acceptance test in codception in my Yii2 Application. here is teh detail for it.
Target: Load fixtures in database so that I can run acceptance tests on them.
Problem: Despite of my a at most efforts, I am still I am unable to achieve this affect
Here is the data that I got to share with you:
common\modules\myCustomModule\tests\acceptance\models\DashboardCest ```
class ResumeDashboardCest
{
public function _before(AcceptanceTester $I)
{
$I->haveFixtures([
'country' => [
'class' => CountryFixture::className(),
'dataFile' => codecept_data_dir() . 'country_data.php',
],
'region' => [
'class' => RegionFixture::className(),
'dataFile' => codecept_data_dir() . 'region_data.php',
],
'city' => [
'class' => CityFixture::className(),
'dataFile' => codecept_data_dir() . 'city_data.php',
],
'user_group' => [
'class' => UserGroupFixture::className(),
'dataFile' => codecept_data_dir() . 'user_group.php',
],
'user' => [
'class' => UserFixture::className(),
'dataFile' => codecept_data_dir() . 'user.php',
],
'status' => [
'class' => StatusFixture::className(),
'dataFile' => codecept_data_dir() . 'status_data.php',
],
'resume' => [
'class' => ResumeFixture::className(),
'dataFile' => codecept_data_dir() . 'resume_data.php'
],
]);
// initialize the module first
// fill in the login page before performing my main test
$I->amGoingTo("Login in My Application");
$I->amOnPage(Url::toRoute('/site/login'));
$I->fillField('#loginform-username', 'admin');
$I->fillField('#loginform-password', 'gulabmehak');
$I->click('.btn-success'); // The login button
$I->wait(3); // wait for 3 seconds meanwhile bakend processing is complete
$I->dontSee('Incorrect username or password.');
}
// my test function
public function load_HomePage(AcceptanceTester $I)
{
$I->amOnPage( Url::toRoute('/'.\Yii::$app->params['ModuleName'].'/resume/index') );
$I->see(T::t('main', 'My Resumes'));
$I->see(T::t('main', 'My Resumes'), 'ul.breadcrumb li.active');
}
}
Here is the fixture for country common\modules\myCustomModule\tests\fixtures\CountryFixture
class CountryFixture extends \yii\test\ActiveFixture
{
public $modelClass = 'common\modules\location\models\Country'; // the model for this belongs to another module
public function beforeLoad() {
parent::beforeLoad();
$this->db->createCommand()->setSql('SET FOREIGN_KEY_CHECKS = 0')->execute();
}
public function afterLoad() {
parent::afterLoad();
$this->db->createCommand()->setSql('SET FOREIGN_KEY_CHECKS = 1')->execute();
}
}
same goes for the rest of fixture files but I've eliminated them for ease.
Here is the data (fixture data) file: common\modules\myCustomModule\tests\data\country_data.php
<?php
return [
[
'name' => 'Pakistan',
'iso' => 'PK',
'status' => 1,
],
[
'name' => 'China',
'iso' => 'CH',
'status' => 1,
],
[
'name' => 'United States of America',
'iso' => 'US',
'status' => 1,
],
[
'name' => 'Saudi Arabia',
'iso' => 'SA',
'status' => 1,
],
[
'name' => 'Japan',
'iso' => 'JP',
'status' => 1,
],
];
for just in case you need my configurations: common\modules\myCustomModule\tests\acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- Yii2:
part:
[init, orm, fixtures]
config:
db:
populate: false
cleanup: false
WebDriver:
url: 'http://localhost/myProject/'
browser: phantomjs
window_size: 1920x1310
capabilities:
webStorageEnabled: true
Codeception: 2.2.9 Yii2 application version: 2.0.12 composer: 1.4.2 Also I am using PhantomJs for testing
Please let me know of any questions. Stay Blessed.