mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 22:30:27 +08:00
Fixes #5442: Fixed problem on load fixture dependencies with database related tests
This commit is contained in:

committed by
Alexander Makarov

parent
9c0274d249
commit
25242adb91
@ -4,6 +4,10 @@ Yii Framework 2 Change Log
|
|||||||
2.0.12 under development
|
2.0.12 under development
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
|
- Enh #13820: Add new HTTP status code 451 (yyxx9988)
|
||||||
|
- Bug #5442: Fixed problem on load fixture dependencies with database related tests (leandrogehlen)
|
||||||
|
- Bug #13671: Fixed error handler trace to work correctly with XDebug (samdark)
|
||||||
|
- Bug #13657: Fixed `yii\helpers\StringHelper::truncateHtml()` skip extra tags at the end (sam002)
|
||||||
- Bug #4408: Add support for unicode word characters and `+` character in attribute names (sammousa, kmindi)
|
- Bug #4408: Add support for unicode word characters and `+` character in attribute names (sammousa, kmindi)
|
||||||
- Bug #7946: Fixed a bug when the `form` attribute was not propagated to the hidden input of the checkbox (Kolyunya)
|
- Bug #7946: Fixed a bug when the `form` attribute was not propagated to the hidden input of the checkbox (Kolyunya)
|
||||||
- Bug #8120: Fixes LIKE special characters escaping for Cubrid/MSSQL/Oracle/SQLite in `yii\db\QueryBuilder` (sergeymakinen)
|
- Bug #8120: Fixes LIKE special characters escaping for Cubrid/MSSQL/Oracle/SQLite in `yii\db\QueryBuilder` (sergeymakinen)
|
||||||
@ -83,6 +87,9 @@ Yii Framework 2 Change Log
|
|||||||
- Enh #13883: `yii\data\SqlDataProvider` now provides automatic fallback for the case when `totalCount` is not specified (SamMousa)
|
- Enh #13883: `yii\data\SqlDataProvider` now provides automatic fallback for the case when `totalCount` is not specified (SamMousa)
|
||||||
- Enh #13911: Significantly enhanced MSSQL schema reading performance (paulzi, WebdevMerlion)
|
- Enh #13911: Significantly enhanced MSSQL schema reading performance (paulzi, WebdevMerlion)
|
||||||
- Enh #13945: Removed Courier New from error page fonts list since it looks bad on Linux (samdark)
|
- Enh #13945: Removed Courier New from error page fonts list since it looks bad on Linux (samdark)
|
||||||
|
- Bug #13961: RBAC Rules: PostgreSQL: PHP Warning "unserialize() expects parameter 1 to be string, resource given" was fixed (vsguts)
|
||||||
|
- Enh #13976: Disabled IPv6 check on `\yii\validators\IpValidator` as it turns out it is not needed for inet_* methods to work (mikk150)
|
||||||
|
- Enh #13981: `yii\caching\Cache::getOrSet()` now supports both `Closure` and `callable` (silverfire)
|
||||||
- Enh #13963: Added tests for `yii\behaviors\TimestampBehavior` (vladis84)
|
- Enh #13963: Added tests for `yii\behaviors\TimestampBehavior` (vladis84)
|
||||||
- Enh #13976: Disabled IPv6 check on `\yii\validators\IpValidator` as it turns out it is not needed for `inet_*` methods to work (mikk150)
|
- Enh #13976: Disabled IPv6 check on `\yii\validators\IpValidator` as it turns out it is not needed for `inet_*` methods to work (mikk150)
|
||||||
- Enh #13981: `yii\caching\Cache::getOrSet()` now supports both `Closure` and `callable` (silverfire)
|
- Enh #13981: `yii\caching\Cache::getOrSet()` now supports both `Closure` and `callable` (silverfire)
|
||||||
@ -1843,4 +1850,3 @@ Yii Framework 2 Change Log
|
|||||||
|
|
||||||
- [Smarty View Renderer](https://github.com/yiisoft/yii2-smarty)
|
- [Smarty View Renderer](https://github.com/yiisoft/yii2-smarty)
|
||||||
- [Twig View Renderer](https://github.com/yiisoft/yii2-twig)
|
- [Twig View Renderer](https://github.com/yiisoft/yii2-twig)
|
||||||
|
|
||||||
|
@ -75,7 +75,6 @@ class ActiveFixture extends BaseActiveFixture
|
|||||||
*/
|
*/
|
||||||
public function load()
|
public function load()
|
||||||
{
|
{
|
||||||
$this->resetTable();
|
|
||||||
$this->data = [];
|
$this->data = [];
|
||||||
$table = $this->getTableSchema();
|
$table = $this->getTableSchema();
|
||||||
foreach ($this->getData() as $alias => $row) {
|
foreach ($this->getData() as $alias => $row) {
|
||||||
@ -106,6 +105,15 @@ class ActiveFixture extends BaseActiveFixture
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function unload()
|
||||||
|
{
|
||||||
|
$this->resetTable();
|
||||||
|
parent::unload();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all existing data from the specified table and resets sequence number to 1 (if any).
|
* Removes all existing data from the specified table and resets sequence number to 1 (if any).
|
||||||
* This method is called before populating fixture data into the table associated with this fixture.
|
* This method is called before populating fixture data into the table associated with this fixture.
|
||||||
|
@ -124,6 +124,16 @@ trait FixtureTrait
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the fixtures
|
||||||
|
* @since 2.0.12
|
||||||
|
*/
|
||||||
|
public function initFixtures()
|
||||||
|
{
|
||||||
|
$this->unloadFixtures();
|
||||||
|
$this->loadFixtures();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the fixture objects as specified in [[globalFixtures()]] and [[fixtures()]].
|
* Returns the fixture objects as specified in [[globalFixtures()]] and [[fixtures()]].
|
||||||
* @return Fixture[] the loaded fixtures for the current test case
|
* @return Fixture[] the loaded fixtures for the current test case
|
||||||
|
@ -42,7 +42,8 @@ CREATE TABLE `customer` (
|
|||||||
`address` text,
|
`address` text,
|
||||||
`status` int (11) DEFAULT 0,
|
`status` int (11) DEFAULT 0,
|
||||||
`profile_id` int(11),
|
`profile_id` int(11),
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`),
|
||||||
|
CONSTRAINT `FK_customer_profile_id` FOREIGN KEY (`profile_id`) REFERENCES `profile` (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
CREATE TABLE `category` (
|
CREATE TABLE `category` (
|
||||||
|
@ -9,9 +9,18 @@ use yii\test\InitDbFixture;
|
|||||||
use yiiunit\data\ar\Customer;
|
use yiiunit\data\ar\Customer;
|
||||||
use yiiunit\framework\db\DatabaseTestCase;
|
use yiiunit\framework\db\DatabaseTestCase;
|
||||||
|
|
||||||
|
class ProfileFixture extends ActiveFixture
|
||||||
|
{
|
||||||
|
public $modelClass = 'yiiunit\data\ar\Profile';
|
||||||
|
}
|
||||||
|
|
||||||
class CustomerFixture extends ActiveFixture
|
class CustomerFixture extends ActiveFixture
|
||||||
{
|
{
|
||||||
public $modelClass = 'yiiunit\data\ar\Customer';
|
public $modelClass = 'yiiunit\data\ar\Customer';
|
||||||
|
|
||||||
|
public $depends = [
|
||||||
|
'yiiunit\framework\test\ProfileFixture'
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyDbTestCase
|
class MyDbTestCase
|
||||||
@ -20,8 +29,7 @@ class MyDbTestCase
|
|||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->unloadFixtures();
|
$this->initFixtures();
|
||||||
$this->loadFixtures();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
@ -34,17 +42,15 @@ class MyDbTestCase
|
|||||||
'customers' => CustomerFixture::className(),
|
'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()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@ -63,12 +69,17 @@ abstract class ActiveFixtureTest extends DatabaseTestCase
|
|||||||
$test = new MyDbTestCase();
|
$test = new MyDbTestCase();
|
||||||
$test->setUp();
|
$test->setUp();
|
||||||
$fixture = $test->getFixture('customers');
|
$fixture = $test->getFixture('customers');
|
||||||
|
|
||||||
$this->assertEquals(CustomerFixture::className(), get_class($fixture));
|
$this->assertEquals(CustomerFixture::className(), get_class($fixture));
|
||||||
$this->assertCount(2, $fixture);
|
$this->assertCount(2, $fixture);
|
||||||
$this->assertEquals(1, $fixture['customer1']['id']);
|
$this->assertEquals(1, $fixture['customer1']['id']);
|
||||||
$this->assertEquals('customer1@example.com', $fixture['customer1']['email']);
|
$this->assertEquals('customer1@example.com', $fixture['customer1']['email']);
|
||||||
|
$this->assertEquals(1, $fixture['customer1']['profile_id']);
|
||||||
|
|
||||||
$this->assertEquals(2, $fixture['customer2']['id']);
|
$this->assertEquals(2, $fixture['customer2']['id']);
|
||||||
$this->assertEquals('customer2@example.com', $fixture['customer2']['email']);
|
$this->assertEquals('customer2@example.com', $fixture['customer2']['email']);
|
||||||
|
$this->assertEquals(2, $fixture['customer2']['profile_id']);
|
||||||
|
|
||||||
$test->tearDown();
|
$test->tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,11 +88,16 @@ abstract class ActiveFixtureTest extends DatabaseTestCase
|
|||||||
$test = new MyDbTestCase();
|
$test = new MyDbTestCase();
|
||||||
$test->setUp();
|
$test->setUp();
|
||||||
$fixture = $test->getFixture('customers');
|
$fixture = $test->getFixture('customers');
|
||||||
|
|
||||||
$this->assertEquals(Customer::className(), get_class($fixture->getModel('customer1')));
|
$this->assertEquals(Customer::className(), get_class($fixture->getModel('customer1')));
|
||||||
$this->assertEquals(1, $fixture->getModel('customer1')->id);
|
$this->assertEquals(1, $fixture->getModel('customer1')->id);
|
||||||
$this->assertEquals('customer1@example.com', $fixture->getModel('customer1')->email);
|
$this->assertEquals('customer1@example.com', $fixture->getModel('customer1')->email);
|
||||||
|
$this->assertEquals(1, $fixture['customer1']['profile_id']);
|
||||||
|
|
||||||
$this->assertEquals(2, $fixture->getModel('customer2')->id);
|
$this->assertEquals(2, $fixture->getModel('customer2')->id);
|
||||||
$this->assertEquals('customer2@example.com', $fixture->getModel('customer2')->email);
|
$this->assertEquals('customer2@example.com', $fixture->getModel('customer2')->email);
|
||||||
|
$this->assertEquals(2, $fixture['customer2']['profile_id']);
|
||||||
|
|
||||||
$test->tearDown();
|
$test->tearDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,9 @@ namespace yiiunit\framework\test;
|
|||||||
use yiiunit\TestCase;
|
use yiiunit\TestCase;
|
||||||
use yii\test\ArrayFixture;
|
use yii\test\ArrayFixture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group fixture
|
||||||
|
*/
|
||||||
class ArrayFixtureTest extends TestCase
|
class ArrayFixtureTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -11,6 +11,9 @@ use yii\test\Fixture;
|
|||||||
use yii\test\FixtureTrait;
|
use yii\test\FixtureTrait;
|
||||||
use yiiunit\TestCase;
|
use yiiunit\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group fixture
|
||||||
|
*/
|
||||||
class Fixture1 extends Fixture
|
class Fixture1 extends Fixture
|
||||||
{
|
{
|
||||||
public $depends = ['yiiunit\framework\test\Fixture2'];
|
public $depends = ['yiiunit\framework\test\Fixture2'];
|
||||||
|
@ -6,11 +6,13 @@ return [
|
|||||||
'name' => 'customer1',
|
'name' => 'customer1',
|
||||||
'address' => 'address1',
|
'address' => 'address1',
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
|
'profile_id' => 1
|
||||||
],
|
],
|
||||||
'customer2' => [
|
'customer2' => [
|
||||||
'email' => 'customer2@example.com',
|
'email' => 'customer2@example.com',
|
||||||
'name' => 'customer2',
|
'name' => 'customer2',
|
||||||
'address' => 'address2',
|
'address' => 'address2',
|
||||||
'status' => 2,
|
'status' => 2,
|
||||||
|
'profile_id' => 2
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
12
tests/framework/test/data/profile.php
Normal file
12
tests/framework/test/data/profile.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'profile1' => [
|
||||||
|
'id' => 1,
|
||||||
|
'description' => 'profile 1',
|
||||||
|
],
|
||||||
|
'profile2' => [
|
||||||
|
'id' => 2,
|
||||||
|
'description' => 'profile 2',
|
||||||
|
],
|
||||||
|
];
|
Reference in New Issue
Block a user