Browse Source

Fixes #1733: Incorrect code about `$_modelClasses` in `DbFixtureManager`

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
64c4d8e718
  1. 1
      framework/CHANGELOG.md
  2. 16
      framework/yii/test/DbFixtureManager.php

1
framework/CHANGELOG.md

@ -20,6 +20,7 @@ Yii Framework 2 Change Log
- Bug #1686: ActiveForm is creating duplicated messages in error summary (qiangxue) - Bug #1686: ActiveForm is creating duplicated messages in error summary (qiangxue)
- Bug #1704: Incorrect regexp is used in `Inflector::camelize()` (qiangxue) - Bug #1704: Incorrect regexp is used in `Inflector::camelize()` (qiangxue)
- Bug #1710: OpenId auth client does not request required attributes correctly (klimov-paul) - Bug #1710: OpenId auth client does not request required attributes correctly (klimov-paul)
- Bug #1733: Incorrect code about `$_modelClasses` in `DbFixtureManager` (qiangxue)
- Bug: Fixed `Call to a member function registerAssetFiles() on a non-object` in case of wrong `sourcePath` for an asset bundle (samdark) - Bug: Fixed `Call to a member function registerAssetFiles() on a non-object` in case of wrong `sourcePath` for an asset bundle (samdark)
- Bug: Fixed incorrect event name for `yii\jui\Spinner` (samdark) - Bug: Fixed incorrect event name for `yii\jui\Spinner` (samdark)
- Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe) - Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe)

16
framework/yii/test/DbFixtureManager.php

@ -10,7 +10,7 @@ namespace yii\test;
use Yii; use Yii;
use yii\base\Component; use yii\base\Component;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
use yii\db\ActiveRecordInterface; use yii\db\ActiveRecord;
use yii\db\Connection; use yii\db\Connection;
/** /**
@ -59,7 +59,6 @@ class DbFixtureManager extends Component
private $_rows; // fixture name, row alias => row private $_rows; // fixture name, row alias => row
private $_models; // fixture name, row alias => record (or class name) private $_models; // fixture name, row alias => record (or class name)
private $_modelClasses;
/** /**
@ -92,8 +91,7 @@ class DbFixtureManager extends Component
foreach ($fixtures as $name => $fixture) { foreach ($fixtures as $name => $fixture) {
if (strpos($fixture, '\\') !== false) { if (strpos($fixture, '\\') !== false) {
$model = new $fixture; $model = new $fixture;
if ($model instanceof ActiveRecordInterface) { if ($model instanceof ActiveRecord) {
$this->_modelClasses[$name] = $fixture;
$fixtures[$name] = $model->getTableSchema()->name; $fixtures[$name] = $model->getTableSchema()->name;
} else { } else {
throw new InvalidConfigException("Fixture '$fixture' must be an ActiveRecord class."); throw new InvalidConfigException("Fixture '$fixture' must be an ActiveRecord class.");
@ -101,7 +99,7 @@ class DbFixtureManager extends Component
} }
} }
$this->_modelClasses = $this->_rows = $this->_models = []; $this->_rows = $this->_models = [];
$this->checkIntegrity(false); $this->checkIntegrity(false);
@ -184,20 +182,20 @@ class DbFixtureManager extends Component
* Returns the specified ActiveRecord instance in the fixture data. * Returns the specified ActiveRecord instance in the fixture data.
* @param string $fixtureName the fixture name * @param string $fixtureName the fixture name
* @param string $modelName the alias for the fixture data row * @param string $modelName the alias for the fixture data row
* @return ActiveRecordInterface the ActiveRecord instance. Null is returned if there is no such fixture row. * @return ActiveRecord the ActiveRecord instance. Null is returned if there is no such fixture row.
*/ */
public function getModel($fixtureName, $modelName) public function getModel($fixtureName, $modelName)
{ {
if (!isset($this->_modelClasses[$fixtureName]) || !isset($this->_rows[$fixtureName][$modelName])) { if (!isset($this->_rows[$fixtureName][$modelName])) {
return null; return null;
} }
if (isset($this->_models[$fixtureName][$modelName])) { if (isset($this->_models[$fixtureName][$modelName])) {
return $this->_models[$fixtureName][$modelName]; return $this->_models[$fixtureName][$modelName];
} }
$row = $this->_rows[$fixtureName][$modelName]; $row = $this->_rows[$fixtureName][$modelName];
/** @var ActiveRecordInterface $modelClass */ /** @var ActiveRecord $modelClass */
$modelClass = $this->_models[$fixtureName]; $modelClass = $this->_models[$fixtureName];
/** @var ActiveRecordInterface $model */ /** @var ActiveRecord $model */
$model = new $modelClass; $model = new $modelClass;
$keys = []; $keys = [];
foreach ($model->primaryKey() as $key) { foreach ($model->primaryKey() as $key) {

Loading…
Cancel
Save