From 70eb43f986c23e8691e3d878efb1d35f334704d8 Mon Sep 17 00:00:00 2001 From: CameronJMayfield Date: Tue, 30 Dec 2014 13:39:06 -0800 Subject: [PATCH 1/2] RuntimeException if log file for test suite is empty. --- src/ParaTest/Logging/JUnit/Reader.php | 12 ++++++++++++ src/ParaTest/Runners/PHPUnit/ResultPrinter.php | 5 +++++ test/fixtures/results/empty-test-suite.xml | 2 ++ .../ParaTest/Runners/PHPUnit/ResultPrinterTest.php | 10 ++++++++++ 4 files changed, 29 insertions(+) create mode 100644 test/fixtures/results/empty-test-suite.xml diff --git a/src/ParaTest/Logging/JUnit/Reader.php b/src/ParaTest/Logging/JUnit/Reader.php index 86c3835e..7e0740ae 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 @@ -195,4 +206,5 @@ protected function initSuite() $this->suites[] = TestSuite::suiteFromNode($node); } } + } 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/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(); From 9727b51d64ff23a61e5d8ea11214b84f2b9d92e7 Mon Sep 17 00:00:00 2001 From: CameronJMayfield Date: Fri, 2 Jan 2015 14:25:57 -0800 Subject: [PATCH 2/2] No longer runs unselected groups when multiple are selected. --- src/ParaTest/Logging/JUnit/Reader.php | 1 - src/ParaTest/Parser/ParsedClass.php | 12 +++++-- test/unit/ParaTest/Parser/ParsedClassTest.php | 33 ++++++++++++++++--- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/ParaTest/Logging/JUnit/Reader.php b/src/ParaTest/Logging/JUnit/Reader.php index 7e0740ae..595af7fa 100644 --- a/src/ParaTest/Logging/JUnit/Reader.php +++ b/src/ParaTest/Logging/JUnit/Reader.php @@ -206,5 +206,4 @@ protected function initSuite() $this->suites[] = TestSuite::suiteFromNode($node); } } - } 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/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'));