Browse Source

Fixes #15840: Fixed regression on load fixture data file

tags/2.0.14.2
Leandro Gehlen 7 years ago committed by Alexander Makarov
parent
commit
c484792084
  1. 2
      framework/CHANGELOG.md
  2. 3
      framework/test/ActiveFixture.php
  3. 2
      framework/test/BaseActiveFixture.php
  4. 11
      framework/test/FileFixtureTrait.php
  5. 26
      tests/framework/test/ActiveFixtureTest.php

2
framework/CHANGELOG.md

@ -11,10 +11,12 @@ Yii Framework 2 Change Log
- Bug #15817: Fixed support of deprecated array format type casting in `yii\db\Command::bindValues()` (silverfire) - Bug #15817: Fixed support of deprecated array format type casting in `yii\db\Command::bindValues()` (silverfire)
- Bug #15804: Fixed `null` values handling for PostgresSQL arrays (silverfire) - Bug #15804: Fixed `null` values handling for PostgresSQL arrays (silverfire)
- Bug #15829: Fixed JSONB support in PostgreSQL 9.4 (silverfire) - Bug #15829: Fixed JSONB support in PostgreSQL 9.4 (silverfire)
- Bug #15840: Fixed regression on load fixture data file (leandrogehlen)
- Bug: Fixed encoding of empty `yii\db\ArrayExpression` for PostgreSQL (silverfire) - Bug: Fixed encoding of empty `yii\db\ArrayExpression` for PostgreSQL (silverfire)
- Bug: Fixed table schema retrieving for PostgreSQL when the table name was wrapped in quotes (silverfire) - Bug: Fixed table schema retrieving for PostgreSQL when the table name was wrapped in quotes (silverfire)
2.0.14.1 February 24, 2018 2.0.14.1 February 24, 2018
-------------------------- --------------------------

3
framework/test/ActiveFixture.php

@ -102,9 +102,8 @@ class ActiveFixture extends BaseActiveFixture
$dataFile = dirname($class->getFileName()) . '/data/' . $this->getTableSchema()->fullName . '.php'; $dataFile = dirname($class->getFileName()) . '/data/' . $this->getTableSchema()->fullName . '.php';
} }
return $this->loadData($dataFile); return $this->loadData($dataFile, false);
} }
return parent::getData(); return parent::getData();
} }

2
framework/test/BaseActiveFixture.php

@ -84,7 +84,7 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate
* *
* @return array the data to be put into the database * @return array the data to be put into the database
* @throws InvalidConfigException if the specified data file does not exist. * @throws InvalidConfigException if the specified data file does not exist.
* @see [[loadDataFile]] * @see [[loadData]]
*/ */
protected function getData() protected function getData()
{ {

11
framework/test/FileFixtureTrait.php

@ -35,12 +35,13 @@ trait FileFixtureTrait
* The file should return the data array that will be stored in [[data]] after inserting into the database. * The file should return the data array that will be stored in [[data]] after inserting into the database.
* *
* @param string $file the data file path * @param string $file the data file path
* @param bool $throwException whether to throw exception if fixture data file does not exist.
* @return array the data to be put into the database * @return array the data to be put into the database
* @throws InvalidConfigException if the specified data file does not exist. * @throws InvalidConfigException if the specified data file does not exist.
*/ */
protected function loadData($file) protected function loadData($file, $throwException = true)
{ {
if ($file === false || $file === null) { if ($file === null || $file === false) {
return []; return [];
} }
@ -52,8 +53,12 @@ trait FileFixtureTrait
if (is_file($file)) { if (is_file($file)) {
return require $file; return require $file;
} }
if ($throwException) {
throw new InvalidConfigException("Fixture data file does not exist: {$file}");
}
throw new InvalidConfigException("Fixture data file does not exist: {$file}"); return [];
} }
} }

26
tests/framework/test/ActiveFixtureTest.php

@ -34,6 +34,10 @@ class CustomDirectoryFixture extends ActiveFixture
public $dataDirectory = '@app/framework/test/custom'; public $dataDirectory = '@app/framework/test/custom';
} }
class AnimalFixture extends ActiveFixture
{
public $modelClass = 'yiiunit\data\ar\Animal';
}
class BaseDbTestCase class BaseDbTestCase
{ {
@ -82,6 +86,19 @@ class DataPathDbTestCase extends BaseDbTestCase
} }
} }
class TruncateTestCase extends BaseDbTestCase
{
public function fixtures()
{
return [
'animals' => [
'class' => AnimalFixture::className(),
]
];
}
}
/** /**
* @group fixture * @group fixture
* @group db * @group db
@ -165,6 +182,15 @@ class ActiveFixtureTest extends DatabaseTestCase
$this->assertEquals(1, $customer->id); $this->assertEquals(1, $customer->id);
$this->assertEquals('customer1@example.com', $customer['email']); $this->assertEquals('customer1@example.com', $customer['email']);
$test->tearDown(); $test->tearDown();
}
public function testTruncate()
{
$test = new TruncateTestCase();
$test->setUp();
$fixture = $test->getFixture('animals');
$this->assertEmpty($fixture->data);
$test->tearDown();
} }
} }

Loading…
Cancel
Save