I've set up a fixture, but Codeception can't find it. What am I missing or doing wrong?
% php vendor/bin/codecept run functional
...
[Error] Class 'myname\tests\fixtures\MyFixture' not found
In the sample code the namespaces are under myname but I've also tried using just tests\fixtures, tests\unit\fixtures, and myname\tests\unit\fixtures.
Thinking it's something to do with the namespace or most likely something to do with the Craft fixtures docs saying
Fixtures…can be defined in the
fixturesMethoddefined in thecodeception.ymlfile.
My codeception.yml doesn't have fixturesMethod. I can imagine that's a way of doing some of this but haven't found any documentation describing what that configuration should look like.
I've also tried loading the fixture on the command line
% ./craft fixture/load ImageAssetFixture
Exception 'yii\base\InvalidConfigException' with message 'Invalid fixture namespace: "tests\unit\fixtures". Please, check your FixtureController::namespace parameter'
% ./craft fixture/load ImageAssetFixture --namespace='myname\tests\fixtures'
Exception 'yii\base\InvalidConfigException' with message 'Invalid fixture namespace: "myname\tests\fixtures". Please, check your FixtureController::namespace parameter'
Here's the setup:
tests/functional/AssetFixtureCest.php
<?php
use FunctionalTester;
use myname\tests\fixtures\MyFixture;
class AssetFixtureCest
{
public function _fixtures()
{
return [
'myFixture' => [
'class' => MyFixture::className(),
'dataFile' => codecept_data_dir() . 'my-fixture.php',
],
];
}
public function testMyFixture(FunctionalTester $I)
{
$myFixture = $I->grabFixture('myFixture');
codecept_debug($myFixture);
}
}
tests/fixtures/MyFixture.php
<?php
namespace myname\tests\fixtures;
use Craft;
use craft\test\fixtures\elements...;
class MyFixture extends ...
{
/**
* {@inheritdoc}
*/
public $dataFile = DIR . '/data/my-fixture.php';
}
test/fixtures/data/my-fixture.php
<?php
return [
...
];