forked from yiisoft/yii2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(yiisoft#8298) Restart sequence for Postgresql when loading fixtures
- Loading branch information
Showing
3 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
use Yii; | ||
use yii\db\Connection; | ||
use yii\di\Instance; | ||
use yii\test\ActiveFixture; | ||
use yii\test\FixtureTrait; | ||
use yiiunit\data\ar\ActiveRecord; | ||
|
@@ -55,6 +56,36 @@ public function testGetData() | |
$test->tearDown(); | ||
} | ||
|
||
/** | ||
* Testing the use of offset fixtures | ||
* @return void | ||
* @throws \yii\base\InvalidConfigException | ||
* @throws \yii\db\Exception | ||
*/ | ||
public function testOffsetGetData() | ||
{ | ||
$test = new CustomerOffsetDbTestCase(); | ||
/** @var Connection $db */ | ||
$db = Instance::ensure('db', Connection::class); | ||
if ('pgsql' === $db->driverName) { | ||
$db->createCommand('alter sequence customer_id_seq start 2 minvalue 2 restart 2;')->execute(); | ||
} | ||
$test->setUp(); | ||
$fixture = $test->getFixture('customers'); | ||
|
||
$this->assertEquals(CustomerFixture::className(), get_class($fixture)); | ||
$this->assertCount(2, $fixture); | ||
$this->assertEquals(2, $fixture['customer1']['id']); | ||
$this->assertEquals('[email protected]', $fixture['customer1']['email']); | ||
$this->assertEquals(1, $fixture['customer1']['profile_id']); | ||
|
||
$this->assertEquals(3, $fixture['customer2']['id']); | ||
$this->assertEquals('[email protected]', $fixture['customer2']['email']); | ||
$this->assertEquals(2, $fixture['customer2']['profile_id']); | ||
|
||
$test->tearDown(); | ||
} | ||
|
||
public function testGetModel() | ||
{ | ||
$test = new CustomerDbTestCase(); | ||
|
@@ -225,6 +256,19 @@ public function fixtures() | |
} | ||
} | ||
|
||
class CustomerOffsetDbTestCase extends BaseDbTestCase | ||
{ | ||
public function fixtures() | ||
{ | ||
return [ | ||
'customers' => [ | ||
'class' => CustomerFixture::className(), | ||
'dataFile' => '@app/framework/test/data/customer_offset_sequence.php', | ||
], | ||
]; | ||
} | ||
} | ||
|
||
class CustomDirectoryDbTestCase extends BaseDbTestCase | ||
{ | ||
public function fixtures() | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* @link https://www.yiiframework.com/ | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @license https://www.yiiframework.com/license/ | ||
*/ | ||
|
||
return [ | ||
'customer1' => [ | ||
'id' => 2, | ||
'email' => '[email protected]', | ||
'name' => 'customer1', | ||
'address' => 'address1', | ||
'status' => 1, | ||
'profile_id' => 1, | ||
], | ||
'customer2' => [ | ||
'id' => 3, | ||
'email' => '[email protected]', | ||
'name' => 'customer2', | ||
'address' => 'address2', | ||
'status' => 2, | ||
'profile_id' => 2, | ||
], | ||
]; |