diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..2b2002c --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,23 @@ + + + + + + ./test/ + + + + + ./src + + + diff --git a/src/Printer.php b/src/Printer.php index e71d471..2bd2ab3 100644 --- a/src/Printer.php +++ b/src/Printer.php @@ -40,8 +40,12 @@ protected function printDefectTrace(TestFailure $defect): void { $e = $defect->thrownException(); - $firstError = explode(PHP_EOL, (string)$e)[2]; - list($path, $line) = explode(":", $firstError); + $errorLines = array_filter( + explode(PHP_EOL, (string)$e), + function($l){ return $l; } + ); + + list($path, $line) = explode(":", end($errorLines)); if (!$path) { list($path, $line) = $this->getReflectionFromTest($defect->getTestName()); diff --git a/test/_files/PrinterStatesTest.php b/test/_files/PrinterStatesTest.php new file mode 100644 index 0000000..3bb686d --- /dev/null +++ b/test/_files/PrinterStatesTest.php @@ -0,0 +1,49 @@ +assertTrue(true); + } + + public function testFailure() + { + $this->assertTrue(false); + } + + public function testError() + { + strpos(); + } + + public function testMissing() + { + $this->isMissing(); + } + + public function testSkipped() + { + $this->markTestSkipped('Skipped'); + } + + public function testWarning() + { + throw new PHPUnit\Framework\Warning("This is a test warning"); + } + + public function testRisky() + { + throw new PHPUnit\Framework\RiskyTestError("This is a risky test"); + } + + public function testNoAssertions() + { + } + + public function testIncomplete() + { + $this->markTestIncomplete('Incomplete'); + } +} + diff --git a/test/_files/phpunit.xml b/test/_files/phpunit.xml new file mode 100644 index 0000000..bd54171 --- /dev/null +++ b/test/_files/phpunit.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/test/states-test.phpt b/test/states-test.phpt new file mode 100644 index 0000000..a639ffd --- /dev/null +++ b/test/states-test.phpt @@ -0,0 +1,23 @@ +--TEST-- +phpunit -c tests/_files/phpunit.xml tests/_files/PrinterStatesTest.php +--FILE-- + +--EXPECTF-- +PHPUnit 8.5.2 by Sebastian Bergmann and contributors. + +::error file=test/_files/PrinterStatesTest.php,line=17::strpos() expects at least 2 parameters, 0 given +::error file=test/_files/PrinterStatesTest.php,line=22::Call to undefined method PrinterStatesTest::isMissing() +::warning file=test/_files/PrinterStatesTest.php,line=32::This is a test warning +::error file=test/_files/PrinterStatesTest.php,line=12::Failed asserting that false is true. +::warning file=test/_files/PrinterStatesTest.php,line=37::This is a risky test +::warning file=test/_files/PrinterStatesTest.php,line=40::This test did not perform any assertions