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.
Fixes yiisoft#5442: Fixed problem on load fixture dependencies with d…
…atabase related tests
- Loading branch information
1 parent
9c0274d
commit 25242ad
Showing
9 changed files
with
74 additions
and
13 deletions.
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
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
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,9 +9,18 @@ | |
use yiiunit\data\ar\Customer; | ||
use yiiunit\framework\db\DatabaseTestCase; | ||
|
||
class ProfileFixture extends ActiveFixture | ||
{ | ||
public $modelClass = 'yiiunit\data\ar\Profile'; | ||
} | ||
|
||
class CustomerFixture extends ActiveFixture | ||
{ | ||
public $modelClass = 'yiiunit\data\ar\Customer'; | ||
|
||
public $depends = [ | ||
'yiiunit\framework\test\ProfileFixture' | ||
]; | ||
} | ||
|
||
class MyDbTestCase | ||
|
@@ -20,8 +29,7 @@ class MyDbTestCase | |
|
||
public function setUp() | ||
{ | ||
$this->unloadFixtures(); | ||
$this->loadFixtures(); | ||
$this->initFixtures(); | ||
} | ||
|
||
public function tearDown() | ||
|
@@ -34,17 +42,15 @@ public function fixtures() | |
'customers' => CustomerFixture::className(), | ||
]; | ||
} | ||
|
||
public function globalFixtures() | ||
{ | ||
return [ | ||
InitDbFixture::className(), | ||
]; | ||
} | ||
} | ||
|
||
abstract class ActiveFixtureTest extends DatabaseTestCase | ||
/** | ||
* @group fixture | ||
*/ | ||
class ActiveFixtureTest extends DatabaseTestCase | ||
{ | ||
protected $driverName = 'mysql'; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
@@ -63,12 +69,17 @@ public function testGetData() | |
$test = new MyDbTestCase(); | ||
$test->setUp(); | ||
$fixture = $test->getFixture('customers'); | ||
|
||
$this->assertEquals(CustomerFixture::className(), get_class($fixture)); | ||
$this->assertCount(2, $fixture); | ||
$this->assertEquals(1, $fixture['customer1']['id']); | ||
$this->assertEquals('[email protected]', $fixture['customer1']['email']); | ||
$this->assertEquals(1, $fixture['customer1']['profile_id']); | ||
|
||
$this->assertEquals(2, $fixture['customer2']['id']); | ||
$this->assertEquals('[email protected]', $fixture['customer2']['email']); | ||
$this->assertEquals(2, $fixture['customer2']['profile_id']); | ||
|
||
$test->tearDown(); | ||
} | ||
|
||
|
@@ -77,11 +88,16 @@ public function testGetModel() | |
$test = new MyDbTestCase(); | ||
$test->setUp(); | ||
$fixture = $test->getFixture('customers'); | ||
|
||
$this->assertEquals(Customer::className(), get_class($fixture->getModel('customer1'))); | ||
$this->assertEquals(1, $fixture->getModel('customer1')->id); | ||
$this->assertEquals('[email protected]', $fixture->getModel('customer1')->email); | ||
$this->assertEquals(1, $fixture['customer1']['profile_id']); | ||
|
||
$this->assertEquals(2, $fixture->getModel('customer2')->id); | ||
$this->assertEquals('[email protected]', $fixture->getModel('customer2')->email); | ||
$this->assertEquals(2, $fixture['customer2']['profile_id']); | ||
|
||
$test->tearDown(); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -6,11 +6,13 @@ | |
'name' => 'customer1', | ||
'address' => 'address1', | ||
'status' => 1, | ||
'profile_id' => 1 | ||
], | ||
'customer2' => [ | ||
'email' => '[email protected]', | ||
'name' => 'customer2', | ||
'address' => 'address2', | ||
'status' => 2, | ||
'profile_id' => 2 | ||
], | ||
]; |
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,12 @@ | ||
<?php | ||
|
||
return [ | ||
'profile1' => [ | ||
'id' => 1, | ||
'description' => 'profile 1', | ||
], | ||
'profile2' => [ | ||
'id' => 2, | ||
'description' => 'profile 2', | ||
], | ||
]; |