diff --git a/src/PHPCensor/Plugin/Util/PhpUnitResult.php b/src/PHPCensor/Plugin/Util/PhpUnitResult.php index 04a75488..000d2e70 100644 --- a/src/PHPCensor/Plugin/Util/PhpUnitResult.php +++ b/src/PHPCensor/Plugin/Util/PhpUnitResult.php @@ -39,13 +39,12 @@ class PhpUnitResult public function parse() { $rawResults = file_get_contents($this->outputFile); - if (empty($rawResults)) { - throw new \Exception('No test executed.'); - } - if ($rawResults[0] == '{') { + + $events = []; + if ($rawResults && $rawResults[0] == '{') { $fixedJson = '[' . str_replace('}{', '},{', $rawResults) . ']'; $events = json_decode($fixedJson, true); - } else { + } elseif ($rawResults) { $events = json_decode($rawResults, true); } @@ -54,14 +53,12 @@ class PhpUnitResult $this->errors = []; $this->failures = 0; - if (is_array($events)) { + if ($events) { foreach ($events as $event) { - if ($event['event'] == self::EVENT_TEST) { + if (isset($event['event']) && $event['event'] == self::EVENT_TEST) { $this->results[] = $this->parseEvent($event); } } - } else { - throw new \Exception('Failed to parse the JSON output.'); } return $this; diff --git a/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php b/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php index c81ef4b6..95eab8dd 100644 --- a/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php +++ b/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php @@ -36,13 +36,4 @@ class PhpUnitResultTest extends \PHPUnit_Framework_TestCase $this->assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[11]['severity']); $this->assertContains('Skipped Test:', $output[11]['message']); } - - public function testParseFailure() - { - $this->setExpectedException('\Exception', 'Failed to parse the JSON output'); - - $buildPath = '/path/to/build'; - $parser = new PhpUnitResult(ROOT_DIR . 'tests/PHPCensor/Plugin/SampleFiles/invalid_format.txt', $buildPath); - $parser->parse(); - } }