Setup a database connection and create the tester classes (php vendor/bin/codecept build)
Create foo.php and bar.php files in tests/_data directory, the data they return is irrelevant
Create the test class
<?php
// tests/unit/FooTest.php
use yii\test\ArrayFixture;
class FooTest extends \Codeception\Test\Unit
{
/**
* @var \UnitTester
*/
protected $tester;
public function _fixtures()
{
return [
'foo' => [
'class' => ArrayFixture::class,
'dataFile' => codecept_data_dir('foo.php')
],
'bar' => [
'class' => ArrayFixture::class,
'dataFile' => codecept_data_dir('bar.php')
]
];
}
// tests
public function testSomeFeature()
{
// holds foo fixture data
$this->tester->grabFixture('bar');
// throws [ModuleException] Yii2: Fixture foo is not loaded
$this->tester->grabFixture('foo');
}
}
Run the test php vendor/bin/codecept run unit -- FooTest
What is the expected result?
Both foo and bar fixtures are loaded with correct data
What do you get instead?
Only bar fixture is loaded but with wrong data
Additional info
The issue seems to come from how FixtureTrait assigns aliases to fixtures. Each class will only have 1 alias, in this case 'yii\test\ArrayFixture' => 'bar'. First it creates bar instance with foo fixture config. Next iteration when it tries to create the bar fixture, it skips it since since bar named instance already exists.
What steps will reproduce the problem?
php vendor/bin/codecept build
)foo.php
andbar.php
files intests/_data
directory, the data they return is irrelevantCreate the test class
php vendor/bin/codecept run unit -- FooTest
What is the expected result?
Both
foo
andbar
fixtures are loaded with correct dataWhat do you get instead?
Only
bar
fixture is loaded but with wrong dataAdditional info
The issue seems to come from how FixtureTrait assigns aliases to fixtures. Each class will only have 1 alias, in this case
'yii\test\ArrayFixture' => 'bar'
. First it createsbar
instance withfoo
fixture config. Next iteration when it tries to create thebar
fixture, it skips it since sincebar
named instance already exists.