After doing a lot of googling, I have found a satisfactory solution.
With Cept files, as they dont use classes, you have to include the Yii2 module in the YAML configuration, BUT only the fixtures part.
In acceptance.suite.yml:
modules:
enabled:
- WebDriver
- Yii2:
part:
- init
- fixtures
transaction: false
I am using selenium, so I have also enabled the WebDriver module. I have also found it necessary to set transaction: false
, otherwise my logins didn't work.
(Probably due to the transaction data not being available to the web request)
Then I have to run the build command to make the $I->haveFixtures()
method available.
codeception build
I can now include fixtures as a part of the Cept files thus:
use tests\fixtures\DBAddressFixture;
use tests\fixtures\DBCustomerFixture;
use tests\fixtures\OAuthClientsFixture;
/* @var $scenario Codeception\Scenario */
$I = new AcceptanceTester($scenario);
$I->wantTo("Check that the account information page exists and works");
$I->haveFixtures([
'customer' => DBCustomerFixture::className(),
'address' => DBAddressFixture::className(),
'auth' => OAuthClientsFixture::className()
]);
Regarding Cest Files. Apparently it should be as simple as adding the _fixtures()
method to the Cest class, although I havent tried this.
Here are some Useful links:
Codeception Yii2 Fixtures Documentation
CodeCeption Fixtures Issue 4099
Similar StackOverflow issue 45881907
Yii2 Fixtures Documentation