Skip to content

Commit

Permalink
Test Runner
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed May 22, 2016
1 parent 1b5c0f4 commit ed7b7ff
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 18 deletions.
19 changes: 16 additions & 3 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,24 @@ class RoboFile extends \Robo\Tasks
/**
* Run the Robo unit tests.
*/
public function test($args = "")
public function test($args = "", $options =
[
'coverage-html' => false,
'coverage' => false
])
{
return $this->taskCodecept()
$taskCodecept = $this->taskCodecept()
->args($args);
}

if ($options['coverage']) {
$taskCodecept->coverageXml('../../build/logs/clover.xml');
}
if ($options['coverage-html']) {
$taskCodecept->coverageHtml('../../build/logs/coverage');
}

return $taskCodecept;
}

/**
* Code sniffer.
Expand Down
3 changes: 1 addition & 2 deletions robo
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ if (strpos(basename(__FILE__), 'phar')) {
}
}
$runner = new \Robo\Runner();
$statusCode = $runner->execute();
$statusCode = $runner->execute($_SERVER['argv']);
exit($statusCode);

28 changes: 18 additions & 10 deletions src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,27 @@ protected function loadRoboFile()
return true;
}

public function execute($input = null)
public function execute($argv, $output = null)
{
register_shutdown_function(array($this, 'shutdown'));
set_error_handler(array($this, 'handleError'));
$input = $this->prepareInput($input ? $input : $this->shebang($_SERVER['argv']));
$argv = $this->shebang($argv);
$input = $this->prepareInput($argv);
return $this->run($input, $output);
}

public function run($input = null, $output = null)
{
// If we were not provided a container, then create one
if (!Config::hasContainer()) {
// Set up our dependency injection container.
$container = new RoboContainer();
static::configureContainer($container, $input);
static::configureContainer($container, $input, $output);
static::addServiceProviders($container);
$container->share('application', \Robo\Application::class)
->withArgument('Robo')
->withArgument(self::VERSION)
->withMethodCall('setAutoExit', [false])
->withMethodCall('setDispatcher', ['eventDispatcher']);
Config::setContainer($container);

// Only register a shutdown function when we
// provide the container.
register_shutdown_function(array($this, 'shutdown'));
set_error_handler(array($this, 'handleError'));
}

$container = Config::getContainer();
Expand Down Expand Up @@ -167,6 +170,11 @@ public static function configureContainer($container, $input = null, $output = n
->withMethodCall('setFormatterManager', ['formatterManager']);
$container->share('commandFactory', \Consolidation\AnnotatedCommand\AnnotatedCommandFactory::class)
->withMethodCall('setCommandProcessor', ['commandProcessor']);
$container->share('application', \Robo\Application::class)
->withArgument('Robo')
->withArgument(self::VERSION)
->withMethodCall('setAutoExit', [false])
->withMethodCall('setDispatcher', ['eventDispatcher']);

static::addInflectors($container);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Task/Filesystem/CopyDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function copyDir($src, $dst)
while (false !== ($file = readdir($dir))) {
if (in_array($file, $this->exclude)) {
continue;
}
}
if (($file !== '.') && ($file !== '..')) {
$srcFile = $src . '/' . $file;
$destFile = $dst . '/' . $file;
Expand Down
40 changes: 38 additions & 2 deletions tests/unit/RunnerTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
<?php
use Robo\Config;
use Symfony\Component\Console\Output\BufferedOutput;

class RunnerTest extends \Codeception\TestCase\Test
{
/**
* @var \Robo\Runner
*/
private $runner;

/**
* @var \CodeGuy
*/
protected $guy;

public function _before()
{
$this->runner = new \Robo\Runner();
}



public function testHandleError()
{
$tmpLevel = error_reporting();
Expand Down Expand Up @@ -59,4 +65,34 @@ public function testErrorIsHandled()
error_reporting($tmpLevel);
}

public function testRunnerNoSuchCommand()
{
$argv = ['placeholder', 'no-such-command'];
$this->runner->execute($argv);
$this->guy->seeInOutput('Command "no-such-command" is not defined.');
}

public function testRunnerList()
{
$argv = ['placeholder', 'list'];
$this->runner->execute($argv);
$this->guy->seeInOutput('try:array-args');
}

public function testRunnerTryArgs()
{
$argv = ['placeholder', 'try:array-args', 'a', 'b', 'c'];
$this->runner->execute($argv);

$expected = <<<EOT
➜ The parameters passed are:
array (
0 => 'a',
1 => 'b',
2 => 'c',
)
EOT;
$this->guy->seeOutputEquals($expected);
}
}

0 comments on commit ed7b7ff

Please sign in to comment.