mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-09 08:47:34 +01:00
Fixes #14546: Added dataDirectory property into BaseActiveFixture
This commit is contained in:
committed by
Alexander Makarov
parent
57b31fc92c
commit
810e9e5337
@@ -7,7 +7,6 @@
|
||||
|
||||
namespace yii\test;
|
||||
|
||||
use Yii;
|
||||
use yii\base\ArrayAccessTrait;
|
||||
use yii\base\InvalidConfigException;
|
||||
|
||||
@@ -22,6 +21,7 @@ use yii\base\InvalidConfigException;
|
||||
abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate, \ArrayAccess, \Countable
|
||||
{
|
||||
use ArrayAccessTrait;
|
||||
use FileFixtureTrait;
|
||||
|
||||
/**
|
||||
* @var string the AR model class associated with this fixture.
|
||||
@@ -31,18 +31,11 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate
|
||||
* @var array the data rows. Each array element represents one row of data (column name => column value).
|
||||
*/
|
||||
public $data = [];
|
||||
/**
|
||||
* @var string|bool the file path or [path alias](guide:concept-aliases) of the data file that contains the fixture data
|
||||
* to be returned by [[getData()]]. You can set this property to be false to prevent loading any data.
|
||||
*/
|
||||
public $dataFile;
|
||||
|
||||
/**
|
||||
* @var \yii\db\ActiveRecord[] the loaded AR models
|
||||
*/
|
||||
private $_models = [];
|
||||
|
||||
|
||||
/**
|
||||
* Returns the AR model by the specified model name.
|
||||
* A model name is the key of the corresponding data row in [[data]].
|
||||
@@ -87,23 +80,13 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate
|
||||
/**
|
||||
* Returns the fixture data.
|
||||
*
|
||||
* The default implementation will try to return the fixture data by including the external file specified by [[dataFile]].
|
||||
* The file should return the data array that will be stored in [[data]] after inserting into the database.
|
||||
*
|
||||
* @return array the data to be put into the database
|
||||
* @throws InvalidConfigException if the specified data file does not exist.
|
||||
* @see [[loadDataFile]]
|
||||
*/
|
||||
protected function getData()
|
||||
{
|
||||
if ($this->dataFile === false || $this->dataFile === null) {
|
||||
return [];
|
||||
}
|
||||
$dataFile = Yii::getAlias($this->dataFile);
|
||||
if (is_file($dataFile)) {
|
||||
return require $dataFile;
|
||||
}
|
||||
|
||||
throw new InvalidConfigException("Fixture data file does not exist: {$this->dataFile}");
|
||||
return $this->loadData($this->dataFile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user