diff --git a/Dockerfile b/Dockerfile index c245132..0e6c712 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.1-cli +FROM php:5.6-cli # Work out of this directory WORKDIR /usr/flaptastic diff --git a/composer.json b/composer.json index 354d5ad..5be6d3c 100644 --- a/composer.json +++ b/composer.json @@ -12,11 +12,11 @@ } ], "require": { - "php": ">=7.1.0", + "php": ">=5.6.0", "guzzlehttp/guzzle": ">=6.0.0" }, "require-dev": { - "phpunit/phpunit": ">=7.0.0" + "phpunit/phpunit": ">=4.0.0 <5.0.0" }, "autoload": { "psr-4": { diff --git a/src/FlaptasticListener.php b/src/FlaptasticListener.php index fd685b6..0274d79 100644 --- a/src/FlaptasticListener.php +++ b/src/FlaptasticListener.php @@ -2,13 +2,10 @@ namespace BlockJon\PHPUnit\Listener; -use PHPUnit\Framework\TestListener; - - /** * Integrates with flaptastic.com to expose flappy test information. */ -class FlaptasticListener implements TestListener +class FlaptasticListener implements \PHPUnit_Framework_TestListener { public static $FLAPTASTIC_INTRODUCED = false; @@ -37,6 +34,15 @@ function __construct() { } public function getTestFailureFileAndLine($e) { + if (is_subclass_of($e, '\PHPUnit_Framework_Exception')) { + $result = explode(":", trim(\PHPUnit_Util_Filter::getFilteredStacktrace($e))); + if (count($result) == 2) { + return (object) [ + "file" => $result[0], + "line" => $result[1] + ]; + } + } return (object) [ "file" => $e->getFile(), "line" => $e->getLine() @@ -160,47 +166,47 @@ private function missingEnvVarsDetected() { return false; } - public function addError(\PHPUnit\Framework\Test $test, \Throwable $e, float $time): void + public function addError(\PHPUnit_Framework_Test $test, Exception $e, $time) { $this->testType = 'error'; $this->testException = $e; } - public function addWarning(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, float $time): void + public function addWarning(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_Warning $e, $time) { $this->testType = 'warning'; } - public function addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\AssertionFailedError $e, float $time): void + public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time) { $this->testType = 'failure'; $this->testException = $e; } - public function addIncompleteTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time): void + public function addIncompleteTest(\PHPUnit_Framework_Test $test, Exception $e, $time) { // We are not interested in incomplete tests and they are ultimately ignored. $this->testType = 'incomplete'; } - public function addRiskyTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time): void + public function addRiskyTest(\PHPUnit_Framework_Test $test, Exception $e, $time) { // We dont care if php happens to deem a test is risky. } - public function addSkippedTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time): void + public function addSkippedTest(\PHPUnit_Framework_Test $test, Exception $e, $time) { $this->testType = 'skipped'; } - public function startTest(\PHPUnit\Framework\Test $test): void + public function startTest(\PHPUnit_Framework_Test $test) { // Assume tests all pass. $this->testType = 'passed'; $this->testException = null; } - public function endTest(\PHPUnit\Framework\Test $test, float $time): void + public function endTest(\PHPUnit_Framework_Test $test, $time) { if ($this->testType == 'passed') { $this->addPassedTest($test); @@ -209,7 +215,7 @@ public function endTest(\PHPUnit\Framework\Test $test, float $time): void } } - public function startTestSuite(\PHPUnit\Framework\TestSuite $suite): void + public function startTestSuite(\PHPUnit_Framework_TestSuite $suite) { $this->testSuite = $suite; if (!static::$FLAPTASTIC_INTRODUCED) { @@ -228,7 +234,7 @@ public function startTestSuite(\PHPUnit\Framework\TestSuite $suite): void } } - public function endTestSuite(\PHPUnit\Framework\TestSuite $suite): void + public function endTestSuite(\PHPUnit_Framework_TestSuite $suite) { if (count($this->buffer)) { $this->occasionallyDeliver();