diff --git a/src/ParaTest/Logging/JUnit/Reader.php b/src/ParaTest/Logging/JUnit/Reader.php index 86c3835e..595af7fa 100644 --- a/src/ParaTest/Logging/JUnit/Reader.php +++ b/src/ParaTest/Logging/JUnit/Reader.php @@ -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 diff --git a/src/ParaTest/Parser/ParsedClass.php b/src/ParaTest/Parser/ParsedClass.php index 1bfa1c91..5dd0b4c8 100644 --- a/src/ParaTest/Parser/ParsedClass.php +++ b/src/ParaTest/Parser/ParsedClass.php @@ -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; } diff --git a/src/ParaTest/Runners/PHPUnit/ResultPrinter.php b/src/ParaTest/Runners/PHPUnit/ResultPrinter.php index a5d2102e..9858eb6d 100644 --- a/src/ParaTest/Runners/PHPUnit/ResultPrinter.php +++ b/src/ParaTest/Runners/PHPUnit/ResultPrinter.php @@ -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) diff --git a/test/fixtures/results/empty-test-suite.xml b/test/fixtures/results/empty-test-suite.xml new file mode 100644 index 00000000..dfe64167 --- /dev/null +++ b/test/fixtures/results/empty-test-suite.xml @@ -0,0 +1,2 @@ + + diff --git a/test/unit/ParaTest/Parser/ParsedClassTest.php b/test/unit/ParaTest/Parser/ParsedClassTest.php index 11982731..62469449 100644 --- a/test/unit/ParaTest/Parser/ParsedClassTest.php +++ b/test/unit/ParaTest/Parser/ParsedClassTest.php @@ -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') ); @@ -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')); diff --git a/test/unit/ParaTest/Runners/PHPUnit/ResultPrinterTest.php b/test/unit/ParaTest/Runners/PHPUnit/ResultPrinterTest.php index 17eeeff0..2a1c9ef8 100644 --- a/test/unit/ParaTest/Runners/PHPUnit/ResultPrinterTest.php +++ b/test/unit/ParaTest/Runners/PHPUnit/ResultPrinterTest.php @@ -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();