Skip to content

Commit

Permalink
Fix backcompat for assertMatchesRegularExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
olssonm authored and romanzipp committed Mar 19, 2024
1 parent a0fdb65 commit a20408b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/CollisionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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]);
}
}
6 changes: 3 additions & 3 deletions tests/HooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down
11 changes: 11 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit a20408b

Please sign in to comment.