]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/TestCase.php
Compatibility with PHPUnit 9
[github/shaarli/Shaarli.git] / tests / TestCase.php
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Shaarli;
6
7 /**
8 * Helper class extending \PHPUnit\Framework\TestCase.
9 * Used to make Shaarli UT run on multiple versions of PHPUnit.
10 */
11 class TestCase extends \PHPUnit\Framework\TestCase
12 {
13 /**
14 * expectExceptionMessageRegExp has been removed and replaced by expectExceptionMessageMatches in PHPUnit 9.
15 */
16 public function expectExceptionMessageRegExp(string $regularExpression): void
17 {
18 if (method_exists($this, 'expectExceptionMessageMatches')) {
19 $this->expectExceptionMessageMatches($regularExpression);
20 } else {
21 parent::expectExceptionMessageRegExp($regularExpression);
22 }
23 }
24
25 /**
26 * assertContains is now used for iterable, strings should use assertStringContainsString
27 */
28 public function assertContainsPolyfill($expected, $actual, string $message = ''): void
29 {
30 if (is_string($actual) && method_exists($this, 'assertStringContainsString')) {
31 static::assertStringContainsString($expected, $actual, $message);
32 } else {
33 static::assertContains($expected, $actual, $message);
34 }
35 }
36
37 /**
38 * assertNotContains is now used for iterable, strings should use assertStringNotContainsString
39 */
40 public function assertNotContainsPolyfill($expected, $actual, string $message = ''): void
41 {
42 if (is_string($actual) && method_exists($this, 'assertStringNotContainsString')) {
43 static::assertStringNotContainsString($expected, $actual, $message);
44 } else {
45 static::assertNotContains($expected, $actual, $message);
46 }
47 }
48
49 /**
50 * assertFileNotExists has been renamed in assertFileDoesNotExist
51 */
52 public static function assertFileNotExists(string $filename, string $message = ''): void
53 {
54 if (method_exists(TestCase::class, 'assertFileDoesNotExist')) {
55 static::assertFileDoesNotExist($filename, $message);
56 } else {
57 parent::assertFileNotExists($filename, $message);
58 }
59 }
60
61 /**
62 * assertRegExp has been renamed in assertMatchesRegularExpression
63 */
64 public static function assertRegExp(string $pattern, string $string, string $message = ''): void
65 {
66 if (method_exists(TestCase::class, 'assertMatchesRegularExpression')) {
67 static::assertMatchesRegularExpression($pattern, $string, $message);
68 } else {
69 parent::assertRegExp($pattern, $string, $message);
70 }
71 }
72
73 public function isInTestsContext(): bool
74 {
75 return true;
76 }
77 }