Skip to content

Commit

Permalink
Fix unit test mocks: be sure to supply a logger where needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Aug 26, 2016
1 parent 3e31dff commit ac85ff8
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 57 deletions.
63 changes: 33 additions & 30 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/_helpers/CodeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ class CodeHelper extends \Codeception\Module
protected static $testPrinter;
protected static $capturedOutput;
protected static $container;
protected static $logger;

public function _before(\Codeception\TestCase $test)
{
static::$capturedOutput = '';
static::$testPrinter = new BufferedOutput(OutputInterface::VERBOSITY_DEBUG);
static::$logger = new \Robo\Log\RoboLogger(static::$testPrinter);
$progressBar = new \Symfony\Component\Console\Helper\ProgressBar(static::$testPrinter);

static::$container = new \League\Container\Container();
Expand All @@ -37,6 +39,11 @@ public function _after(\Codeception\TestCase $test)
static::$container->add('logger', new \Consolidation\Log\Logger($consoleOutput));
}

public function logger()
{
return static::$logger;
}

public function accumulate()
{
static::$capturedOutput .= static::$testPrinter->fetch();
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/Task/ApiGenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ protected function _before()
{
$this->apigen = test::double('Robo\Task\ApiGen\ApiGen', [
'executeCommand' => null,
'output' => new \Symfony\Component\Console\Output\NullOutput()
'output' => new \Symfony\Component\Console\Output\NullOutput(),
'logger' => new \Psr\Log\NullLogger(),
]);

$this->container = Robo::getContainer();
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/Task/AtoumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ protected function _before()
{
$this->atoum = test::double('Robo\Task\Testing\Atoum', [
'executeCommand' => null,
'output' => new \Symfony\Component\Console\Output\NullOutput()
'output' => new \Symfony\Component\Console\Output\NullOutput(),
'logger' => new \Psr\Log\NullLogger(),
]);
}

Expand Down
10 changes: 7 additions & 3 deletions tests/unit/Task/BowerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@ class BowerTest extends \Codeception\TestCase\Test
protected function _before()
{
$this->baseBower = test::double('Robo\Task\Bower\Base', [
'output' => new \Symfony\Component\Console\Output\NullOutput()
'output' => new \Symfony\Component\Console\Output\NullOutput(),
'logger' => new \Psr\Log\NullLogger(),
]);
}
// tests
public function testBowerInstall()
{
$bower = test::double('Robo\Task\Bower\Install', ['executeCommand' => null]);
$bower = test::double('Robo\Task\Bower\Install', ['executeCommand' => null, 'logger' => new \Psr\Log\NullLogger(),]);
(new \Robo\Task\Bower\Install('bower'))->run();
$bower->verifyInvoked('executeCommand', ['bower install']);
}

public function testBowerUpdate()
{
$bower = test::double('Robo\Task\Bower\Update', ['executeCommand' => null]);
(new \Robo\Task\Bower\Update('bower'))->run();
$task = new \Robo\Task\Bower\Update('bower');
$task->setLogger(new \Psr\Log\NullLogger());

$task->run();
$bower->verifyInvoked('executeCommand', ['bower update']);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Task/CodeceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public function testCodeceptionCommand()

public function testCodeceptionRun()
{
(new \Robo\Task\Testing\Codecept('codecept.phar'))->run();
$task = new \Robo\Task\Testing\Codecept('codecept.phar');
$task->setLogger(new \Psr\Log\NullLogger());

$task->run();
$this->codecept->verifyInvoked('executeCommand');
}

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Task/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public function testAddCodeRollbackAndCompletion()
->completion($completion2)
->addCode(function () { return 13; });

$collection->setLogger($this->guy->logger());

$result = $collection->run();
// Execution stops on the first error.
// Confirm that status code is converted to a Result object.
Expand Down
11 changes: 6 additions & 5 deletions tests/unit/Task/ComposerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ protected function _before()
{
$this->baseComposer = test::double('Robo\Task\Composer\Base', [
'output' => new \Symfony\Component\Console\Output\NullOutput(),
'logger' => new \Psr\Log\NullLogger(),
]);
}
// tests
public function testComposerInstall()
{
$composer = test::double('Robo\Task\Composer\Install', ['executeCommand' => null, 'getConfig' => new \Robo\Config()]);
$composer = test::double('Robo\Task\Composer\Install', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]);

(new \Robo\Task\Composer\Install('composer'))->run();
$composer->verifyInvoked('executeCommand', ['composer install']);
Expand All @@ -40,7 +41,7 @@ public function testComposerInstallAnsi()
{
$config = new \Robo\Config();
$config->setDecorated(true);
$composer = test::double('Robo\Task\Composer\Install', ['executeCommand' => null, 'getConfig' => $config]);
$composer = test::double('Robo\Task\Composer\Install', ['executeCommand' => null, 'getConfig' => $config, 'logger' => new \Psr\Log\NullLogger()]);

(new \Robo\Task\Composer\Install('composer'))->run();
$composer->verifyInvoked('executeCommand', ['composer install --ansi']);
Expand All @@ -58,7 +59,7 @@ public function testComposerInstallAnsi()

public function testComposerUpdate()
{
$composer = test::double('Robo\Task\Composer\Update', ['executeCommand' => null, 'getConfig' => new \Robo\Config()]);
$composer = test::double('Robo\Task\Composer\Update', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]);

(new \Robo\Task\Composer\Update('composer'))->run();
$composer->verifyInvoked('executeCommand', ['composer update']);
Expand All @@ -71,7 +72,7 @@ public function testComposerUpdate()

public function testComposerDumpAutoload()
{
$composer = test::double('Robo\Task\Composer\DumpAutoload', ['executeCommand' => null, 'getConfig' => new \Robo\Config()]);
$composer = test::double('Robo\Task\Composer\DumpAutoload', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]);

(new \Robo\Task\Composer\DumpAutoload('composer'))->run();
$composer->verifyInvoked('executeCommand', ['composer dump-autoload']);
Expand All @@ -95,7 +96,7 @@ public function testComposerDumpAutoload()

public function testComposerValidate()
{
$composer = test::double('Robo\Task\Composer\Validate', ['executeCommand' => null, 'getConfig' => new \Robo\Config()]);
$composer = test::double('Robo\Task\Composer\Validate', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]);

(new \Robo\Task\Composer\Validate('composer'))->run();
$composer->verifyInvoked('executeCommand', ['composer validate']);
Expand Down
18 changes: 14 additions & 4 deletions tests/unit/Task/ExecTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,29 @@ protected function _before()
'run' => false,
'start' => false,
'getOutput' => 'Hello world',
'getExitCode' => 0
'getExitCode' => 0,
'logger' => new \Psr\Log\NullLogger(),
]);
test::double('Robo\Task\Base\Exec', ['output' => new \Symfony\Component\Console\Output\NullOutput()]);
}

public function testExec()
{
$result = (new \Robo\Task\Base\Exec('ls'))->run();
$task = new \Robo\Task\Base\Exec('ls');
$task->setLogger(new \Psr\Log\NullLogger());

$result = $task->run();
$this->process->verifyInvoked('run');
verify($result->getMessage())->equals('Hello world');
verify($result->getExitCode())->equals(0);
}

public function testExecInBackground()
{
$result = (new \Robo\Task\Base\Exec('ls'))->background()->run();
$task = new \Robo\Task\Base\Exec('ls');
$task->setLogger(new \Psr\Log\NullLogger());

$result = $task->background()->run();
$this->process->verifyInvoked('start');
$this->process->verifyNeverInvoked('run');
verify('exit code was not received', $result->getExitCode())->notEquals(100);
Expand All @@ -43,7 +50,10 @@ public function testGetCommand()

public function testExecStack()
{
(new \Robo\Task\Base\ExecStack())
$task = new \Robo\Task\Base\ExecStack();
$task->setLogger(new \Psr\Log\NullLogger());

$task
->exec('ls')
->exec('cd /')
->exec('cd home')
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/Task/GitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ protected function _before()
{
$this->git = test::double('Robo\Task\Vcs\GitStack', [
'executeCommand' => new \AspectMock\Proxy\Anything(),
'output' => new \Symfony\Component\Console\Output\NullOutput()
'output' => new \Symfony\Component\Console\Output\NullOutput(),
'logger' => new \Psr\Log\NullLogger(),
]);
}

Expand Down
Loading

0 comments on commit ac85ff8

Please sign in to comment.