From 855252b037560314da5d0cd34391cc539366c449 Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Wed, 13 Mar 2024 18:37:03 +0100 Subject: [PATCH] Fix backcompat for assertMatchesRegularExpression --- .github/workflows/tests.yml | 2 +- tests/CollisionTest.php | 8 ++++---- tests/HooksTest.php | 6 +++--- tests/TestCase.php | 11 +++++++++++ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d11fab5..e0f3a83 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: composer-dependency: prefer-lowest - php: "8.2" composer-dependency: prefer-lowest - - php: "8.2" + - php: "8.3" composer-dependency: prefer-lowest name: "PHP ${{ matrix.php }} - ${{ matrix.composer-dependency }}" runs-on: ubuntu-latest diff --git a/tests/CollisionTest.php b/tests/CollisionTest.php index b16d957..4c4d725 100644 --- a/tests/CollisionTest.php +++ b/tests/CollisionTest.php @@ -78,7 +78,7 @@ public function testVoidElementSingleAttributeCollisions() $this->assertCount(1, $contents); - $this->assertMatchesRegularExpression('/content\=\"My Second Site Name\"/', $contents[0]); + $this->assertMatchesRegularExpressionCustom('/content\=\"My Second Site Name\"/', $contents[0]); } public function testVoidElementSingleOptionalAttributeCollisions() @@ -99,8 +99,8 @@ public function testVoidElementSingleOptionalAttributeCollisions() $this->assertCount(2, $contents); - $this->assertMatchesRegularExpression('/content\=\"My Site Name\"/', $contents[0]); - $this->assertMatchesRegularExpression('/content\=\"My Second Site Name\"/', $contents[1]); + $this->assertMatchesRegularExpressionCustom('/content\=\"My Site Name\"/', $contents[0]); + $this->assertMatchesRegularExpressionCustom('/content\=\"My Second Site Name\"/', $contents[1]); } public function testVoidElementMultipleAttributesCollisions() @@ -123,6 +123,6 @@ public function testVoidElementMultipleAttributesCollisions() $this->assertCount(1, $contents); - $this->assertMatchesRegularExpression('/content\=\"My Second Value\"/', $contents[0]); + $this->assertMatchesRegularExpressionCustom('/content\=\"My Second Value\"/', $contents[0]); } } diff --git a/tests/HooksTest.php b/tests/HooksTest.php index 06a5a5c..4f7f1ad 100644 --- a/tests/HooksTest.php +++ b/tests/HooksTest.php @@ -102,7 +102,7 @@ public function testExistingAttributesHooks() $contents = seo()->render()->toArray(); - $this->assertMatchesRegularExpression('/content\=\"My Second Title\"/', $contents[0]); + $this->assertMatchesRegularExpressionCustom('/content\=\"My Second Title\"/', $contents[0]); OpenGraph::clearHooks(); } @@ -124,7 +124,7 @@ public function testAppendingAttributesHooks() $contents = seo()->render()->toArray(); - $this->assertMatchesRegularExpression('/should\=\"exist\"/', $contents[0]); + $this->assertMatchesRegularExpressionCustom('/should\=\"exist\"/', $contents[0]); OpenGraph::clearHooks(); } @@ -146,7 +146,7 @@ public function testAttributeHooks() $contents = seo()->render()->toArray(); - $this->assertMatchesRegularExpression('/content\=\"My Title 1\"/', $contents[0]); + $this->assertMatchesRegularExpressionCustom('/content\=\"My Title 1\"/', $contents[0]); OpenGraph::clearHooks(); } diff --git a/tests/TestCase.php b/tests/TestCase.php index f5b1e29..f214c16 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -31,4 +31,15 @@ protected function getPackageAliases($app) 'Seo' => Seo::class, ]; } + + public static function assertMatchesRegularExpressionCustom(string $pattern, string $string, string $message = ''): void + { + // If parent has method assertMatchesRegularExpression, call it + if (method_exists(BaseTestCase::class, 'assertMatchesRegularExpression')) { + parent::assertMatchesRegularExpression($pattern, $string, $message); + return; + } + + static::assertThat($string, new RegularExpression($pattern), $message); + } }