Skip to content

Commit

Permalink
Merge pull request #143 from brianium/percentage-fix
Browse files Browse the repository at this point in the history
Percentage fix
  • Loading branch information
julianseeger committed Jan 28, 2015
2 parents c961df8 + 8170889 commit 47a4f4d
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 31 deletions.
13 changes: 13 additions & 0 deletions src/ParaTest/Runners/PHPUnit/ExecutableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public function __construct($path, $fullyQualifiedClassName = null)
$this->fullyQualifiedClassName = $fullyQualifiedClassName;
}

/**
* Get the expected count of tests or testmethods
* to be executed in this test
*
* @return int
*/
abstract public function getTestMethodCount();

/**
* Get the path to the test being executed
*
Expand Down Expand Up @@ -267,4 +275,9 @@ public function getStdout()
{
return $this->process->getOutput();
}

public function setTempFile($temp)
{
$this->temp = $temp;
}
}
7 changes: 5 additions & 2 deletions src/ParaTest/Runners/PHPUnit/ResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public function printFeedback(ExecutableTest $test)
}
$this->results->addReader($reader);
$feedbackItems = $reader->getFeedback();

$dataProviderOverhead = count($feedbackItems) - $test->getTestMethodCount();
$this->totalCases += $dataProviderOverhead;

foreach ($feedbackItems as $item) {
$this->printFeedbackItem($item);
}
Expand Down Expand Up @@ -320,9 +324,8 @@ protected function getDefects(array $defects, $type)
protected function printProgress()
{
printf(
' %' . $this->numTestsWidth . 'd / %' . $this->numTestsWidth . 'd (%3s%%)',
' %' . $this->numTestsWidth . 'd (%3s%%)',
$this->casesProcessed,
$this->totalCases,
floor(($this->casesProcessed / $this->totalCases) * 100)
);

Expand Down
11 changes: 11 additions & 0 deletions src/ParaTest/Runners/PHPUnit/Suite.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ public function getFunctions()
{
return $this->functions;
}

/**
* Get the expected count of tests or testmethods
* to be executed in this test
*
* @return int
*/
public function getTestMethodCount()
{
return count($this->functions);
}
}
11 changes: 11 additions & 0 deletions src/ParaTest/Runners/PHPUnit/TestMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,15 @@ protected function prepareOptions($options)

return $options;
}

/**
* Get the expected count of tests or testmethods
* to be executed in this test
*
* @return int
*/
public function getTestMethodCount()
{
return 1;
}
}
40 changes: 16 additions & 24 deletions test/unit/ParaTest/ResultTester.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace ParaTest;

use ParaTest\Parser\ParsedFunction;
use ParaTest\Runners\PHPUnit\Suite;

abstract class ResultTester extends \TestBase
{
Expand All @@ -12,37 +13,28 @@ abstract class ResultTester extends \TestBase

public function setUp()
{
$this->errorSuite = $this->getSuiteWithResult('single-werror.xml');
$this->otherErrorSuite = $this->getSuiteWithResult('single-werror2.xml');
$this->failureSuite = $this->getSuiteWithResult('single-wfailure.xml');
$this->mixedSuite = $this->getSuiteWithResult('mixed-results.xml');
$this->passingSuite = $this->getSuiteWithResult('single-passing.xml');
$this->errorSuite = $this->getSuiteWithResult('single-werror.xml', 1);
$this->otherErrorSuite = $this->getSuiteWithResult('single-werror2.xml', 1);
$this->failureSuite = $this->getSuiteWithResult('single-wfailure.xml', 3);
$this->mixedSuite = $this->getSuiteWithResult('mixed-results.xml', 7);
$this->passingSuite = $this->getSuiteWithResult('single-passing.xml', 3);
}

public function getSuiteWithResult($result)
public function getSuiteWithResult($result, $methodCount)
{
$result = FIXTURES . DS . 'results' . DS . $result;
$suite = $this->getMockBuilder('ParaTest\\Runners\\PHPUnit\\Suite')
->disableOriginalConstructor()
->getMock();

$suite->expects($this->any())
->method('getTempFile')
->will($this->returnValue($result));
$functions = array();
for ($i = 0; $i < $methodCount; $i++) {
$functions[] = $this->mockFunction($i);
}
$suite = new Suite('', $functions);
$suite->setTempFile($result);

return $suite;
}

public function mockFunctions($mockSuite, $numFuncs)
protected function mockFunction($functionCount)
{
$i = 0;
$funcs = array();
while ($i < $numFuncs) {
$funcs[] = new ParsedFunction('doc', 'public', 'func' + $i);
$i++;
}
$mockSuite->expects($this->any())
->method('getFunctions')
->will($this->returnValue($funcs));
return new ParsedFunction('doc', 'public', 'func' . $functionCount);
}
}
}
10 changes: 10 additions & 0 deletions test/unit/ParaTest/Runners/PHPUnit/ExecutableTestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,14 @@ public function testGetTempFileShouldReturnSameFileIfAlreadyCalled()
class ExecutableTestChild extends ExecutableTest
{

/**
* Get the expected count of tests or testmethods
* to be executed in this test
*
* @return int
*/
public function getTestMethodCount()
{
return 1;
}
}
38 changes: 33 additions & 5 deletions test/unit/ParaTest/Runners/PHPUnit/ResultPrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ class ResultPrinterTest extends ResultTester
protected $printer;
protected $interpreter;

protected $passingSuiteWithWrongTestCountEsimation;

public function setUp()
{
parent::setUp();
$this->interpreter = new LogInterpreter();
$this->printer = new ResultPrinter($this->interpreter);
$this->mockFunctions($this->errorSuite, 1);
$this->mockFunctions($this->failureSuite, 3);
$this->mockFunctions($this->mixedSuite, 7);
$this->mockFunctions($this->passingSuite, 3);
chdir(__DIR__);
if(file_exists('myconfig.xml'))
unlink('myconfig.xml');

$this->passingSuiteWithWrongTestCountEsimation = $this->getSuiteWithResult('single-passing.xml', 1);
}

public function testConstructor()
Expand Down Expand Up @@ -248,12 +248,40 @@ public function testPrintFeedbackForMoreThan100Suites()
$expected = '';
for($i = 0; $i < 63; $i++)
$expected .= '.';
$expected .= " 63 / 120 ( 52%)\n";
$expected .= " 63 ( 52%)\n";
for($i = 0; $i < 57; $i++)
$expected .= '.';
$this->assertEquals($expected, $feedback);
}

public function testResultPrinterAdjustsTotalCountForDataProviders()
{
//add tests
for ($i = 0; $i < 22; $i++)
$this->printer->addTest($this->passingSuiteWithWrongTestCountEsimation);

//start the printer so boundaries are established
ob_start();
$this->printer->start(new Options());
ob_end_clean();

//get the feedback string
ob_start();
for ($i = 0; $i < 22; $i++)
$this->printer->printFeedback($this->passingSuiteWithWrongTestCountEsimation);
$feedback = ob_get_clean();

//assert it is as expected
$expected = '';
for($i = 0; $i < 65; $i++)
$expected .= '.';
$expected .= " 65 ( 98%)\n";
for($i = 0; $i < 1; $i++)
$expected .= '.';
$this->assertEquals($expected, $feedback);

}

/**
* @expectedException \RuntimeException
*/
Expand Down

0 comments on commit 47a4f4d

Please sign in to comment.