Skip to content

Commit

Permalink
Merge pull request #205 from elliotchance/1.4/205-run-in-ci-mode
Browse files Browse the repository at this point in the history
Run in CI mode
  • Loading branch information
elliotchance committed Oct 6, 2014
2 parents 34d89e1 + 04c2876 commit 789fca1
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/Concise/Console/Command.php
Expand Up @@ -5,12 +5,19 @@
use Concise\Console\TestRunner\DefaultTestRunner;
use Concise\Console\ResultPrinter\ResultPrinterProxy;
use Concise\Console\ResultPrinter\DefaultResultPrinter;
use Concise\Console\ResultPrinter\CIResultPrinter;

class Command extends \PHPUnit_TextUI_Command
{
protected $ci = false;

protected function createRunner()
{
$resultPrinter = new DefaultResultPrinter();
if ($this->ci) {
$resultPrinter = new CIResultPrinter();
} else {
$resultPrinter = new DefaultResultPrinter();
}
if (array_key_exists('verbose', $this->arguments) && $this->arguments['verbose']) {
$resultPrinter->setVerbose(true);
}
Expand All @@ -26,6 +33,7 @@ protected function createRunner()
protected function handleArguments(array $argv)
{
$this->longOptions['test-colors'] = null;
$this->longOptions['ci'] = null;
parent::handleArguments($argv);

foreach ($this->options[0] as $option) {
Expand All @@ -35,6 +43,10 @@ protected function handleArguments(array $argv)
echo $testColors->renderAll();
exit(0);
break;

case '--ci':
$this->ci = true;
break;
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/Concise/Console/ResultPrinter/CIResultPrinter.php
@@ -0,0 +1,17 @@
<?php

namespace Concise\Console\ResultPrinter;

class CIResultPrinter extends DefaultResultPrinter
{
protected $lastPercentage = -1;

public function update()
{
$percentage = $this->counter->getPercentage($this->getTestCount());
if ($percentage > $this->lastPercentage) {
$this->write($this->getAssertionString());
$this->lastPercentage = $percentage;
}
}
}
Expand Up @@ -46,10 +46,14 @@ public function render($value = 0)
$this->atLeastZero($value, 'Value');
$r = $value . ' / ' . max($value, $this->total);
if ($this->showPercentage) {
$percentage = (0 === $this->total) ? 0 : floor($value / $this->total * 100);
$r .= sprintf(' (%3s%%)', min(100, $percentage));
$r .= sprintf(' (%3s%%)', min(100, $this->getPercentage($value)));
}

return $r;
}

public function getPercentage($value)
{
return (0 === $this->total) ? 0 : floor($value / $this->total * 100);
}
}
16 changes: 16 additions & 0 deletions tests/Concise/Console/ResultPrinter/CIResultPrinterTest.php
@@ -0,0 +1,16 @@
<?php

namespace Concise\Console\ResultPrinter;

use Concise\TestCase;

class CIResultPrinterTest extends TestCase
{
public function testUpdateCallsWrite()
{
$resultPrinter = $this->niceMock('Concise\Console\ResultPrinter\CIResultPrinter')
->expect('write')
->get();
$resultPrinter->update();
}
}
Expand Up @@ -112,4 +112,10 @@ public function testShowPercentageMustBeAnInteger()
{
new ProgressCounter(123, 'foo');
}

public function testCanGetPercentage()
{
$counter = new ProgressCounter(5);
$this->assert($counter->getPercentage(1), equals, 20);
}
}
2 changes: 1 addition & 1 deletion wiki
Submodule wiki updated from a57a69 to a4d3f2

0 comments on commit 789fca1

Please sign in to comment.