Skip to content

Commit

Permalink
Added to the basic app, fixed config, added to core commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ragazzo committed Jan 3, 2014
1 parent 6291d0c commit ccfb763
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
14 changes: 14 additions & 0 deletions apps/basic/config/console.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

Yii::setAlias('tests', __DIR__ . '/../tests');

$params = require(__DIR__ . '/params.php');
return [
'id' => 'basic-console',
Expand All @@ -19,6 +22,17 @@
],
],
],
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2basic',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
'fixture' => [
'class' => 'yii\test\DbFixtureManager',
'basePath' => '@tests/unit/fixtures',
],
],
'params' => $params,
];
Empty file.
Empty file.
1 change: 1 addition & 0 deletions framework/yii/console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public function coreCommands()
'migrate' => 'yii\console\controllers\MigrateController',
'cache' => 'yii\console\controllers\CacheController',
'asset' => 'yii\console\controllers\AssetController',
'fixture' => 'yii\console\controllers\FixtureController',
];
}

Expand Down
25 changes: 23 additions & 2 deletions framework/yii/console/controllers/FixtureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,18 @@ public function beforeAction($action)
* you can specify table name as a second parameter.
* @param string $fixture
*/
public function actionApply($fixture)
public function actionApply(array $fixture)
{
if ($this->getFixtureManager() == null) {
throw new Exception(
'Fixture manager is not configured properly. '
. 'Please refer to official documentation for this purposes.');
}

$this->getFixtureManager()->basePath = $this->fixturePath;
$this->getFixtureManager()->db = $this->db;
$this->loadFixtures([$fixture]);
$this->loadFixtures($fixture);
$this->notifySuccess($fixture);
}

/**
Expand Down Expand Up @@ -150,4 +157,18 @@ public function getDbConnection()
return $db;
}

/**
* Notifies user that fixtures were successfully loaded.
* @param array $fixtures
*/
private function notifySuccess($fixtures)
{
$this->stdout("Fixtures were successfully loaded from path: \n", Console::FG_YELLOW);
$this->stdout(realpath(Yii::getAlias($this->fixturePath)) . "\n\n", Console::FG_GREEN);

foreach($fixtures as $index => $fixture) {
$this->stdout($index +1 . ". " . $fixture . "\n", Console::FG_GREEN);
}
}

}

0 comments on commit ccfb763

Please sign in to comment.