Created
July 2, 2015 03:25
-
-
Save m8rge/353bf459a740e8eb767c to your computer and use it in GitHub Desktop.
Yii2 db fixtures from array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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