diff --git a/tests/TestListeners/Fixtures/FailurePHPUnitGte7.php b/tests/TestListeners/Fixtures/FailurePHPUnitGte7.php new file mode 100644 index 0000000..f1e333c --- /dev/null +++ b/tests/TestListeners/Fixtures/FailurePHPUnitGte7.php @@ -0,0 +1,22 @@ +fail(); + } +} diff --git a/tests/TestListeners/Fixtures/IncompletePHPUnitGte7.php b/tests/TestListeners/Fixtures/IncompletePHPUnitGte7.php new file mode 100644 index 0000000..543b3ad --- /dev/null +++ b/tests/TestListeners/Fixtures/IncompletePHPUnitGte7.php @@ -0,0 +1,22 @@ +markTestIncomplete( 'Test incomplete' ); + } +} diff --git a/tests/TestListeners/Fixtures/RiskyPHPUnitGte7.php b/tests/TestListeners/Fixtures/RiskyPHPUnitGte7.php new file mode 100644 index 0000000..78d482a --- /dev/null +++ b/tests/TestListeners/Fixtures/RiskyPHPUnitGte7.php @@ -0,0 +1,22 @@ +markAsRisky(); + } +} diff --git a/tests/TestListeners/Fixtures/SkippedPHPUnitGte7.php b/tests/TestListeners/Fixtures/SkippedPHPUnitGte7.php new file mode 100644 index 0000000..7b62132 --- /dev/null +++ b/tests/TestListeners/Fixtures/SkippedPHPUnitGte7.php @@ -0,0 +1,22 @@ +markTestSkipped( 'Skipped test' ); + } +} diff --git a/tests/TestListeners/Fixtures/SuccessPHPUnitGte7.php b/tests/TestListeners/Fixtures/SuccessPHPUnitGte7.php new file mode 100644 index 0000000..a4e6d63 --- /dev/null +++ b/tests/TestListeners/Fixtures/SuccessPHPUnitGte7.php @@ -0,0 +1,22 @@ +assertTrue( true ); + } +} diff --git a/tests/TestListeners/Fixtures/TestErrorPHPUnitGte7.php b/tests/TestListeners/Fixtures/TestErrorPHPUnitGte7.php new file mode 100644 index 0000000..b114f4f --- /dev/null +++ b/tests/TestListeners/Fixtures/TestErrorPHPUnitGte7.php @@ -0,0 +1,27 @@ +getTestObject( 'TestError' ); $test->run( $this->result ); $this->assertSame( 1, $this->listener->startTestCount, 'test start count failed' ); @@ -72,7 +67,7 @@ public function testError() { * @return void */ public function testWarning() { - $test = new Warning( 'runTest' ); + $test = $this->getTestObject( 'Warning' ); $test->run( $this->result ); $this->assertSame( 1, $this->listener->startTestCount, 'test start count failed' ); @@ -86,7 +81,7 @@ public function testWarning() { * @return void */ public function testFailure() { - $test = new Failure( 'runTest' ); + $test = $this->getTestObject( 'Failure' ); $test->run( $this->result ); $this->assertSame( 1, $this->listener->startTestCount, 'test start count failed' ); @@ -100,7 +95,7 @@ public function testFailure() { * @return void */ public function testIncomplete() { - $test = new Incomplete( 'runTest' ); + $test = $this->getTestObject( 'Incomplete' ); $test->run( $this->result ); $this->assertSame( 1, $this->listener->startTestCount, 'test start count failed' ); @@ -118,7 +113,7 @@ public function testIncomplete() { * @return void */ public function testRisky() { - $test = new Risky( 'runTest' ); + $test = $this->getTestObject( 'Risky' ); $test->run( $this->result ); $this->assertSame( 1, $this->listener->startTestCount, 'test start count failed' ); @@ -132,7 +127,7 @@ public function testRisky() { * @return void */ public function testSkipped() { - $test = new Skipped( 'runTest' ); + $test = $this->getTestObject( 'Skipped' ); $test->run( $this->result ); $this->assertSame( 1, $this->listener->startTestCount, 'test start count failed' ); @@ -146,10 +141,33 @@ public function testSkipped() { * @return void */ public function testStartStop() { - $test = new Success( 'runTest' ); + $test = $this->getTestObject( 'Success' ); $test->run( $this->result ); $this->assertSame( 1, $this->listener->startTestCount, 'test start count failed' ); $this->assertSame( 1, $this->listener->endTestCount, 'test end count failed' ); } + + /** + * Helper method to get the right Test class object. + * + * Toggles between different versions of the same Test class object: + * - Base version using `runTest()` method, compatible with PHPUnit < 10.0. + * - Version using `testForListener()` method, compatible with PHPUnit > 7.0. + * + * @param string $className Base class name of the test class to instantiate. + * + * @return PHPUnitTestCase + */ + private function getTestObject( $className ) { + $className = '\Yoast\PHPUnitPolyfills\Tests\TestListeners\Fixtures\\' . $className; + $testName = 'runTest'; + + if ( \version_compare( Autoload::getPHPUnitVersion(), '7.0.0', '>=' ) ) { + $className .= 'PHPUnitGte7'; + $testName = 'testForListener'; + } + + return new $className( $testName ); + } }