Skip to content

Commit

Permalink
Merge pull request #213 from elliotchance/release/1.4.1
Browse files Browse the repository at this point in the history
Release/1.4.1
  • Loading branch information
elliotchance committed Oct 16, 2014
2 parents 98e3d33 + abf955b commit c52ede7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/Concise/Console/Command.php
Expand Up @@ -13,11 +13,7 @@ class Command extends \PHPUnit_TextUI_Command

protected function createRunner()
{
if ($this->ci) {
$resultPrinter = new CIResultPrinter();
} else {
$resultPrinter = new DefaultResultPrinter();
}
$resultPrinter = $this->getResultPrinter();
if (array_key_exists('verbose', $this->arguments) && $this->arguments['verbose']) {
$resultPrinter->setVerbose(true);
}
Expand All @@ -27,6 +23,15 @@ protected function createRunner()
return $testRunner;
}

public function getResultPrinter()
{
if ($this->ci) {
return new CIResultPrinter();
}

return new DefaultResultPrinter();
}

/**
* @codeCoverageIgnore
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Concise/Console/ResultPrinter/CIResultPrinter.php
Expand Up @@ -14,4 +14,9 @@ public function update()
$this->lastPercentage = $percentage;
}
}

public function appendTextAbove($text)
{
parent::appendTextAbove("\n$text");
}
}
2 changes: 1 addition & 1 deletion src/Concise/Console/ResultPrinter/DefaultResultPrinter.php
Expand Up @@ -53,7 +53,6 @@ public function endTest($status, PHPUnit_Framework_Test $test, $time, Exception
{
if ($status !== PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
$this->add($status, $test, $e);
++$this->issueNumber;
}
$this->update();
}
Expand Down Expand Up @@ -95,6 +94,7 @@ protected function add($status, PHPUnit_Framework_Test $test, Exception $e)
}
}

++$this->issueNumber;
$renderIssue = new RenderIssue();
$message = $renderIssue->render($status, $this->issueNumber, $test, $e);
$this->appendTextAbove("$message\n\n");
Expand Down
27 changes: 27 additions & 0 deletions tests/Concise/Console/CommandTest.php
Expand Up @@ -10,6 +10,11 @@ public function setArgument($name, $value)
{
$this->arguments[$name] = $value;
}

public function setCI($ci)
{
$this->ci = $ci;
}
}

class CommandTest extends TestCase
Expand Down Expand Up @@ -57,4 +62,26 @@ public function testVerboseIsNotTurnedOnIfItExistsButIfNotTrue()
$command->setArgument('verbose', false);
$this->assert($command->createRunner()->getPrinter()->getResultPrinter()->isVerbose(), is_false);
}

public function testCIResultPrinterIsUsedIfCIIsTrue()
{
$command = $this->getCommandMock();
$command->setCI(true);

$this->assert($command->getResultPrinter(), instance_of, 'Concise\Console\ResultPrinter\CIResultPrinter');
}

public function testDefaultResultPrinterIsNotUsedIfCIIsFalse()
{
$command = $this->getCommandMock();
$command->setCI(false);

$this->assert($command->getResultPrinter(), instance_of, 'Concise\Console\ResultPrinter\DefaultResultPrinter');
}

public function testDefaultResultPrinterIsUsedByDefault()
{
$command = $this->getCommandMock();
$this->assert($command->getResultPrinter(), instance_of, 'Concise\Console\ResultPrinter\DefaultResultPrinter');
}
}
9 changes: 9 additions & 0 deletions tests/Concise/Console/ResultPrinter/CIResultPrinterTest.php
Expand Up @@ -13,4 +13,13 @@ public function testUpdateCallsWrite()
->get();
$resultPrinter->update();
}

public function testAppendTextAbovePrintsANewLineAbove()
{
$resultPrinter = $this->niceMock('Concise\Console\ResultPrinter\CIResultPrinter')
->expect('write')
->stub('update')
->get();
$resultPrinter->appendTextAbove('a');
}
}

0 comments on commit c52ede7

Please sign in to comment.