From 4642b9fd1c684b926e547e855663a32171d1af93 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Mon, 1 Mar 2021 18:20:50 -0500 Subject: [PATCH] PRovide upgrade path for assertRegExp --- tests/cases/REST/Miniflux/TestToken.php | 2 +- tests/lib/AbstractTest.php | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/cases/REST/Miniflux/TestToken.php b/tests/cases/REST/Miniflux/TestToken.php index 39978077..484d9b24 100644 --- a/tests/cases/REST/Miniflux/TestToken.php +++ b/tests/cases/REST/Miniflux/TestToken.php @@ -43,7 +43,7 @@ class TestToken extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertSame("RANDOM TOKEN", $this->prepTest()->tokenGenerate("ook", "Eek")); $this->dbMock->tokenCreate->calledWith("ook", "miniflux.login", "~", null, "Eek"); $token = $this->dbMock->tokenCreate->firstCall()->argument(2); - $this->assertRegExp("/^[A-Za-z0-9_\-]{43}=$/", $token); + $this->assertMatchesRegularExpression("/^[A-Za-z0-9_\-]{43}=$/", $token); } public function testListTheTokensOfAUser(): void { diff --git a/tests/lib/AbstractTest.php b/tests/lib/AbstractTest.php index 1eb1b2e3..5d9eb5e7 100644 --- a/tests/lib/AbstractTest.php +++ b/tests/lib/AbstractTest.php @@ -141,6 +141,14 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { return $req; } + public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void { + if (method_exists(parent::class, "assertMatchesRegularExpression")) { + parent::assertMatchesRegularExpression($pattern, $string, $message); + } else { + parent::assertRegExp($pattern, $string, $message); + } + } + public function assertException($msg = "", string $prefix = "", string $type = "Exception"): void { if (func_num_args()) { if ($msg instanceof \JKingWeb\Arsse\AbstractException) { @@ -334,7 +342,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { } // compare the result set to the expectations foreach ($rows as $row) { - $this->assertContains($row, $expected, "Result set contains unexpected record."); + $this->assertEquals($row, $expected, "Result set contains unexpected record."); $found = array_search($row, $expected); unset($expected[$found]); }