Skip to content

Commit

Permalink
Merge pull request #135 from Cameronjmayfield/ErrorMessageWhenEmpty
Browse files Browse the repository at this point in the history
Error message when empty + No longer runs unselected groups when multiple are selected
  • Loading branch information
julianseeger committed Jan 2, 2015
2 parents 5e53fce + 9727b51 commit 70ec388
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 7 deletions.
11 changes: 11 additions & 0 deletions src/ParaTest/Logging/JUnit/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ public function getSuites()
return $this->suites;
}

/**
* Checks whether the xml log has
* test suite results
*
* @return array
*/
public function hasResults()
{
return $this->xml->count() > 0;
}

/**
* Return an array that contains
* each suite's instant feedback. Since
Expand Down
12 changes: 9 additions & 3 deletions src/ParaTest/Parser/ParsedClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ public function __construct($doc, $name, $namespace, $methods = array())
*/
public function getMethods($annotations = array())
{
$methods = array_filter($this->methods, function($m) use($annotations){
foreach($annotations as $a => $v)
return $m->hasAnnotation($a, $v);
$methods = array_filter($this->methods, function ($m) use ($annotations) {
foreach ($annotations as $a => $v) {
foreach (explode(',', $v) as $subValue) {
if ($m->hasAnnotation($a, $subValue)) {
return true;
}
}
}
return false;
});
return $methods ? $methods : $this->methods;
}
Expand Down
5 changes: 5 additions & 0 deletions src/ParaTest/Runners/PHPUnit/ResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ public function printResults()
public function printFeedback(ExecutableTest $test)
{
$reader = new Reader($test->getTempFile());
if (!$reader->hasResults()) {
throw new \RuntimeException("Log file " . $test->getTempFile() . " is empty.
This means a PHPUnit process was unable to run " . $test->getPath() . "
Maybe there is more than one class in this file.");
}
$this->results->addReader($reader);
$feedbackItems = $reader->getFeedback();
foreach ($feedbackItems as $item)
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/results/empty-test-suite.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites/>
33 changes: 29 additions & 4 deletions test/unit/ParaTest/Parser/ParsedClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ public function setUp()
{
$this->methods = array(
new ParsedFunction(
"/**
"/**
* @group group1
*/",
'public', 'testFunction'
'public', 'testFunction'
),
new ParsedFunction(
"/**
"/**
* @group group2
*/",
'public', 'testFunction2'
'public', 'testFunction2'
),
new ParsedFunction('', 'public', 'testFunction3')
);
Expand All @@ -30,6 +30,31 @@ public function testGetMethodsReturnsMethods()
$this->assertEquals($this->methods, $this->class->getMethods());
}

public function testGetMethodsMultipleAnnotationsReturnsMethods()
{
$goodMethod = new ParsedFunction(
"/**
* @group group1
*/",
'public', 'testFunction'
);
$goodMethod2 = new ParsedFunction(
"/**
* @group group2
*/",
'public', 'testFunction2'
);
$badMethod = new ParsedFunction(
"/**
* @group group3
*/",
'public', 'testFunction2'
);
$annotatedClass = new ParsedClass('', 'MyTestClass', '', array($goodMethod, $goodMethod2, $badMethod));
$methods = $annotatedClass->getMethods(array('group' => 'group1,group2'));
$this->assertEquals(array($goodMethod, $goodMethod2), $methods);
}

public function testGetMethodsExceptsAdditionalAnnotationFilter()
{
$group1 = $this->class->getMethods(array('group' => 'group1'));
Expand Down
10 changes: 10 additions & 0 deletions test/unit/ParaTest/Runners/PHPUnit/ResultPrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ public function testPrintFeedbackForMoreThan100Suites()
$this->assertEquals($expected, $feedback);
}

/**
* @expectedException \RuntimeException
*/
public function testEmptyResultsLog(){
$suite = new Suite('/path/to/ResultSuite.php', array());
$empty = FIXTURES . DS . 'results' . DS . 'empty-test-suite.xml';
file_put_contents($suite->getTempFile(), file_get_contents($empty));
$this->printer->printFeedback($suite);
}

protected function getStartOutput(Options $options)
{
ob_start();
Expand Down

0 comments on commit 70ec388

Please # to comment.