Skip to content

Instantly share code, notes, and snippets.

@m8rge
Created July 2, 2015 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m8rge/353bf459a740e8eb767c to your computer and use it in GitHub Desktop.
Save m8rge/353bf459a740e8eb767c to your computer and use it in GitHub Desktop.
Yii2 db fixtures from array
<?php
namespace tests\codeception\common\unit;
use Codeception\Specify;
use yii\di\Instance;
use yii\test\InitDbFixture;
/**
* usage:
* $this->loadLocalFixtures([
* PlaceFixture::className() => [
* ['id' => 1, 'filling' => Place::FILL_PARTIAL, 'shipmentId' => 1],
* ],
* TaskFixture::className() => [
* ['placeId' => 1],
* ['placeId' => 2],
* ],
* ]);
*/
class DbTestCase extends \yii\codeception\DbTestCase
{
use Specify;
public $appConfig = '@tests/codeception/config/common/unit.php';
public function loadLocalFixtures($fixtures)
{
foreach ($fixtures as $className => &$fixture) {
$fixturePrepared = [];
$fixturePrepared['data'] = $fixture;
$fixturePrepared['dataFile'] = false;
$fixturePrepared['class'] = $className;
$fixture = $fixturePrepared;
}
unset($fixture);
array_unshift($fixtures, InitDbFixture::className()); // disables db integrity check
parent::loadFixtures($this->createFixtures($fixtures));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment