Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
44 changes: 24 additions & 20 deletions system/user/addons/unit_tests/src/Commands/Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
];

/**
Expand All @@ -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);
Expand Down
169 changes: 169 additions & 0 deletions system/user/addons/unit_tests/src/Tests/Commands/ListTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php
namespace Mithra62\UnitTests\Tests\Commands;

use PHPUnit\Framework\TestCase;
use Mithra62\UnitTests\Commands\ListIt AS TestsCommand;

class ListTest extends TestCase
{
public function testParentInstance(): TestsCommand
{
$command = new TestsCommand;
$this->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;
}
}
43 changes: 27 additions & 16 deletions system/user/addons/unit_tests/src/Tests/Commands/TestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testParentInstance(): TestsCommand

/**
* @depends testParentInstance
* @param $command
* @param TestsCommand $command
* @return TestsCommand
*/
public function testSignatureAttributeExists(TestsCommand $command): TestsCommand
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -158,23 +158,34 @@ 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
{
$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;
}
}
Loading