Commit 7863a0ff by Qiang Xue

Merge pull request #2279 from Ragazzo/fixtures_controller_improvements

Fixtures controller improvements
parents 27738286 2ed30dfe
Database Fixtures Fixtures console flow
================= =====================
Fixtures are important part of testing. Their main purpose is to populate you with data that needed by testing Fixtures are important part of testing. Their main purpose is to populate you with data that needed by testing
different cases. With this data using your tests becoming more efficient and useful. different cases. With this data using your tests becoming more efficient and useful.
Yii supports database fixtures via the `yii fixture` command line tool. This tool supports: Yii supports fixtures via the `yii fixture` command line tool. This tool supports:
* Applying new fixtures to database tables; * Loading fixtures to different storages such as: database, nosql, etc;
* Clearing, database tables (with sequences); * Unloading fixtures in different ways (usually it is clearing storage);
* Auto-generating fixtures and populating it with random data. * Auto-generating fixtures and populating it with random data.
Fixtures format Fixtures format
--------------- ---------------
Fixtures are just plain php files returning array. These files are usually stored under `@tests/unit/fixtures` path, but it Fixtures are objects with different methods and configurations, refer to official [documentation](https://github.com/yiisoft/yii2/blob/master/docs/guide/test-fixture.md) on them.
can be [configured](#configure-command-globally) in other way. Example of fixture file: Lets assume we have fixtures data to load:
``` ```
#users.php file under fixtures path #users.php file under fixtures data path, by default @tests\unit\fixtures\data
return [ return [
[ [
...@@ -36,31 +36,35 @@ return [ ...@@ -36,31 +36,35 @@ return [
], ],
]; ];
``` ```
If we are using fixture that loads data into database then these rows will be applied to `users` table. If we are using nosql fixtures, for example `mongodb`
This data will be loaded to the `users`, but before it will be loaded table `users` will be cleared: all data deleted, sequence reset. fixture, then this data will be applied to `users` mongodb collection. In order to learn about implementing various loading strategies and more, refer to official [documentation](https://github.com/yiisoft/yii2/blob/master/docs/guide/test-fixture.md).
Above fixture example was auto-generated by `yii2-faker` extension, read more about it in these [section](#auto-generating-fixtures). Above fixture example was auto-generated by `yii2-faker` extension, read more about it in these [section](#auto-generating-fixtures).
Fixture classes name should not be plural.
Loading fixtures
----------------
Applying fixtures Fixture classes should be suffixed by `Fixture` class. By default fixtures will be searched under `tests\unit\fixtures` namespace, you can
----------------- change this behavior with config or command options.
To apply fixture to the table, run the following command: To apply fixture, run the following command:
``` ```
yii fixture/apply <tbl_name> yii fixture/apply <fixture_name>
``` ```
The required `tbl_name` parameter specifies a database table to which data will be loaded. You can load data to several tables at once. The required `fixture_name` parameter specifies a fixture name which data will be loaded. You can load several fixtures at once.
Below are correct formats of this command: Below are correct formats of this command:
``` ```
// apply fixtures to the "users" table of database // apply `users` fixture
yii fixture/apply users yii fixture/apply User
// same as above, because default action of "fixture" command is "apply" // same as above, because default action of "fixture" command is "apply"
yii fixture users yii fixture User
// apply several fixtures to several tables. Note that there should not be any whitespace between ",", it should be one string. // apply several fixtures. Note that there should not be any whitespace between ",", it should be one string.
yii fixture users,users_profiles yii fixture User,UserProfile
// apply all fixtures // apply all fixtures
yii fixture/apply all yii fixture/apply all
...@@ -68,29 +72,31 @@ yii fixture/apply all ...@@ -68,29 +72,31 @@ yii fixture/apply all
// same as above // same as above
yii fixture all yii fixture all
// apply fixtures to the table users, but fixtures will be taken from different path. // apply fixtures, but for other database connection.
yii fixture users --fixturePath='@app/my/custom/path/to/fixtures' yii fixtures User --db='customDbConnectionId'
// apply fixtures to the table users, but for other database connection. // apply fixtures, but search them in different namespace. By default namespace is: tests\unit\fixtures.
yii fixtures users --db='customDbConnectionId' yii fixtures User --namespace='alias\my\custom\namespace'
``` ```
Clearing tables Unloading fixtures
--------------- ------------------
To clear table, run the following command: To unload fixture, run the following command:
``` ```
// clear given table: delete all data and reset sequence. // unload Users fixture, by default it will clear fixture storage (for example "users" table, or "users" collection if this is mongodb fixture).
yii fixture/clear users yii fixture/clear User
// clear several tables. Note that there should not be any whitespace between ",", it should be one string. // Unload several fixtures. Note that there should not be any whitespace between ",", it should be one string.
yii fixture/clear users,users_profile yii fixture/clear User,UserProfile
// clear all tables of current connection in current schema // unload all fixtures
yii fixture/clear all yii fixture/clear all
``` ```
Same command options like: `db`, `namespace` also can be applied to this command.
Configure Command Globally Configure Command Globally
-------------------------- --------------------------
While command line options allow us to configure the migration command While command line options allow us to configure the migration command
...@@ -101,8 +107,8 @@ different migration path as follows: ...@@ -101,8 +107,8 @@ different migration path as follows:
'controllerMap' => [ 'controllerMap' => [
'fixture' => [ 'fixture' => [
'class' => 'yii\console\FixtureController', 'class' => 'yii\console\FixtureController',
'fixturePath' => '@app/my/custom/path/to/fixtures',
'db' => 'customDbConnectionId', 'db' => 'customDbConnectionId',
'namespace' => 'myalias\some\custom\namespace',
], ],
] ]
``` ```
......
...@@ -175,6 +175,47 @@ This means you only need to work with `@app/tests/fixtures/initdb.php` if you wa ...@@ -175,6 +175,47 @@ This means you only need to work with `@app/tests/fixtures/initdb.php` if you wa
before each test. You may otherwise simply focus on developing each individual test case and the corresponding fixtures. before each test. You may otherwise simply focus on developing each individual test case and the corresponding fixtures.
Fixtures hierarchy convention
-----------------------------
Usually you will have one fixture class per needed fixture and will be only switching data files for fixture classes.
When you have simple project that does not have much database testing and fixtures, you can put all fixtures data files under `data` folder, as it is done by default.
But when your project is not very simple you should not be greedy when using data files and organize them according these rule:
- data file should follow same hierarchy that is used for your project classes namespace.
Lets see example:
```php
#under folder tests\unit\fixtures
data\
components\
some_fixture_data_file1.php
some_fixture_data_file2.php
...
some_fixture_data_fileN.php
models\
db\
some_fixture_data_file1.php
some_fixture_data_file2.php
...
some_fixture_data_fileN.php
forms\
some_fixture_data_file1.php
some_fixture_data_file2.php
...
some_fixture_data_fileN.php
#and so on
```
In this way you will avoid fixture data collision between tests and use them as you need.
> **Note** In the example above fixture files are named only for example purposes, in real life you should name them according what fixture type you are using.
It can be table name, or mongodb collection name if you are using mongodb fixture. In order to know how to specify and name data files for your fixtures read above on this article.
Same rule can be applied to organize fixtures classes in your project, so similar hierarchy will be build under `fixtures` directory, avoiding usage of `data` directory, that is reserved for data files.
Summary Summary
------- -------
......
...@@ -53,12 +53,12 @@ class ActiveFixture extends BaseActiveFixture ...@@ -53,12 +53,12 @@ class ActiveFixture extends BaseActiveFixture
/** /**
* Loads the fixture data. * Loads the fixture data.
* The default implementation will first reset the DB table and then populate it with the data * Data will be batch inserted into the given collection.
* returned by [[getData()]].
*/ */
public function load() public function load()
{ {
$this->resetCollection(); parent::load();
$data = $this->getData(); $data = $this->getData();
$this->getCollection()->batchInsert($data); $this->getCollection()->batchInsert($data);
foreach ($data as $alias => $row) { foreach ($data as $alias => $row) {
...@@ -66,6 +66,17 @@ class ActiveFixture extends BaseActiveFixture ...@@ -66,6 +66,17 @@ class ActiveFixture extends BaseActiveFixture
} }
} }
/**
* Unloads the fixture.
*
* The default implementation will clean up the colection by calling [[resetCollection()]].
*/
public function unload()
{
$this->resetCollection();
parent::unload();
}
protected function getCollection() protected function getCollection()
{ {
return $this->db->getCollection($this->getCollectionName()); return $this->db->getCollection($this->getCollectionName());
......
...@@ -12,9 +12,11 @@ use yii\console\Controller; ...@@ -12,9 +12,11 @@ use yii\console\Controller;
use yii\console\Exception; use yii\console\Exception;
use yii\helpers\FileHelper; use yii\helpers\FileHelper;
use yii\helpers\Console; use yii\helpers\Console;
use yii\test\FixtureTrait;
use yii\helpers\Inflector;
/** /**
* This command manages fixtures load to the database tables. * This command manages loading and unloading fixtures.
* You can specify different options of this command to point fixture manager * You can specify different options of this command to point fixture manager
* to the specific tables of the different database connections. * to the specific tables of the different database connections.
* *
...@@ -28,23 +30,20 @@ use yii\helpers\Console; ...@@ -28,23 +30,20 @@ use yii\helpers\Console;
* 'password' => '', * 'password' => '',
* 'charset' => 'utf8', * 'charset' => 'utf8',
* ], * ],
* 'fixture' => [
* 'class' => 'yii\test\DbFixtureManager',
* ],
* ~~~ * ~~~
* *
* ~~~ * ~~~
* #load fixtures under $fixturePath to the "users" table * #load fixtures under $fixturePath from UsersFixture class with default namespace "tests\unit\fixtures"
* yii fixture/apply users * yii fixture/apply User
* *
* #also a short version of this command (generate action is default) * #also a short version of this command (generate action is default)
* yii fixture users * yii fixture User
* *
* #load fixtures under $fixturePath to the "users" table to the different connection * #load fixtures under $fixturePath with the different database connection
* yii fixture/apply users --db=someOtherDbConneciton * yii fixture/apply User --db=someOtherDbConneciton
* *
* #load fixtures under different $fixturePath to the "users" table. * #load fixtures under different $fixturePath.
* yii fixture/apply users --fixturePath=@app/some/other/path/to/fixtures * yii fixture/apply User --namespace=alias\my\custom\namespace\goes\here
* ~~~ * ~~~
* *
* @author Mark Jebri <mark.github@yandex.ru> * @author Mark Jebri <mark.github@yandex.ru>
...@@ -52,8 +51,9 @@ use yii\helpers\Console; ...@@ -52,8 +51,9 @@ use yii\helpers\Console;
*/ */
class FixtureController extends Controller class FixtureController extends Controller
{ {
use DbTestTrait;
use FixtureTrait;
/** /**
* type of fixture apply to database * type of fixture apply to database
*/ */
...@@ -64,16 +64,14 @@ class FixtureController extends Controller ...@@ -64,16 +64,14 @@ class FixtureController extends Controller
*/ */
public $defaultAction = 'apply'; public $defaultAction = 'apply';
/** /**
* Alias to the path, where all fixtures are stored. * @var string id of the database connection component of the application.
* @var string
*/
public $fixturePath = '@tests/unit/fixtures';
/**
* Id of the database connection component of the application.
* @var string
*/ */
public $db = 'db'; public $db = 'db';
/**
* @var string default namespace to search fixtures in
*/
public $namespace = 'tests\unit\fixtures';
/** /**
* Returns the names of the global options for this command. * Returns the names of the global options for this command.
...@@ -82,27 +80,11 @@ class FixtureController extends Controller ...@@ -82,27 +80,11 @@ class FixtureController extends Controller
public function globalOptions() public function globalOptions()
{ {
return array_merge(parent::globalOptions(), [ return array_merge(parent::globalOptions(), [
'db', 'fixturePath' 'db','namespace'
]); ]);
} }
/** /**
* This method is invoked right before an action is to be executed (after all possible filters.)
* It checks that fixtures path and database connection are available.
* @param \yii\base\Action $action
* @return boolean
*/
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
$this->checkRequirements();
return true;
} else {
return false;
}
}
/**
* Apply given fixture to the table. You can load several fixtures specifying * Apply given fixture to the table. You can load several fixtures specifying
* their names separated with commas, like: tbl_user,tbl_profile. Be sure there is no * their names separated with commas, like: tbl_user,tbl_profile. Be sure there is no
* whitespace between tables names. * whitespace between tables names.
...@@ -111,10 +93,6 @@ class FixtureController extends Controller ...@@ -111,10 +93,6 @@ class FixtureController extends Controller
*/ */
public function actionApply(array $fixtures, array $except = []) public function actionApply(array $fixtures, array $except = [])
{ {
if ($this->getFixtureManager() === null) {
throw new Exception('Fixture manager is not configured properly. Please refer to official documentation for this purposes.');
}
$foundFixtures = $this->findFixtures($fixtures); $foundFixtures = $this->findFixtures($fixtures);
if (!$this->needToApplyAll($fixtures[0])) { if (!$this->needToApplyAll($fixtures[0])) {
...@@ -127,25 +105,27 @@ class FixtureController extends Controller ...@@ -127,25 +105,27 @@ class FixtureController extends Controller
if (!$foundFixtures) { if (!$foundFixtures) {
throw new Exception("No files were found by name: \"" . implode(', ', $fixtures) . "\".\n" throw new Exception("No files were found by name: \"" . implode(', ', $fixtures) . "\".\n"
. "Check that fixtures with these name exists, under fixtures path: \n\"" . Yii::getAlias($this->fixturePath) . "\"." . "Check that files with these name exists, under fixtures path: \n\"" . Yii::getAlias($this->getFixturePath()) . "\"."
); );
} }
if (!$this->confirmApply($foundFixtures, $except)) { if (!$this->confirmApply($foundFixtures, $except)) {
return; return;
} }
$fixtures = array_diff($foundFixtures, $except); $fixtures = $this->getFixturesConfig(array_diff($foundFixtures, $except));
$this->getFixtureManager()->basePath = $this->fixturePath; if (!$fixtures) {
$this->getFixtureManager()->db = $this->db; throw new Exception('No fixtures were found in namespace: "' . $this->namespace . '"'.'');
}
$transaction = Yii::$app->db->beginTransaction(); $transaction = Yii::$app->db->beginTransaction();
try { try {
$this->loadFixtures($foundFixtures); $this->getDbConnection()->createCommand()->checkIntegrity(false)->execute();
$this->loadFixtures($fixtures);
$this->getDbConnection()->createCommand()->checkIntegrity(true)->execute();
$transaction->commit(); $transaction->commit();
} catch (\Exception $e) { } catch (\Exception $e) {
$transaction->rollback(); $transaction->rollback();
$this->stdout("Exception occured, transaction rollback. Tables will be in same state.\n", Console::BG_RED); $this->stdout("Exception occured, transaction rollback. Tables will be in same state.\n", Console::BG_RED);
...@@ -155,32 +135,49 @@ class FixtureController extends Controller ...@@ -155,32 +135,49 @@ class FixtureController extends Controller
} }
/** /**
* Truncate given table and clear all fixtures from it. You can clear several tables specifying * Unloads given fixtures. You can clear environment and unload multiple fixtures by specifying
* their names separated with commas, like: tbl_user,tbl_profile. Be sure there is no * their names separated with commas, like: tbl_user,tbl_profile. Be sure there is no
* whitespace between tables names. * whitespace between tables names.
* @param array|string $tables * @param array|string $fixtures
* @param array|string $except
*/ */
public function actionClear(array $tables, array $except = ['tbl_migration']) public function actionClear(array $fixtures, array $except = [])
{ {
if ($this->needToApplyAll($tables[0])) { $foundFixtures = $this->findFixtures($fixtures);
$tables = $this->getDbConnection()->schema->getTableNames();
if (!$this->needToApplyAll($fixtures[0])) {
$notFoundFixtures = array_diff($fixtures, $foundFixtures);
if ($notFoundFixtures) {
$this->notifyNotFound($notFoundFixtures);
}
}
if (!$foundFixtures) {
throw new Exception("No files were found by name: \"" . implode(', ', $fixtures) . "\".\n"
. "Check that fixtures with these name exists, under fixtures path: \n\"" . Yii::getAlias($this->getFixturePath()) . "\"."
);
} }
if (!$this->confirmClear($tables, $except)) { if (!$this->confirmClear($foundFixtures, $except)) {
return; return;
} }
$tables = array_diff($tables, $except); $fixtures = $this->getFixturesConfig(array_diff($foundFixtures, $except));
if (!$fixtures) {
throw new Exception('No fixtures were found in namespace: ' . $this->namespace . '".');
}
$transaction = Yii::$app->db->beginTransaction(); $transaction = Yii::$app->db->beginTransaction();
try { try {
$this->getDbConnection()->createCommand()->checkIntegrity(false)->execute(); $this->getDbConnection()->createCommand()->checkIntegrity(false)->execute();
foreach($tables as $table) { foreach($fixtures as $fixtureConfig) {
$this->getDbConnection()->createCommand()->delete($table)->execute(); $fixture = Yii::createObject($fixtureConfig);
$this->getDbConnection()->createCommand()->resetSequence($table)->execute(); $fixture->unload();
$this->stdout(" Table \"{$table}\" was successfully cleared. \n", Console::FG_GREEN); $this->stdout("\tFixture \"{$fixture::className()}\" was successfully unloaded. \n", Console::FG_GREEN);
} }
$this->getDbConnection()->createCommand()->checkIntegrity(true)->execute(); $this->getDbConnection()->createCommand()->checkIntegrity(true)->execute();
...@@ -194,23 +191,9 @@ class FixtureController extends Controller ...@@ -194,23 +191,9 @@ class FixtureController extends Controller
} }
/** /**
* Checks if the database and fixtures path are available.
* @throws Exception
*/
public function checkRequirements()
{
$path = Yii::getAlias($this->fixturePath, false);
if (!is_dir($path) || !is_writable($path)) {
throw new Exception("The fixtures path \"{$this->fixturePath}\" not exist or is not writable.");
}
}
/**
* Returns database connection component * Returns database connection component
* @return \yii\db\Connection * @return \yii\db\Connection
* @throws Exception if [[db]] is invalid. * @throws yii\console\Exception if [[db]] is invalid.
*/ */
public function getDbConnection() public function getDbConnection()
{ {
...@@ -229,8 +212,8 @@ class FixtureController extends Controller ...@@ -229,8 +212,8 @@ class FixtureController extends Controller
*/ */
private function notifySuccess($fixtures) private function notifySuccess($fixtures)
{ {
$this->stdout("Fixtures were successfully loaded from path:\n", Console::FG_YELLOW); $this->stdout("Fixtures were successfully loaded from namespace:\n", Console::FG_YELLOW);
$this->stdout(Yii::getAlias($this->fixturePath) . "\n\n", Console::FG_GREEN); $this->stdout("\t\"" . Yii::getAlias($this->namespace) . "\"\n\n", Console::FG_GREEN);
$this->outputList($fixtures); $this->outputList($fixtures);
} }
...@@ -241,7 +224,8 @@ class FixtureController extends Controller ...@@ -241,7 +224,8 @@ class FixtureController extends Controller
private function notifyNotFound($fixtures) private function notifyNotFound($fixtures)
{ {
$this->stdout("Some fixtures were not found under path:\n", Console::BG_RED); $this->stdout("Some fixtures were not found under path:\n", Console::BG_RED);
$this->stdout(Yii::getAlias($this->fixturePath) . "\n\n", Console::FG_GREEN); $this->stdout("\t" . Yii::getAlias($this->getFixturePath()) . "\n\n", Console::FG_GREEN);
$this->stdout("Check that they have correct namespace \"{$this->namespace}\" \n", Console::BG_RED);
$this->outputList($fixtures); $this->outputList($fixtures);
$this->stdout("\n"); $this->stdout("\n");
} }
...@@ -254,8 +238,10 @@ class FixtureController extends Controller ...@@ -254,8 +238,10 @@ class FixtureController extends Controller
*/ */
private function confirmApply($fixtures, $except) private function confirmApply($fixtures, $except)
{ {
$this->stdout("Fixtures will be loaded from path: \n", Console::FG_YELLOW); $this->stdout("Fixtures namespace is: \n", Console::FG_YELLOW);
$this->stdout(Yii::getAlias($this->fixturePath) . "\n\n", Console::FG_GREEN); $this->stdout("\t" . $this->namespace . "\n\n", Console::FG_GREEN);
$this->stdout("Fixtures below will be loaded:\n\n", Console::FG_YELLOW);
$this->outputList($fixtures); $this->outputList($fixtures);
if (count($except)) { if (count($except)) {
...@@ -263,26 +249,29 @@ class FixtureController extends Controller ...@@ -263,26 +249,29 @@ class FixtureController extends Controller
$this->outputList($except); $this->outputList($except);
} }
return $this->confirm("\nLoad to database above fixtures?"); return $this->confirm("\nLoad above fixtures?");
} }
/** /**
* Prompts user with confirmation for tables that should be cleared. * Prompts user with confirmation for fixtures that should be unloaded.
* @param array $tables * @param array $fixtures
* @param array $except * @param array $except
* @return boolean * @return boolean
*/ */
private function confirmClear($tables, $except) private function confirmClear($fixtures, $except)
{ {
$this->stdout("Tables below will be cleared:\n\n", Console::FG_YELLOW); $this->stdout("Fixtures namespace is: \n", Console::FG_YELLOW);
$this->outputList($tables); $this->stdout("\t" . $this->namespace . "\n\n", Console::FG_GREEN);
$this->stdout("Fixtures below will be unloaded:\n\n", Console::FG_YELLOW);
$this->outputList($fixtures);
if (count($except)) { if (count($except)) {
$this->stdout("\nTables that will NOT be cleared:\n\n", Console::FG_YELLOW); $this->stdout("\nFixtures that will NOT be unloaded:\n\n", Console::FG_YELLOW);
$this->outputList($except); $this->outputList($except);
} }
return $this->confirm("\nClear tables?"); return $this->confirm("\nUnload fixtures?");
} }
/** /**
...@@ -292,7 +281,7 @@ class FixtureController extends Controller ...@@ -292,7 +281,7 @@ class FixtureController extends Controller
private function outputList($data) private function outputList($data)
{ {
foreach($data as $index => $item) { foreach($data as $index => $item) {
$this->stdout(" " . ($index + 1) . ". {$item}\n", Console::FG_GREEN); $this->stdout("\t" . ($index + 1) . ". {$item}\n", Console::FG_GREEN);
} }
} }
...@@ -312,13 +301,13 @@ class FixtureController extends Controller ...@@ -312,13 +301,13 @@ class FixtureController extends Controller
*/ */
private function findFixtures(array $fixtures) private function findFixtures(array $fixtures)
{ {
$fixturesPath = Yii::getAlias($this->fixturePath); $fixturesPath = Yii::getAlias($this->getFixturePath());
$filesToSearch = ['*.php']; $filesToSearch = ['*Fixture.php'];
if (!$this->needToApplyAll($fixtures[0])) { if (!$this->needToApplyAll($fixtures[0])) {
$filesToSearch = []; $filesToSearch = [];
foreach ($fixtures as $fileName) { foreach ($fixtures as $fileName) {
$filesToSearch[] = $fileName . '.php'; $filesToSearch[] = $fileName . 'Fixture.php';
} }
} }
...@@ -326,10 +315,42 @@ class FixtureController extends Controller ...@@ -326,10 +315,42 @@ class FixtureController extends Controller
$foundFixtures = []; $foundFixtures = [];
foreach ($files as $fixture) { foreach ($files as $fixture) {
$foundFixtures[] = basename($fixture , '.php'); $foundFixtures[] = basename($fixture , 'Fixture.php');
} }
return $foundFixtures; return $foundFixtures;
} }
/**
* Returns valid fixtures config that can be used to load them.
* @param array $fixtures fixtures to configure
* @return array
*/
private function getFixturesConfig($fixtures)
{
$config = [];
foreach($fixtures as $fixture) {
$fullClassName = $this->namespace . '\\' . $fixture . 'Fixture';
if (class_exists($fullClassName)) {
$config[Inflector::camel2id($fixture, '_')] = [
'class' => $fullClassName,
];
}
}
return $config;
}
/**
* Returns fixture path that determined on fixtures namespace.
* @return string fixture path
*/
private function getFixturePath()
{
return Yii::getAlias('@' . str_replace('\\', '/', $this->namespace));
}
} }
...@@ -65,7 +65,6 @@ class ActiveFixture extends BaseActiveFixture ...@@ -65,7 +65,6 @@ class ActiveFixture extends BaseActiveFixture
/** /**
* Loads the fixture. * Loads the fixture.
* *
* The default implementation will first clean up the table by calling [[resetTable()]].
* It will then populate the table with the data returned by [[getData()]]. * It will then populate the table with the data returned by [[getData()]].
* *
* If you override this method, you should consider calling the parent implementation * If you override this method, you should consider calling the parent implementation
...@@ -73,7 +72,7 @@ class ActiveFixture extends BaseActiveFixture ...@@ -73,7 +72,7 @@ class ActiveFixture extends BaseActiveFixture
*/ */
public function load() public function load()
{ {
$this->resetTable(); parent::load();
$table = $this->getTableSchema(); $table = $this->getTableSchema();
...@@ -92,6 +91,17 @@ class ActiveFixture extends BaseActiveFixture ...@@ -92,6 +91,17 @@ class ActiveFixture extends BaseActiveFixture
} }
/** /**
* Unloads the fixture.
*
* The default implementation will clean up the table by calling [[resetTable()]].
*/
public function unload()
{
$this->resetTable();
parent::unload();
}
/**
* Returns the fixture data. * Returns the fixture data.
* *
* The default implementation will try to return the fixture data by including the external file specified by [[dataFile]]. * The default implementation will try to return the fixture data by including the external file specified by [[dataFile]].
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment