From 9459eaa277d56baac3300bfb22ea2f669abf9b0d Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 15 Mar 2017 13:47:21 +0100 Subject: [PATCH] Fixes #10372: Fixed console controller including complex typed arguments in help --- framework/CHANGELOG.md | 2 +- framework/console/Controller.php | 3 +++ tests/framework/console/ControllerTest.php | 14 ++++++++++++++ tests/framework/console/FakeController.php | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 7b7de64cedc..51a9a532b49 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -46,7 +46,7 @@ Yii Framework 2 Change Log - Enh #13695: `\yii\web\Response::setStatusCode()` method now returns the Response object itself (kyle-mccarthy) - Enh #13698: `yii\grid\DataColumn` filter is automatically generated as dropdown list in case of `format` set to `boolean` (bizley) - Enh #13254: Core validators no longer require Yii::$app to be set (sammousa) - +- Bug #10372: Fixed console controller including complex typed arguments in help (sammousa) 2.0.11.2 February 08, 2017 -------------------------- diff --git a/framework/console/Controller.php b/framework/console/Controller.php index 2225e02cdcb..7cd4999ac6f 100644 --- a/framework/console/Controller.php +++ b/framework/console/Controller.php @@ -467,6 +467,9 @@ public function getActionArgsHelp($action) /** @var \ReflectionParameter $reflection */ foreach ($method->getParameters() as $i => $reflection) { + if ($reflection->getClass() !== null) { + continue; + } $name = $reflection->getName(); $tag = isset($params[$i]) ? $params[$i] : ''; if (preg_match('/^(\S+)\s+(\$\w+\s+)?(.*)/s', $tag, $matches)) { diff --git a/tests/framework/console/ControllerTest.php b/tests/framework/console/ControllerTest.php index 00343f75d30..041bc844848 100644 --- a/tests/framework/console/ControllerTest.php +++ b/tests/framework/console/ControllerTest.php @@ -132,4 +132,18 @@ public function testHelpOptionWithModule() $this->assertFalse(FakeController::getWasActionIndexCalled()); $this->assertEquals(FakeHelpController::getActionIndexLastCallParams(), ['news/posts/index']); } + + + /** + * Tests if action help does not include (class) type hinted arguments. + * @see #10372 + */ + public function testHelpSkipsTypeHintedArguments() + { + $controller = new FakeController('fake', Yii::$app); + $help = $controller->getActionArgsHelp($controller->createAction('with-complex-type-hint')); + + $this->assertArrayNotHasKey('typedArgument', $help); + $this->assertArrayHasKey('simpleArgument', $help); + } } diff --git a/tests/framework/console/FakeController.php b/tests/framework/console/FakeController.php index 8f00b2ebfd1..2fc6ab18c8d 100644 --- a/tests/framework/console/FakeController.php +++ b/tests/framework/console/FakeController.php @@ -84,6 +84,10 @@ public function actionAksi6() return $this->testArray; } + public function actionWithComplexTypeHint(self $typedArgument, $simpleArgument) { + return $simpleArgument; + } + public function actionStatus($status = 0) { return $status;