Fixes #11683: Fixed fixture command to work with short syntax. yii fixture "*, -User" should be used instead of yii fixture "*" -User

This commit is contained in:
Angel Guevara
2016-06-06 23:15:01 -05:00
committed by Alexander Makarov
parent 326cdfeb52
commit 8c240ed067
8 changed files with 53 additions and 53 deletions

View File

@ -310,7 +310,7 @@ yii fixture/load User
yii fixture User
// carga varios fixtures
yii fixture User UserProfile
yii fixture "User, UserProfile"
// carga todos los fixtures
yii fixture/load "*"
@ -319,7 +319,7 @@ yii fixture/load "*"
yii fixture "*"
// carga todos los fixtures excepto uno
yii fixture "*" -DoNotLoadThisOne
yii fixture "*, -DoNotLoadThisOne"
// carga fixtures, pero los busca en diferente espacio de nombre. El espacio de nombre por defecto es: tests\unit\fixtures.
yii fixture User --namespace='alias\my\custom\namespace'
@ -340,13 +340,13 @@ Para descargar un fixture, ejecuta el siguiente comando:
yii fixture/unload User
// descarga varios fixtures
yii fixture/unload User,UserProfile
yii fixture/unload "User, UserProfile"
// descarga todos los fixtures
yii fixture/unload "*"
// descarga todos los fixtures excepto uno
yii fixture/unload "*" -DoNotUnloadThisOne
yii fixture/unload "*, -DoNotUnloadThisOne"
```

View File

@ -307,7 +307,7 @@ yii fixture/load User
yii fixture User
// load several fixtures
yii fixture User UserProfile
yii fixture "User, UserProfile"
// load all fixtures
yii fixture/load "*"
@ -316,7 +316,7 @@ yii fixture/load "*"
yii fixture "*"
// load all fixtures except ones
yii fixture "*" -DoNotLoadThisOne
yii fixture "*, -DoNotLoadThisOne"
// load fixtures, but search them in different namespace. By default namespace is: tests\unit\fixtures.
yii fixture User --namespace='alias\my\custom\namespace'
@ -337,13 +337,13 @@ To unload fixture, run the following command:
yii fixture/unload User
// Unload several fixtures
yii fixture/unload User,UserProfile
yii fixture/unload "User, UserProfile"
// unload all fixtures
yii fixture/unload "*"
// unload all fixtures except ones
yii fixture/unload "*" -DoNotUnloadThisOne
yii fixture/unload "*, -DoNotUnloadThisOne"
```

View File

@ -312,7 +312,7 @@ yii fixture/load User
yii fixture User
// загрузить нескольких фикстур
yii fixture User UserProfile
yii fixture "User, UserProfile"
// загрузить все фикстуры
yii fixture/load "*"
@ -321,7 +321,7 @@ yii fixture/load "*"
yii fixture "*"
// загрузить все фикстуры кроме указанной
yii fixture "*" -DoNotLoadThisOne
yii fixture "*, -DoNotLoadThisOne"
// загрузка фикстур, но искать их следует в другом пространстве имен. Пространство имен по умолчанию: tests\unit\fixtures.
yii fixture User --namespace='alias\my\custom\namespace'
@ -342,13 +342,13 @@ yii fixture User --globalFixtures='some\name\space\Custom'
yii fixture/unload User
// выгрузить несколько фикстур
yii fixture/unload User,UserProfile
yii fixture/unload "User, UserProfile"
// выгрузить все фикстуры
yii fixture/unload "*"
// выгрузить все фикстуры за исключением указанной
yii fixture/unload "*" -DoNotUnloadThisOne
yii fixture/unload "*, -DoNotUnloadThisOne"
```

View File

@ -310,7 +310,7 @@ yii fixture/load User
yii fixture User
// load several fixtures
yii fixture User UserProfile
yii fixture "User, UserProfile"
// load all fixtures
yii fixture/load "*"
@ -319,7 +319,7 @@ yii fixture/load "*"
yii fixture "*"
// load all fixtures except ones
yii fixture "*" -DoNotLoadThisOne
yii fixture "*, -DoNotLoadThisOne"
// load fixtures, but search them in different namespace. By default namespace is: tests\unit\fixtures.
yii fixture User --namespace='alias\my\custom\namespace'
@ -340,13 +340,13 @@ To unload fixture, run the following command:
yii fixture/unload User
// Unload several fixtures
yii fixture/unload User,UserProfile
yii fixture/unload "User, UserProfile"
// unload all fixtures
yii fixture/unload "*"
// unload all fixtures except ones
yii fixture/unload "*" -DoNotUnloadThisOne
yii fixture/unload "*, -DoNotUnloadThisOne"
```

View File

@ -60,6 +60,7 @@ Yii Framework 2 Change Log
- Bug #11322: Fixed incorrect error message in `yii\validators\UniqueValidator` for composite `targetAttribute` (PowerGamer1, silverfire, cebe)
- Chg #11364: Updated jQuery dependency to include versions `1.12.*` (cebe)
- Bug #11252: Use strict comparison on ActiveRecord::hasAttribute() to avoid cases where it returns true when a number is passed to it (Faryshta)
- Chg #11683: Fixed fixture command to work with short syntax. `yii fixture "*, -User"` should be used instead of `yii fixture "*" -User` (Faryshta, samdark)
2.0.8 April 28, 2016

View File

@ -20,6 +20,8 @@ Upgrade from Yii 2.0.8
* Part of code from `yii\web\User::loginByCookie()` method was moved to new `getIdentityAndDurationFromCookie()`
and `removeIdentityCookie()` methods. If you override `loginByCookie()` method, update it in order use new methods.
* Fixture console command syntax was changed from `yii fixture "*" -User` to `yii fixture "*, -User"`. Upgrade your
scripts if necessary.
Upgrade from Yii 2.0.7
----------------------

View File

@ -28,7 +28,7 @@ use yii\test\FixtureTrait;
* yii fixture "*"
*
* #load all fixtures except User
* yii fixture "*" -User
* yii fixture "*, -User"
*
* #load fixtures with different namespace.
* yii fixture/load User --namespace=alias\my\custom\namespace\goes\here
@ -89,20 +89,19 @@ class FixtureController extends Controller
* ```
* # load the fixture data specified by User and UserProfile.
* # any existing fixture data will be removed first
* yii fixture/load User UserProfile
* yii fixture/load "User, UserProfile"
*
* # load all available fixtures found under 'tests\unit\fixtures'
* yii fixture/load "*"
*
* # load all fixtures except User and UserProfile
* yii fixture/load "*" -User -UserProfile
* yii fixture/load "*, -User, -UserProfile"
* ```
*
* @throws Exception if the specified fixture does not exist.
*/
public function actionLoad()
public function actionLoad(array $fixturesInput = [])
{
$fixturesInput = func_get_args();
if ($fixturesInput === []) {
$this->stdout($this->getHelpSummary() . "\n");
@ -116,7 +115,6 @@ class FixtureController extends Controller
$except = $filtered['except'];
if (!$this->needToApplyAll($fixturesInput[0])) {
$fixtures = $filtered['apply'];
$foundFixtures = $this->findFixtures($fixtures);
@ -125,7 +123,6 @@ class FixtureController extends Controller
if ($notFoundFixtures) {
$this->notifyNotFound($notFoundFixtures);
}
} else {
$foundFixtures = $this->findFixtures();
}
@ -134,8 +131,8 @@ class FixtureController extends Controller
if (!$foundFixtures) {
throw new Exception(
"No files were found by name: \"" . implode(', ', $fixturesInput) . "\".\n" .
"Check that files with these name exists, under fixtures path: \n\"" . $this->getFixturePath() . "\"."
"No files were found for: \"" . implode(', ', $fixturesInput) . "\".\n" .
"Check that files exist under fixtures path: \n\"" . $this->getFixturePath() . "\"."
);
}
@ -169,25 +166,23 @@ class FixtureController extends Controller
*
* ```
* # unload the fixture data specified by User and UserProfile.
* yii fixture/unload User UserProfile
* yii fixture/unload "User, UserProfile"
*
* # unload all fixtures found under 'tests\unit\fixtures'
* yii fixture/unload "*"
*
* # unload all fixtures except User and UserProfile
* yii fixture/unload "*" -User -UserProfile
* yii fixture/unload "*, -User, -UserProfile"
* ```
*
* @throws Exception if the specified fixture does not exist.
*/
public function actionUnload()
public function actionUnload(array $fixturesInput = [])
{
$fixturesInput = func_get_args();
$filtered = $this->filterFixtures($fixturesInput);
$except = $filtered['except'];
if (!$this->needToApplyAll($fixturesInput[0])) {
$fixtures = $filtered['apply'];
$foundFixtures = $this->findFixtures($fixtures);
@ -196,7 +191,6 @@ class FixtureController extends Controller
if ($notFoundFixtures) {
$this->notifyNotFound($notFoundFixtures);
}
} else {
$foundFixtures = $this->findFixtures();
}
@ -205,8 +199,8 @@ class FixtureController extends Controller
if (!$foundFixtures) {
throw new Exception(
"No files were found by name: \"" . implode(', ', $fixturesInput) . "\".\n" .
"Check that files with these name exists, under fixtures path: \n\"" . $this->getFixturePath() . "\"."
"No files were found for: \"" . implode(', ', $fixturesInput) . "\".\n" .
"Check that files exist under fixtures path: \n\"" . $this->getFixturePath() . "\"."
);
}
@ -269,12 +263,12 @@ class FixtureController extends Controller
*/
public function notifyNothingToUnload($foundFixtures, $except)
{
$this->stdout("Fixtures to unload could not be found according given conditions:\n\n", Console::FG_RED);
$this->stdout("Fixtures to unload could not be found according to given conditions:\n\n", Console::FG_RED);
$this->stdout("Fixtures namespace is: \n", Console::FG_YELLOW);
$this->stdout("\t" . $this->namespace . "\n", Console::FG_GREEN);
if (count($foundFixtures)) {
$this->stdout("\nFixtures founded under the namespace:\n\n", Console::FG_YELLOW);
$this->stdout("\nFixtures found under the namespace:\n\n", Console::FG_YELLOW);
$this->outputList($foundFixtures);
}
@ -404,7 +398,6 @@ class FixtureController extends Controller
$findAll = ($fixtures === []);
if (!$findAll) {
$filesToSearch = [];
foreach ($fixtures as $fileName) {
@ -432,7 +425,6 @@ class FixtureController extends Controller
$config = [];
foreach ($fixtures as $fixture) {
$isNamespaced = (strpos($fixture, '\\') !== false);
$fullClassName = $isNamespaced ? $fixture . 'Fixture' : $this->namespace . '\\' . $fixture . 'Fixture';

View File

@ -30,7 +30,7 @@ class FixtureControllerTest extends TestCase
'interactive' => false,
'globalFixtures' => [],
'namespace' => 'yiiunit\data\console\controllers\fixtures',
],[null, null]); //id and module are null
], [null, null]); //id and module are null
}
protected function tearDown()
@ -47,7 +47,7 @@ class FixtureControllerTest extends TestCase
'\yiiunit\data\console\controllers\fixtures\Global'
];
$this->_fixtureController->actionLoad('First');
$this->_fixtureController->actionLoad(['First']);
$this->assertCount(1, FixtureStorage::$globalFixturesData, 'global fixture data should be loaded');
$this->assertCount(1, FixtureStorage::$firstFixtureData, 'first fixture data should be loaded');
@ -65,7 +65,7 @@ class FixtureControllerTest extends TestCase
$this->assertCount(1, FixtureStorage::$globalFixturesData, 'global fixture data should be loaded');
$this->assertCount(1, FixtureStorage::$firstFixtureData, 'first fixture data should be loaded');
$this->_fixtureController->actionUnload('First');
$this->_fixtureController->actionUnload(['First']);
$this->assertEmpty(FixtureStorage::$globalFixturesData, 'global fixture data should be unloaded');
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should be unloaded');
@ -77,7 +77,7 @@ class FixtureControllerTest extends TestCase
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should be empty');
$this->assertEmpty(FixtureStorage::$secondFixtureData, 'second fixture data should be empty');
$this->_fixtureController->actionLoad('*');
$this->_fixtureController->actionLoad(['*']);
$this->assertCount(1, FixtureStorage::$globalFixturesData, 'global fixture data should be loaded');
$this->assertCount(1, FixtureStorage::$firstFixtureData, 'first fixture data should be loaded');
@ -94,7 +94,7 @@ class FixtureControllerTest extends TestCase
$this->assertCount(1, FixtureStorage::$firstFixtureData, 'first fixture data should be loaded');
$this->assertCount(1, FixtureStorage::$secondFixtureData, 'second fixture data should be loaded');
$this->_fixtureController->actionUnload('*');
$this->_fixtureController->actionUnload(['*']);
$this->assertEmpty(FixtureStorage::$globalFixturesData, 'global fixture data should be unloaded');
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should be unloaded');
@ -103,7 +103,7 @@ class FixtureControllerTest extends TestCase
public function testLoadParticularExceptOnes()
{
$this->_fixtureController->actionLoad('First', '-Second', '-Global');
$this->_fixtureController->actionLoad(['First', '-Second', '-Global']);
$this->assertCount(1, FixtureStorage::$firstFixtureData, 'first fixture data should be loaded');
$this->assertEmpty(FixtureStorage::$globalFixturesData, 'global fixture data should not be loaded');
@ -116,7 +116,11 @@ class FixtureControllerTest extends TestCase
FixtureStorage::$firstFixtureData[] = 'some seeded first fixture data';
FixtureStorage::$secondFixtureData[] = 'some seeded second fixture data';
$this->_fixtureController->actionUnload('First', '-Second', '-Global');
$this->_fixtureController->actionUnload([
'First',
'-Second',
'-Global',
]);
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should be unloaded');
$this->assertNotEmpty(FixtureStorage::$globalFixturesData, 'global fixture data should not be unloaded');
@ -125,7 +129,7 @@ class FixtureControllerTest extends TestCase
public function testLoadAllExceptOnes()
{
$this->_fixtureController->actionLoad('*', '-Second', '-Global');
$this->_fixtureController->actionLoad(['*', '-Second', '-Global']);
$this->assertCount(1, FixtureStorage::$firstFixtureData, 'first fixture data should be loaded');
$this->assertEmpty(FixtureStorage::$globalFixturesData, 'global fixture data should not be loaded');
@ -138,7 +142,7 @@ class FixtureControllerTest extends TestCase
FixtureStorage::$firstFixtureData[] = 'some seeded first fixture data';
FixtureStorage::$secondFixtureData[] = 'some seeded second fixture data';
$this->_fixtureController->actionUnload('*', '-Second', '-Global');
$this->_fixtureController->actionUnload(['*', '-Second', '-Global']);
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should be unloaded');
$this->assertNotEmpty(FixtureStorage::$globalFixturesData, 'global fixture data should not be unloaded');
@ -147,14 +151,17 @@ class FixtureControllerTest extends TestCase
public function testNothingToLoadParticularExceptOnes()
{
$this->_fixtureController->actionLoad('First', '-First');
$this->_fixtureController->actionLoad(['First', '-First']);
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should not be loaded');
$this->assertEmpty(
FixtureStorage::$firstFixtureData,
'first fixture data should not be loaded'
);
}
public function testNothingToUnloadParticularExceptOnes()
{
$this->_fixtureController->actionUnload('First', '-First');
$this->_fixtureController->actionUnload(['First', '-First']);
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should not be loaded');
}
@ -164,7 +171,7 @@ class FixtureControllerTest extends TestCase
*/
public function testNoFixturesWereFoundInLoad()
{
$this->_fixtureController->actionLoad('NotExistingFixture');
$this->_fixtureController->actionLoad(['NotExistingFixture']);
}
/**
@ -172,9 +179,8 @@ class FixtureControllerTest extends TestCase
*/
public function testNoFixturesWereFoundInUnload()
{
$this->_fixtureController->actionUnload('NotExistingFixture');
$this->_fixtureController->actionUnload(['NotExistingFixture']);
}
}
class FixtureConsoledController extends FixtureController
@ -183,5 +189,4 @@ class FixtureConsoledController extends FixtureController
public function stdout($string)
{
}
}