From af804993e10e580375ff8399321d42d6d77b0a78 Mon Sep 17 00:00:00 2001 From: Petr Kotek Date: Mon, 26 Jun 2017 16:16:02 +1000 Subject: [PATCH 1/3] Update Listener & Printer to support PHPUnit 6 --- src/Listener.php | 93 ++++++++++++++++++++++++++---------------------- src/Printer.php | 78 +++++++++++++++++++++------------------- 2 files changed, 93 insertions(+), 78 deletions(-) diff --git a/src/Listener.php b/src/Listener.php index 98d5dc3..a0bebbc 100644 --- a/src/Listener.php +++ b/src/Listener.php @@ -6,6 +6,15 @@ * */ +use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\Test; +use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\TestListener; +use PHPUnit\Framework\TestSuite; +use PHPUnit\Framework\Warning; +use PHPUnit\Util\Filter; +use PHPUnit\Util\Printer; + if (getenv('TDDIUM')): /** @@ -16,7 +25,7 @@ * @copyright Solano Labs https://www.solanolabs.com/ * @link https://www.solanolabs.com/ */ -class SolanoLabs_PHPUnit_Listener extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener +class SolanoLabs_PHPUnit_Listener extends Printer implements TestListener { /** * @var string @@ -65,17 +74,17 @@ public function __construct($outputFile = '', $excludeFiles = '') /** * A test started. * - * @param PHPUnit_Framework_Test $test + * @param Test $test */ - public function startTest(PHPUnit_Framework_Test $test) + public function startTest(Test $test) { if (getenv('TDDIUM')) { global $tddium_output_buffer; $tddium_output_buffer = ""; } - if (!$test instanceof PHPUnit_Framework_Warning) { + if (!$test instanceof Warning) { $testcase = array('id' => '', 'address' => '', 'status' => '', 'stderr' => '', 'stdout' => '', 'file' => ''); - if ($test instanceof PHPUnit_Framework_TestCase) { + if ($test instanceof TestCase) { $class = new ReflectionClass($test); $className = $class->getName(); $testName = $test->getName(); @@ -98,10 +107,10 @@ public function startTest(PHPUnit_Framework_Test $test) /** * A test ended. * - * @param PHPUnit_Framework_Test $test - * @param float $time + * @param Test $test + * @param float $time */ - public function endTest(PHPUnit_Framework_Test $test, $time) + public function endTest(Test $test, $time) { $testcase = $this->currentTestcase; if (!$testcase['status']) { @@ -122,11 +131,11 @@ public function endTest(PHPUnit_Framework_Test $test, $time) /** * An error occurred. * - * @param PHPUnit_Framework_Test $test - * @param Exception $e - * @param float $time + * @param Test $test + * @param Exception $e + * @param float $time */ - public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + public function addError(Test $test, Exception $e, $time) { $this->addNonPassTest('error', $test, $e, $time); } @@ -134,11 +143,11 @@ public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) /** * A failure occurred. * - * @param PHPUnit_Framework_Test $test - * @param PHPUnit_Framework_AssertionFailedError $e - * @param float $time + * @param Test $test + * @param AssertionFailedError $e + * @param float $time */ - public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + public function addFailure(Test $test, AssertionFailedError $e, $time) { $this->addNonPassTest('fail', $test, $e, $time); } @@ -146,11 +155,11 @@ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_Asser /** * A warning occurred. * - * @param PHPUnit_Framework_Test $test - * @param PHPUnit_Framework_Warning $e - * @param float $time + * @param Test $test + * @param Warning $e + * @param float $time */ - public function addWarning(PHPUnit_Framework_Test $test, PHPUnit_Framework_Warning $e, $time) + public function addWarning(Test $test, Warning $e, $time) { $this->addNonPassTest('error', $test, $e, $time); } @@ -158,11 +167,11 @@ public function addWarning(PHPUnit_Framework_Test $test, PHPUnit_Framework_Warni /** * Incomplete test. * - * @param PHPUnit_Framework_Test $test - * @param Exception $e - * @param float $time + * @param Test $test + * @param Exception $e + * @param float $time */ - public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + public function addIncompleteTest(Test $test, Exception $e, $time) { $this->addNonPassTest('skip', $test, $e, $time, 'Incomplete Test: '); } @@ -170,11 +179,11 @@ public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $t /** * Risky test. * - * @param PHPUnit_Framework_Test $test - * @param Exception $e - * @param float $time + * @param Test $test + * @param Exception $e + * @param float $time */ - public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) + public function addRiskyTest(Test $test, Exception $e, $time) { $this->addNonPassTest('error', $test, $e, $time, 'Risky Test: '); } @@ -182,11 +191,11 @@ public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) /** * Skipped test. * - * @param PHPUnit_Framework_Test $test - * @param Exception $e - * @param float $time + * @param Test $test + * @param Exception $e + * @param float $time */ - public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + public function addSkippedTest(Test $test, Exception $e, $time) { if (count($this->currentTestcase)) { $this->addNonPassTest('skip', $test, $e, $time, 'Skipped Test: '); @@ -201,12 +210,12 @@ public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time /** * Add a non-passing test to the output * - * @param string $status - * @param PHPUnit_Framework_Test $test - * @param Exception $e - * @param string $stderrPrefix + * @param string $status + * @param Test $test + * @param Exception $e + * @param string $stderrPrefix */ - private function addNonPassTest($status, PHPUnit_Framework_Test $test, Exception $e, $time, $stderrPrefix = '') + private function addNonPassTest($status, Test $test, Exception $e, $time, $stderrPrefix = '') { $this->currentTestcase['status'] = $status; $this->currentTestcase['time'] = $time; @@ -214,7 +223,7 @@ private function addNonPassTest($status, PHPUnit_Framework_Test $test, Exception $this->currentTestcase['stdout'] = $test->getActualOutput(); } $this->currentTestcase['stderr'] = $stderrPrefix . $e->getMessage(); - $traceback = PHPUnit_Util_Filter::getFilteredStacktrace($e, false); + $traceback = Filter::getFilteredStacktrace($e, false); // Strip path from traceback? for($i = 0; $i < count($traceback); $i++) { if (0 === strpos($traceback[$i]['file'], $this->stripPath)) { @@ -227,9 +236,9 @@ private function addNonPassTest($status, PHPUnit_Framework_Test $test, Exception /** * A testsuite started. * - * @param PHPUnit_Framework_TestSuite $suite + * @param TestSuite $suite */ - public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + public function startTestSuite(TestSuite $suite) { $this->currentTestSuiteName = $suite->getName(); } @@ -237,9 +246,9 @@ public function startTestSuite(PHPUnit_Framework_TestSuite $suite) /** * A testsuite ended. * - * @param PHPUnit_Framework_TestSuite $suite + * @param TestSuite $suite */ - public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + public function endTestSuite(TestSuite $suite) { $this->currentTestSuiteName = ''; $this->currentTestSuiteAddress = ''; diff --git a/src/Printer.php b/src/Printer.php index 17ae471..98aedcf 100644 --- a/src/Printer.php +++ b/src/Printer.php @@ -6,7 +6,13 @@ * */ -use SebastianBergmann\Environment\Console; +use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\Test; +use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Warning; +use PHPUnit\Runner\PhptTestCase; +use PHPUnit\TextUI\ResultPrinter; +use PHPUnit\Util\Test as TestUtil; /** * PHPUnit Printer for Solano-PHPUnit @@ -17,7 +23,7 @@ * @link https://www.solanolabs.com/ */ -class SolanoLabs_PHPUnit_Printer extends PHPUnit_TextUI_ResultPrinter +class SolanoLabs_PHPUnit_Printer extends ResultPrinter { /** * @var array @@ -48,11 +54,11 @@ public function __construct($out = null, $verbose = false, $colors = self::COLOR /** * An error occurred. * - * @param PHPUnit_Framework_Test $test - * @param Exception $e - * @param float $time + * @param Test $test + * @param Exception $e + * @param float $time */ - public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + public function addError(Test $test, Exception $e, $time) { $this->writeProgressWithColor('fg-red, bold', 'ERROR'); $this->lastTestFailed = true; @@ -64,11 +70,11 @@ public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) /** * A failure occurred. * - * @param PHPUnit_Framework_Test $test - * @param PHPUnit_Framework_AssertionFailedError $e - * @param float $time + * @param Test $test + * @param AssertionFailedError $e + * @param float $time */ - public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + public function addFailure(Test $test, AssertionFailedError $e, $time) { $this->writeProgressWithColor('bg-red, fg-white', 'FAIL'); $this->lastTestFailed = true; @@ -80,11 +86,11 @@ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_Asser /** * A warning occurred. * - * @param PHPUnit_Framework_Test $test - * @param PHPUnit_Framework_Warning $e - * @param float $time + * @param Test $test + * @param Warning $e + * @param float $time */ - public function addWarning(PHPUnit_Framework_Test $test, PHPUnit_Framework_Warning $e, $time) + public function addWarning(Test $test, Warning $e, $time) { $this->writeProgressWithColor('fg-red, bold', 'WARNING'); $this->lastTestFailed = true; @@ -96,11 +102,11 @@ public function addWarning(PHPUnit_Framework_Test $test, PHPUnit_Framework_Warni /** * Incomplete test. * - * @param PHPUnit_Framework_Test $test - * @param Exception $e - * @param float $time + * @param Test $test + * @param Exception $e + * @param float $time */ - public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + public function addIncompleteTest(Test $test, Exception $e, $time) { $this->writeProgressWithColor('fg-yellow, bold', 'INCOMPLETE'); $this->lastTestFailed = true; @@ -112,11 +118,11 @@ public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $t /** * Risky test. * - * @param PHPUnit_Framework_Test $test - * @param Exception $e - * @param float $time + * @param Test $test + * @param Exception $e + * @param float $time */ - public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) + public function addRiskyTest(Test $test, Exception $e, $time) { $this->writeProgressWithColor('fg-yellow, bold', 'RISKY'); $this->lastTestFailed = true; @@ -128,16 +134,16 @@ public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) /** * Skipped test. * - * @param PHPUnit_Framework_Test $test - * @param Exception $e - * @param float $time + * @param Test $test + * @param Exception $e + * @param float $time */ - public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + public function addSkippedTest(Test $test, Exception $e, $time) { // PHPUnit will skip a test without "starting" or "ending" it if a dependency isn't being met. if ($test->getName() != $this->lastTestName) { $this->writeNewLine(); - $this->writeProgressWithColor('fg-cyan, bold', 'SKIPPING: ' . PHPUnit_Util_Test::describe($test)); + $this->writeProgressWithColor('fg-cyan, bold', 'SKIPPING: ' . TestUtil::describe($test)); $this->writeNewLine(); $this->writeProgress($e->getMessage()); $this->writeNewLine(); @@ -150,14 +156,14 @@ public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time /** * A test started. * - * @param PHPUnit_Framework_Test $test + * @param Test $test */ - public function startTest(PHPUnit_Framework_Test $test) + public function startTest(Test $test) { $this->write( sprintf( "\nStarting test '%s'.\n", - PHPUnit_Util_Test::describe($test) + TestUtil::describe($test) ) ); $this->lastTestName = $test->getName(); @@ -166,25 +172,25 @@ public function startTest(PHPUnit_Framework_Test $test) /** * A test ended. * - * @param PHPUnit_Framework_Test $test - * @param float $time + * @param Test $test + * @param float $time */ - public function endTest(PHPUnit_Framework_Test $test, $time) + public function endTest(Test $test, $time) { if (!$this->lastTestFailed) { $this->writeProgressWithColor('fg-green, bold', 'PASS'); } - if ($test instanceof PHPUnit_Framework_TestCase) { + if ($test instanceof TestCase) { $this->numAssertions += $test->getNumAssertions(); - } elseif ($test instanceof PHPUnit_Extensions_PhptTestCase) { + } elseif ($test instanceof PhptTestCase) { $this->numAssertions++; } $this->lastTestFailed = false; $this->lastTestName = ''; - if ($test instanceof PHPUnit_Framework_TestCase) { + if ($test instanceof TestCase) { if (!$test->hasExpectationOnOutput()) { if ($output = $test->getActualOutput()) { $this->writeNewLine(); From 19603077ceebbd65922fde5021f85410eb411878 Mon Sep 17 00:00:00 2001 From: Petr Kotek Date: Mon, 26 Jun 2017 16:18:09 +1000 Subject: [PATCH 2/3] Update tests to work under PHPUnit 6 --- tests/CommandTest.php | 4 +++- tests/ConfigurationAlphaTest.php | 4 +++- tests/ConfigurationEnumeratedFilesTest.php | 4 +++- tests/ConfigurationExtendedAttributesTest.php | 4 +++- tests/ConfigurationPriorityTest.php | 4 +++- tests/ConfigurationTest.php | 4 +++- tests/UtilTest.php | 6 ++++-- tests/XmlGeneratorTest.php | 4 +++- 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 5dcd1c4..27bbba6 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -1,5 +1,7 @@ assertTrue(SolanoLabs_PHPUnit_Util::isRootRelativePath(__FILE__)); $this->assertFalse(SolanoLabs_PHPUnit_Util::isRootRelativePath(basename(__FILE__))); } -} \ No newline at end of file +} diff --git a/tests/XmlGeneratorTest.php b/tests/XmlGeneratorTest.php index ff61a34..838f0b6 100644 --- a/tests/XmlGeneratorTest.php +++ b/tests/XmlGeneratorTest.php @@ -1,5 +1,7 @@ Date: Mon, 26 Jun 2017 16:19:03 +1000 Subject: [PATCH 3/3] Update composer.json and solano.yml to support only PHPUnit 6 and PHP 7 / 7.1 --- composer.json | 2 +- solano.yml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 60533d4..8f8bc11 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ } ], "require": { - "phpunit/phpunit": "^4.0|^5.0|^6.0" + "phpunit/phpunit": "^6.0" }, "autoload": { "classmap": [ diff --git a/solano.yml b/solano.yml index 2298d08..8bfbbf0 100644 --- a/solano.yml +++ b/solano.yml @@ -17,9 +17,8 @@ tests: php: php_version: SPLIT: - - '5.3' - - '5.5' - '7.0' + - '7.1' hooks: pre_setup: composer install