From a5a9cf23acd1248585173aa32757d9720b5f2d62 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 29 Sep 2020 14:41:40 +0200 Subject: Compatibility with PHPUnit 9 --- tests/TestCase.php | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/TestCase.php (limited to 'tests/TestCase.php') diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 00000000..781e7aa3 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,77 @@ +expectExceptionMessageMatches($regularExpression); + } else { + parent::expectExceptionMessageRegExp($regularExpression); + } + } + + /** + * assertContains is now used for iterable, strings should use assertStringContainsString + */ + public function assertContainsPolyfill($expected, $actual, string $message = ''): void + { + if (is_string($actual) && method_exists($this, 'assertStringContainsString')) { + static::assertStringContainsString($expected, $actual, $message); + } else { + static::assertContains($expected, $actual, $message); + } + } + + /** + * assertNotContains is now used for iterable, strings should use assertStringNotContainsString + */ + public function assertNotContainsPolyfill($expected, $actual, string $message = ''): void + { + if (is_string($actual) && method_exists($this, 'assertStringNotContainsString')) { + static::assertStringNotContainsString($expected, $actual, $message); + } else { + static::assertNotContains($expected, $actual, $message); + } + } + + /** + * assertFileNotExists has been renamed in assertFileDoesNotExist + */ + public static function assertFileNotExists(string $filename, string $message = ''): void + { + if (method_exists(TestCase::class, 'assertFileDoesNotExist')) { + static::assertFileDoesNotExist($filename, $message); + } else { + parent::assertFileNotExists($filename, $message); + } + } + + /** + * assertRegExp has been renamed in assertMatchesRegularExpression + */ + public static function assertRegExp(string $pattern, string $string, string $message = ''): void + { + if (method_exists(TestCase::class, 'assertMatchesRegularExpression')) { + static::assertMatchesRegularExpression($pattern, $string, $message); + } else { + parent::assertRegExp($pattern, $string, $message); + } + } + + public function isInTestsContext(): bool + { + return true; + } +} -- cgit v1.2.3