From 7c00f824eb4b562f72bfaeab1e804374861a1298 Mon Sep 17 00:00:00 2001 From: Eric Lamb Date: Mon, 30 Oct 2023 17:37:53 -0700 Subject: [PATCH 1/6] adds "path" param to allow for custom test locations outside an Add-on --- .../addons/unit_tests/src/Commands/Tests.php | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/system/user/addons/unit_tests/src/Commands/Tests.php b/system/user/addons/unit_tests/src/Commands/Tests.php index 21d57a9..37fbafb 100644 --- a/system/user/addons/unit_tests/src/Commands/Tests.php +++ b/system/user/addons/unit_tests/src/Commands/Tests.php @@ -44,7 +44,8 @@ class Tests extends Cli * @var array */ public $commandOptions = [ - 'addon,a:' => 'The Addon Tests you want to run' + 'addon,a:' => 'The Addon Tests you want to run', + 'path,p:' => 'A custom path to the tests you want to run. Must be full path.', ]; /** @@ -53,27 +54,30 @@ class Tests extends Cli */ public function handle() { - ee()->lang->loadfile('unit_tests'); - $addon = $this->option('-a'); - if(!ee('App')->has($addon)) { - return $this->error( - 'm62.ut.addon_not_found' - ); - } + $tests_path = $this->option('-p'); + if(!$tests_path) { + ee()->lang->loadfile('unit_tests'); + $addon = $this->option('-a'); + if (!ee('App')->has($addon)) { + return $this->error( + 'm62.ut.addon_not_found' + ); + } - //prob redundant but shit happens so :shrug: - $addon = ee('App')->get($this->option('-a')); - if(!$addon instanceof Provider) { - return $this->error( - 'm62.ut.addon_not_found' - ); - } + //prob redundant but shit happens so :shrug: + $addon = ee('App')->get($this->option('-a')); + if (!$addon instanceof Provider) { + return $this->error( + 'm62.ut.addon_not_found' + ); + } - $tests_path = Args::buildPath($addon); - if(!$tests_path) { - return $this->error( - 'm62.ut.cannot_find_tests_dir' - ); + $tests_path = Args::buildPath($addon); + if (!$tests_path) { + return $this->error( + 'm62.ut.cannot_find_tests_dir' + ); + } } $_SERVER['argv'] = Args::buildArgs($tests_path); From 777bd038db26188432ad43d9df6a23a78673d581 Mon Sep 17 00:00:00 2001 From: Eric Lamb Date: Mon, 30 Oct 2023 17:43:11 -0700 Subject: [PATCH 2/6] adds tests for new path option --- .../src/Tests/Commands/TestsTest.php | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/system/user/addons/unit_tests/src/Tests/Commands/TestsTest.php b/system/user/addons/unit_tests/src/Tests/Commands/TestsTest.php index 29fca9c..6ebad39 100644 --- a/system/user/addons/unit_tests/src/Tests/Commands/TestsTest.php +++ b/system/user/addons/unit_tests/src/Tests/Commands/TestsTest.php @@ -15,7 +15,7 @@ public function testParentInstance(): TestsCommand /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testSignatureAttributeExists(TestsCommand $command): TestsCommand @@ -26,7 +26,7 @@ public function testSignatureAttributeExists(TestsCommand $command): TestsComman /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testSignatureValue(TestsCommand $command): TestsCommand @@ -37,7 +37,7 @@ public function testSignatureValue(TestsCommand $command): TestsCommand /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testNameAttributeExists(TestsCommand $command): TestsCommand @@ -48,7 +48,7 @@ public function testNameAttributeExists(TestsCommand $command): TestsCommand /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testNameValue(TestsCommand $command): TestsCommand @@ -59,7 +59,7 @@ public function testNameValue(TestsCommand $command): TestsCommand /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testDescAttributeExists(TestsCommand $command): TestsCommand @@ -70,7 +70,7 @@ public function testDescAttributeExists(TestsCommand $command): TestsCommand /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testDescValue(TestsCommand $command): TestsCommand @@ -81,7 +81,7 @@ public function testDescValue(TestsCommand $command): TestsCommand /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testSummaryAttributeExists(TestsCommand $command): TestsCommand @@ -92,7 +92,7 @@ public function testSummaryAttributeExists(TestsCommand $command): TestsCommand /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testSummaryValue(TestsCommand $command): TestsCommand @@ -103,7 +103,7 @@ public function testSummaryValue(TestsCommand $command): TestsCommand /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testUsageAttributeExists(TestsCommand $command): TestsCommand @@ -114,7 +114,7 @@ public function testUsageAttributeExists(TestsCommand $command): TestsCommand /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testUsageIsArray(TestsCommand $command): TestsCommand @@ -125,7 +125,7 @@ public function testUsageIsArray(TestsCommand $command): TestsCommand /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testUsageTotalValues(TestsCommand $command): TestsCommand @@ -136,7 +136,7 @@ public function testUsageTotalValues(TestsCommand $command): TestsCommand /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testOptionsAttributeExists(TestsCommand $command): TestsCommand @@ -147,7 +147,7 @@ public function testOptionsAttributeExists(TestsCommand $command): TestsCommand /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testOptionsIsArray(TestsCommand $command): TestsCommand @@ -158,18 +158,18 @@ public function testOptionsIsArray(TestsCommand $command): TestsCommand /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testOptionsTotalValues(TestsCommand $command): TestsCommand { - $this->assertCount(1, $command->commandOptions); + $this->assertCount(2, $command->commandOptions); return $command; } /** * @depends testParentInstance - * @param $command + * @param TestsCommand $command * @return TestsCommand */ public function testAOptionExists(TestsCommand $command): TestsCommand @@ -177,4 +177,15 @@ public function testAOptionExists(TestsCommand $command): TestsCommand $this->assertTrue(array_key_exists('addon,a:', $command->commandOptions)); return $command; } + + /** + * @depends testAOptionExists + * @param TestsCommand $command + * @return TestsCommand + */ + public function testPOptionExists(TestsCommand $command): TestsCommand + { + $this->assertTrue(array_key_exists('path,p:', $command->commandOptions)); + return $command; + } } \ No newline at end of file From cdd90136ae51d3b485cbd1192641d0297abef552 Mon Sep 17 00:00:00 2001 From: Eric Lamb Date: Mon, 30 Oct 2023 17:48:52 -0700 Subject: [PATCH 3/6] adds List Command test suite --- .../src/Tests/Commands/ListTest.php | 169 ++++++++++++++++++ .../addons/unit_tests/src/Tests/phpunit.xml | 2 +- 2 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 system/user/addons/unit_tests/src/Tests/Commands/ListTest.php diff --git a/system/user/addons/unit_tests/src/Tests/Commands/ListTest.php b/system/user/addons/unit_tests/src/Tests/Commands/ListTest.php new file mode 100644 index 0000000..c9863ae --- /dev/null +++ b/system/user/addons/unit_tests/src/Tests/Commands/ListTest.php @@ -0,0 +1,169 @@ +assertInstanceOf('ExpressionEngine\Cli\Cli', $command); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testSignatureAttributeExists(TestsCommand $command): TestsCommand + { + $this->assertObjectHasAttribute('signature', $command); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testSignatureValue(TestsCommand $command): TestsCommand + { + $this->assertEquals('tests:list', $command->signature); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testNameAttributeExists(TestsCommand $command): TestsCommand + { + $this->assertObjectHasAttribute('name', $command); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testNameValue(TestsCommand $command): TestsCommand + { + $this->assertNotNull($command->name); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testDescAttributeExists(TestsCommand $command): TestsCommand + { + $this->assertObjectHasAttribute('description', $command); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testDescValue(TestsCommand $command): TestsCommand + { + $this->assertNotNull($command->description); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testSummaryAttributeExists(TestsCommand $command): TestsCommand + { + $this->assertObjectHasAttribute('summary', $command); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testSummaryValue(TestsCommand $command): TestsCommand + { + $this->assertNotNull($command->summary); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testUsageAttributeExists(TestsCommand $command): TestsCommand + { + $this->assertObjectHasAttribute('usage', $command); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testUsageIsArray(TestsCommand $command): TestsCommand + { + $this->assertTrue(is_array($command->usage)); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testUsageTotalValues(TestsCommand $command): TestsCommand + { + $this->assertCount(1, $command->usage); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testOptionsAttributeExists(TestsCommand $command): TestsCommand + { + $this->assertObjectHasAttribute('commandOptions', $command); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testOptionsIsArray(TestsCommand $command): TestsCommand + { + $this->assertTrue(is_array($command->commandOptions)); + return $command; + } + + /** + * @depends testParentInstance + * @param TestsCommand $command + * @return TestsCommand + */ + public function testOptionsTotalValues(TestsCommand $command): TestsCommand + { + $this->assertCount(0, $command->commandOptions); + return $command; + } +} \ No newline at end of file diff --git a/system/user/addons/unit_tests/src/Tests/phpunit.xml b/system/user/addons/unit_tests/src/Tests/phpunit.xml index e0501c4..642ce24 100644 --- a/system/user/addons/unit_tests/src/Tests/phpunit.xml +++ b/system/user/addons/unit_tests/src/Tests/phpunit.xml @@ -12,7 +12,7 @@ stopOnSkipped="true" printerClass="PHPUnit\TextUI\DefaultResultPrinter"> - + ./ From c6e4bd21b36e35b02e521a0c4abcee8d64d76272 Mon Sep 17 00:00:00 2001 From: Eric Lamb Date: Mon, 30 Oct 2023 17:54:31 -0700 Subject: [PATCH 4/6] adds example for the path param --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4c4fe34..987c18a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,10 @@ This will execute the Tests within the `unit_tests` add-on. `php ./system/eecli.php tests:run -a your_addon_name` +This will execute the Tests within the `unit_tests` add-on. + +`php ./system/eecli.php tests:run -p /full/path/to/tests + The below will display the available tests on the system `php ./system/eecli.php tests:list` From c3019fef8c1ad1dbe085c2415eb39509caeb69f3 Mon Sep 17 00:00:00 2001 From: Eric Lamb Date: Mon, 30 Oct 2023 17:54:55 -0700 Subject: [PATCH 5/6] missing tick --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 987c18a..0ee80c0 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ This will execute the Tests within the `unit_tests` add-on. This will execute the Tests within the `unit_tests` add-on. -`php ./system/eecli.php tests:run -p /full/path/to/tests +`php ./system/eecli.php tests:run -p /full/path/to/tests` The below will display the available tests on the system From e173a3fc15f5b1980fdc827ee78eaae9343b40bf Mon Sep 17 00:00:00 2001 From: Eric Lamb Date: Mon, 30 Oct 2023 17:55:36 -0700 Subject: [PATCH 6/6] updates description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ee80c0..8a9a823 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ This will execute the Tests within the `unit_tests` add-on. `php ./system/eecli.php tests:run -a your_addon_name` -This will execute the Tests within the `unit_tests` add-on. +This will execute the Tests located at `p`. `php ./system/eecli.php tests:run -p /full/path/to/tests`