From 8d05e81bd4f7c5f2e8dd9a47af795b3e00c8d4fe Mon Sep 17 00:00:00 2001 From: Robert Korulczyk Date: Sun, 18 Jun 2017 17:40:15 +0200 Subject: [PATCH] Fixes #14307: Fixed PHP warning when `yii\console\UnknownCommandException` is thrown for empty command --- framework/CHANGELOG.md | 1 + framework/console/UnknownCommandException.php | 2 +- ...ommandExceptionTest.php => UnknownCommandExceptionTest.php} | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) rename tests/framework/console/{UnkownCommandExceptionTest.php => UnknownCommandExceptionTest.php} (96%) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index e97122470f..e84b0bba55 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -6,6 +6,7 @@ Yii Framework 2 Change Log - Bug #14248: `yii\console\controllers\MessageController` no longer outputs colorized filenames when console does not support text colorization (PowerGamer1) - Bug #14264: Fixed a bug where `yii\log\Logger::calculateTimings()` was not accepting messages with array tokens (bizley) +- Bug #14307: Fixed PHP warning when `yii\console\UnknownCommandException` is thrown for empty command (rob006) - Chg #14201: `yii\console\controllers\MessageController::extractMessagesFromTokens()` is now protected (faenir) - Enh #13787: Added `yii\db\Migration::$maxSqlOutputLength` that allows limiting number of characters for outputting SQL (thiagotalma) - Enh #14089: Added tests for `yii\base\Theme` (vladis84) diff --git a/framework/console/UnknownCommandException.php b/framework/console/UnknownCommandException.php index eeb9d755f3..1027148aa2 100644 --- a/framework/console/UnknownCommandException.php +++ b/framework/console/UnknownCommandException.php @@ -67,7 +67,7 @@ class UnknownCommandException extends Exception public function getSuggestedAlternatives() { $help = $this->application->createController('help'); - if ($help === false) { + if ($help === false || $this->command === '') { return []; } /** @var $helpController HelpController */ diff --git a/tests/framework/console/UnkownCommandExceptionTest.php b/tests/framework/console/UnknownCommandExceptionTest.php similarity index 96% rename from tests/framework/console/UnkownCommandExceptionTest.php rename to tests/framework/console/UnknownCommandExceptionTest.php index 6d743eca8a..2e3369c4a3 100644 --- a/tests/framework/console/UnkownCommandExceptionTest.php +++ b/tests/framework/console/UnknownCommandExceptionTest.php @@ -14,7 +14,7 @@ use yiiunit\TestCase; /** * @group console */ -class UnkownCommandExceptionTest extends TestCase +class UnknownCommandExceptionTest extends TestCase { public function setUp() { @@ -42,6 +42,7 @@ class UnkownCommandExceptionTest extends TestCase ['cach/fush', ['cache/flush']], ['cach/fushall', ['cache/flush-all']], ['what?', []], + ['', []], // test UTF 8 chars ['ёлка', []], // this crashes levenshtein because string is longer than 255 chars