diff --git a/README.md b/README.md index 4c4fe34..8a9a823 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 located at `p`. + +`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` 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); 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/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 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"> - + ./