From 18fc8db32feab872999de8960a07d6f1a49ab3bc Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Tue, 22 Dec 2015 10:03:31 +0000 Subject: [PATCH] Fixes #10372: Fixed console controller including DI arguments in help --- framework/CHANGELOG.md | 1 + framework/console/Controller.php | 5 +++++ tests/framework/console/ControllerTest.php | 23 ++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index afd6fb2904..ea61588541 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -43,6 +43,7 @@ Yii Framework 2 Change Log - Bug #10142: Fixed `yii\validators\EmailValidator` to check the length of email properly (silverfire) - Bug #10278: Fixed `yii\helpers\BaseJson` support \SimpleXMLElement data (SilverFire, LAV45) - Bug #10302: Fixed JS function `yii.getQueryParams`, which parsed array variables incorrectly (servocoder, silverfire) +- Bug #10372: Fixed console controller including DI arguments in help (sammousa) - Bug #10385: Fixed `yii\validators\CaptchaValidator` passed incorrect hashKey to JS validator when `captchaAction` begins with `/` (silverfire) - Bug: Fixed generation of canonical URLs for `ViewAction` pages (samdark) - Bug: Fixed `mb_*` functions calls to use `UTF-8` or `Yii::$app->charset` (silverfire) diff --git a/framework/console/Controller.php b/framework/console/Controller.php index 97296a4956..6d4ed3f669 100644 --- a/framework/console/Controller.php +++ b/framework/console/Controller.php @@ -414,8 +414,13 @@ class Controller extends \yii\base\Controller $params = isset($tags['param']) ? (array) $tags['param'] : []; $args = []; + + /** @var \ReflectionParameter $reflection */ foreach ($method->getParameters() as $i => $reflection) { $name = $reflection->getName(); + if ($reflection->getClass() !== null) { + continue; + } $tag = isset($params[$i]) ? $params[$i] : ''; if (preg_match('/^(\S+)\s+(\$\w+\s+)?(.*)/s', $tag, $matches)) { $type = $matches[1]; diff --git a/tests/framework/console/ControllerTest.php b/tests/framework/console/ControllerTest.php index fb11146b40..74739cfc44 100644 --- a/tests/framework/console/ControllerTest.php +++ b/tests/framework/console/ControllerTest.php @@ -92,4 +92,27 @@ class ControllerTest extends TestCase $result = $controller->runAction('aksi7', $params); } + + /** + * Tests if action help does not include class-hinted arguments + * @see https://github.com/yiisoft/yii2/issues/10372 + */ + public function testHelp() + { + $this->mockApplication([ + 'components' => [ + 'barBelongApp' => [ + 'class' => Bar::className(), + 'foo' => 'belong_app' + ], + 'quxApp' => [ + 'class' => OtherQux::className(), + 'b' => 'belong_app' + ] + ] + ]); + $controller = new FakeController('fake', Yii::$app); + + $this->assertArrayNotHasKey('bar', $controller->getActionArgsHelp($controller->createAction('aksi1'))); + } }