Skip to content

Commit

Permalink
Fixes #10372: Fixed console controller including complex typed argume…
Browse files Browse the repository at this point in the history
…nts in help
  • Loading branch information
SamMousa authored and samdark committed Mar 15, 2017
1 parent 8192f84 commit 9459eaa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------
Expand Down
3 changes: 3 additions & 0 deletions framework/console/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
14 changes: 14 additions & 0 deletions tests/framework/console/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions tests/framework/console/FakeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9459eaa

Please sign in to comment.