From 5b5150ae62e1e2c0391e968aa18d04ecbf59f69e Mon Sep 17 00:00:00 2001 From: Nikolay Poryadin Date: Sat, 9 Mar 2019 15:35:19 +0300 Subject: [PATCH] Fixes #17133: Fixed aliases rendering during help generation for a console command --- framework/CHANGELOG.md | 1 + .../console/controllers/HelpController.php | 2 +- tests/framework/console/ControllerTest.php | 5 +++++ .../FakeHelpControllerWithoutOutput.php | 21 +++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/framework/console/FakeHelpControllerWithoutOutput.php diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 44b978c0cd..c3dbc394d4 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.17 under development ------------------------ +- Bug #17133: Fixed aliases rendering during help generation for a console command (GHopperMSK) - Bug #17185: Fixed `AssetManager` timestamp appending when a file is published manually (GHopperMSK) - Bug #17156: Fixes PHP 7.2 warning when a data provider has no data as a parameter for a GridView (evilito) - Bug #17083: Fixed `yii\validators\EmailValidator::$checkDNS` tells that every domain is correct on alpine linux (mikk150) diff --git a/framework/console/controllers/HelpController.php b/framework/console/controllers/HelpController.php index 20d695fb0e..0155d2e7c2 100644 --- a/framework/console/controllers/HelpController.php +++ b/framework/console/controllers/HelpController.php @@ -532,7 +532,7 @@ class HelpController extends Controller protected function formatOptionAliases($controller, $option) { foreach ($controller->optionAliases() as $name => $value) { - if ($value === $option) { + if (Inflector::camel2id($value, '-', true) === $option) { return ', -' . $name; } } diff --git a/tests/framework/console/ControllerTest.php b/tests/framework/console/ControllerTest.php index 6f685e5d01..4292c0bb04 100644 --- a/tests/framework/console/ControllerTest.php +++ b/tests/framework/console/ControllerTest.php @@ -23,6 +23,7 @@ class ControllerTest extends TestCase $this->mockApplication(); Yii::$app->controllerMap = [ 'fake' => 'yiiunit\framework\console\FakeController', + 'fake_witout_output' => 'yiiunit\framework\console\FakeHelpControllerWithoutOutput', 'help' => 'yiiunit\framework\console\FakeHelpController', ]; } @@ -127,6 +128,10 @@ class ControllerTest extends TestCase $this->assertFalse(FakeController::getWasActionIndexCalled()); $this->assertEquals(FakeHelpController::getActionIndexLastCallParams(), ['posts/index']); + + $helpController = new FakeHelpControllerWithoutOutput('help', Yii::$app); + $helpController->actionIndex('fake/aksi1'); + $this->assertContains('--test-array, -ta', $helpController->outputString); } /** diff --git a/tests/framework/console/FakeHelpControllerWithoutOutput.php b/tests/framework/console/FakeHelpControllerWithoutOutput.php new file mode 100644 index 0000000000..fbd581adf2 --- /dev/null +++ b/tests/framework/console/FakeHelpControllerWithoutOutput.php @@ -0,0 +1,21 @@ +outputString .= $string; + } +}