diff --git a/lib/Compat/v6/Assert/MatchesRegularExpression.php b/lib/Compat/v6/Assert/MatchesRegularExpression.php new file mode 100644 index 0000000..c09edc5 --- /dev/null +++ b/lib/Compat/v6/Assert/MatchesRegularExpression.php @@ -0,0 +1,43 @@ +compatSetUp(); + } + + /** + * @deprecated Please use ::compatSetUpBeforeClass() + */ + public static function setUpBeforeClass() + { + static::compatSetUpBeforeClass(); + } + + /** + * @deprecated Please use ::compatTearDown() + */ + protected function tearDown() + { + $this->compatTearDown(); + } + + /** + * @deprecated Please use ::compatTearDownAfterClass() + */ + public static function tearDownAfterClass() + { + static::compatTearDownAfterClass(); + } } diff --git a/lib/Compat/v7/Assert/MatchesRegularExpression.php b/lib/Compat/v7/Assert/MatchesRegularExpression.php new file mode 100644 index 0000000..8d4c9f7 --- /dev/null +++ b/lib/Compat/v7/Assert/MatchesRegularExpression.php @@ -0,0 +1,43 @@ +compatTearDown(); } + /** + * @deprecated Please use ::compatTearDownAfterClass() + */ public static function tearDownAfterClass() { static::compatTearDownAfterClass(); diff --git a/lib/Compat/v8/TestCase.php b/lib/Compat/v8/TestCase.php index 953078d..90fa160 100644 --- a/lib/Compat/v8/TestCase.php +++ b/lib/Compat/v8/TestCase.php @@ -24,6 +24,7 @@ use PHPUnit\Util\InvalidArgumentHelper; use RmpUp\PHPUnitCompat\Compat\TestCaseTrait; +use RmpUp\PHPUnitCompat\Compat\v7\Assert\MatchesRegularExpression; use RmpUp\PHPUnitCompat\Compat\v8\Assert\ArraySubset; /** @@ -35,23 +36,47 @@ class TestCase extends \PHPUnit\Framework\TestCase { use TestCaseTrait; + /** + * Backward-compatibility + * + * Note: This may become heavily opinionated some day + * and very old methods may be dropped. + * Fingers crossed that we can keep BC up for all of them. + */ use ArraySubset; + /** + * Forward-compatibility + */ + use MatchesRegularExpression; + + /** + * @deprecated Please use ::compatSetUp() instead + */ protected function setUp(): void { $this->compatSetUp(); } + /** + * @deprecated Please use ::compatSetUpBeforeClass() instead. + */ public static function setUpBeforeClass(): void { static::compatSetUpBeforeClass(); } + /** + * @deprecated Please use ::compatTearDown() instead. + */ protected function tearDown(): void { $this->compatTearDown(); } + /** + * @deprecated Please use compatTearDownAfterClass() instead. + */ public static function tearDownAfterClass(): void { static::compatTearDownAfterClass(); diff --git a/lib/Compat/v9/TestCase.php b/lib/Compat/v9/TestCase.php index 034a330..91bbd74 100644 --- a/lib/Compat/v9/TestCase.php +++ b/lib/Compat/v9/TestCase.php @@ -22,13 +22,57 @@ namespace RmpUp\PHPUnitCompat\Compat\v9; +use RmpUp\PHPUnitCompat\Compat\TestCaseTrait; use RmpUp\PHPUnitCompat\Compat\v8\Assert\ArraySubset; /** * TestCase */ -class TestCase extends \RmpUp\PHPUnitCompat\Compat\v8\TestCase +class TestCase extends \PHPUnit\Framework\TestCase { + use TestCaseTrait; + + /** + * Backward-compatibility + * + * Note: This may become heavily opinionated some day + * and very old methods may be dropped. + * Fingers crossed that we can keep BC up for all of them. + */ + use ArraySubset; + + /** + * @deprecated Please use ::compatSetUp() instead + */ + protected function setUp(): void + { + $this->compatSetUp(); + } + + /** + * @deprecated Please use ::compatSetUpBeforeClass() instead. + */ + public static function setUpBeforeClass(): void + { + static::compatSetUpBeforeClass(); + } + + /** + * @deprecated Please use ::compatTearDown() instead. + */ + protected function tearDown(): void + { + $this->compatTearDown(); + } + + /** + * @deprecated Please use compatTearDownAfterClass() instead. + */ + public static function tearDownAfterClass(): void + { + static::compatTearDownAfterClass(); + } + /** * @deprecated Use expectExceptionMessageMatches() instead */ diff --git a/lib/Versions.php b/lib/Versions.php index 8ab2012..2238972 100644 --- a/lib/Versions.php +++ b/lib/Versions.php @@ -29,24 +29,34 @@ */ class Versions { + private static $version; + + /** + * List of classes last seen in the mapped PHPUnit version + * + * Those classes are all deprecated. + * Their last occurrence tells us something about the PHPUnit version. + * + * @var int[] + */ + private static $classToVersion = [ + \PHPUnit\Framework\BaseTestListener::class => 6, + \PHPUnit\Util\TestDox\TestResult::class => 7, + \PHPUnit\Util\Configuration::class => 8, + \PHPUnit\Util\Blacklist::class => 9 + ]; + public static function getPhpUnitVersion(): int { - if (class_exists(\PHPUnit\Framework\BaseTestListener::class)) { - return 6; - } - - if (class_exists(\PHPUnit\Util\TestDox\TestResult::class)) { - return 7; - } - - if (class_exists(\PHPUnit\Util\Configuration::class)) { - return 8; - } - - if (class_exists(\PHPUnit\Util\Blacklist::class)) { - return 9; + if (null === self::$version) { + foreach (self::$classToVersion as $className => $phpUnitVersion) { + if (class_exists($className)) { + self::$version = $phpUnitVersion; + break; + } + } } - return 0; + return self::$version; } } diff --git a/opt/doc/TestCase/v10/MatchesRegularExpressionTest.php b/opt/doc/TestCase/v10/MatchesRegularExpressionTest.php new file mode 100644 index 0000000..5688802 --- /dev/null +++ b/opt/doc/TestCase/v10/MatchesRegularExpressionTest.php @@ -0,0 +1,24 @@ +