From ccfb7638d07b9500ee2e6b35630fc5c8437f8321 Mon Sep 17 00:00:00 2001
From: Mark <mark.github@yandex.ru>
Date: Sat, 4 Jan 2014 01:16:05 +0400
Subject: [PATCH] Added to the basic app, fixed config, added to core commands.

---
 apps/basic/config/console.php                           | 14 ++++++++++++++
 apps/basic/tests/unit/fixtures/.gitkeep                 |  0
 apps/basic/tests/unit/templates/fixtures/.gitkeep       |  0
 framework/yii/console/Application.php                   |  1 +
 framework/yii/console/controllers/FixtureController.php | 25 +++++++++++++++++++++++--
 5 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 apps/basic/tests/unit/fixtures/.gitkeep
 create mode 100644 apps/basic/tests/unit/templates/fixtures/.gitkeep

diff --git a/apps/basic/config/console.php b/apps/basic/config/console.php
index 6f3f9a8..55630fc 100644
--- a/apps/basic/config/console.php
+++ b/apps/basic/config/console.php
@@ -1,4 +1,7 @@
 <?php
+
+Yii::setAlias('tests', __DIR__ . '/../tests');
+
 $params = require(__DIR__ . '/params.php');
 return [
 	'id' => 'basic-console',
@@ -19,6 +22,17 @@ return [
 				],
 			],
 		],
+		'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,
 ];
diff --git a/apps/basic/tests/unit/fixtures/.gitkeep b/apps/basic/tests/unit/fixtures/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/basic/tests/unit/fixtures/.gitkeep
diff --git a/apps/basic/tests/unit/templates/fixtures/.gitkeep b/apps/basic/tests/unit/templates/fixtures/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/basic/tests/unit/templates/fixtures/.gitkeep
diff --git a/framework/yii/console/Application.php b/framework/yii/console/Application.php
index 6701304..6117752 100644
--- a/framework/yii/console/Application.php
+++ b/framework/yii/console/Application.php
@@ -146,6 +146,7 @@ class Application extends \yii\base\Application
 			'migrate' => 'yii\console\controllers\MigrateController',
 			'cache' => 'yii\console\controllers\CacheController',
 			'asset' => 'yii\console\controllers\AssetController',
+			'fixture' => 'yii\console\controllers\FixtureController',
 		];
 	}
 
diff --git a/framework/yii/console/controllers/FixtureController.php b/framework/yii/console/controllers/FixtureController.php
index 84ab7d4..cb78a47 100644
--- a/framework/yii/console/controllers/FixtureController.php
+++ b/framework/yii/console/controllers/FixtureController.php
@@ -103,11 +103,18 @@ class FixtureController extends Controller
 	 * 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);
 	}
 
 	/**
@@ -150,4 +157,18 @@ class FixtureController extends Controller
 		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);
+		}
+	}
+
 }
--
libgit2 0.27.1