From da3b9a06d8f0f5890e07a5ca07fbd35971038906 Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Thu, 25 Oct 2018 15:05:11 -0700 Subject: [PATCH 1/2] Enhance CommandRunnerTest --- system/CLI/CommandRunner.php | 12 ++++++--- tests/_support/Commands/AbstractInfo.php | 15 +++++++++++ tests/_support/Commands/AppInfo.php | 20 ++++++++++++++ tests/system/Commands/CommandsTest.php | 34 ++++++++++++++++++++++-- 4 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 tests/_support/Commands/AbstractInfo.php create mode 100644 tests/_support/Commands/AppInfo.php diff --git a/system/CLI/CommandRunner.php b/system/CLI/CommandRunner.php index 46c2e18f68ff..c09b6528e41f 100644 --- a/system/CLI/CommandRunner.php +++ b/system/CLI/CommandRunner.php @@ -1,4 +1,5 @@ -findQualifiedNameFromPath($file); - if (empty($className) || ! class_exists($className)) { continue; } + $class = new \ReflectionClass($className); + if ( ! $class->isInstantiable() || ! $class->isSubclassOf(BaseCommand::class)) + { + continue; + } + $class = new $className($this->logger, $this); // Store it! diff --git a/tests/_support/Commands/AbstractInfo.php b/tests/_support/Commands/AbstractInfo.php new file mode 100644 index 000000000000..b0013d1ffc24 --- /dev/null +++ b/tests/_support/Commands/AbstractInfo.php @@ -0,0 +1,15 @@ +assertContains('Displays basic usage information.', $result); } + public function testCustomCommand() + { + $this->runner->index(['app:info']); + $result = CITestStreamFilter::$buffer; + + $this->assertContains('CI Version:', $result); + } + + public function testNonexistantCommand() + { + // catch errors too + $this->stream_filter = stream_filter_append(STDERR, 'CITestStreamFilter'); + + $this->runner->index(['app:oops']); + $result = CITestStreamFilter::$buffer; + + $this->assertContains('not found', $result); + } + + public function testAbstractCommand() + { + // catch errors too + $this->stream_filter = stream_filter_append(STDERR, 'CITestStreamFilter'); + + $this->runner->index(['app:pablo']); + $result = CITestStreamFilter::$buffer; + + $this->assertContains('not found', $result); + } + } From 17778bc5a7f3066cb3978d9b1cb7569ab64d2467 Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Thu, 25 Oct 2018 15:18:17 -0700 Subject: [PATCH 2/2] Enhance CommandRunnerTest --- system/Autoloader/FileLocator.php | 4 +--- user_guide_src/source/changelog.rst | 11 +++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index 1a301aa03577..cb69d9f941c2 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -43,8 +43,7 @@ * Allows loading non-class files in a namespaced manner. * Works with Helpers, Views, etc. * - * @todo sanitize filenames prior to checking them... - * + * * @package CodeIgniter */ class FileLocator @@ -133,7 +132,6 @@ public function locateFile(string $file, string $folder = null, string $ext = 'p // IF we have a folder name, then the calling function // expects this file to be within that folder, like 'Views', // or 'libraries'. - // @todo Allow it to check with and without the nested folder. if ( ! empty($folder) && strpos($filename, $folder) === false) { $filename = $folder . '/' . $filename; diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 0a24177d480c..e7d593f90b45 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -25,6 +25,8 @@ public / - index #1295, #1313 system / + - CLI/ + - CommandRunner #1350, #1356 - Commands/ - Server/Serve #1313 - Config/ @@ -65,7 +67,7 @@ system / - Cast #1283 - HTTP #1239 - Router/ - - RouteCollection #1285 + - RouteCollection #1285, #1355 - Test/ - FeatureTestCase #1282 - CodeIgniter #1239 #1337 @@ -76,6 +78,8 @@ system / tests / - API/ - ResponseTraitTest #1302 + - Commands/ + - CommandsTest #1356 - Database/ - BaseBuilderTest #1217 - Live/ModelTest #1311 @@ -98,7 +102,7 @@ tests / - I18n/ - TimeTest #1273, #1316 - Router/ - - RouteTest #1285 + - RouteTest #1285, #1355 - View/ - ParserTest #1311 - EntityTest #1319 @@ -142,6 +146,9 @@ user_guide_src /source/ PRs merged: ----------- +- #1356 Testing/commands +- #1355 Handle duplicate HTTP verb and generic rules properly +- #1350 Checks if class is instantiable and is a command - #1348 Fix sphinx formatting in sessions - #1347 Fix sphinx formatting in sessions - #1342 Toolbar Styles