From b4e82b723da8f78579f5719d6f1943af2c4726d1 Mon Sep 17 00:00:00 2001 From: Oleg Jukovec Date: Mon, 24 Jun 2024 15:00:31 +0300 Subject: [PATCH] Fix test run with PHPUnit 11.2.4 The patch replaces `assertRegExp` with `assertMatchesRegularExpression` because the first one is outdated. Closes #157 --- test/DMLTest.php | 4 ++-- test/PhpUnitCompat.php | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/test/DMLTest.php b/test/DMLTest.php index c2d1e5b..558551d 100644 --- a/test/DMLTest.php +++ b/test/DMLTest.php @@ -361,7 +361,7 @@ public function test_16_hash_select() { self::$tarantool->select("test_hash", null, null, null, null, TARANTOOL::ITERATOR_EQ); $this->assertFalse(True); } catch (TarantoolClientError $e) { - $this->assertRegExp('(Invalid key part|via a partial key)', $e->getMessage()); + $this->assertMatchesRegularExpression('(Invalid key part|via a partial key)', $e->getMessage()); } } @@ -373,7 +373,7 @@ public function test_17_01_it_clienterror($spc, $itype, $xcmsg) { self::$tarantool->select($spc, null, null, null, null, $itype); $this->assertFalse(True); } catch (TarantoolClientError $e) { - $this->assertRegExp($xcmsg, $e->getMessage()); + $this->assertMatchesRegularExpression($xcmsg, $e->getMessage()); } } diff --git a/test/PhpUnitCompat.php b/test/PhpUnitCompat.php index fbc44f6..d5eca90 100644 --- a/test/PhpUnitCompat.php +++ b/test/PhpUnitCompat.php @@ -230,6 +230,28 @@ public function expectExceptionMessageMatches($regularExpression) { } } +/* + * AssertMatchesRegularExpressionTrait (private). + * + * phpunit-8 provides the new name for the + * assertRegExp() method: + * assertMatchesRegularExpression(). phpunit-10 removes the old name. + * + * This trait adds assertMatchesRegularExpression() method for + * phpunit-6, phpunit-7, phpunit-8 and phpunit-9. + */ +if ($testCaseRef->hasMethod('assertMatchesRegularExpression')) { + trait AssertMatchesRegularExpressionTrait { + /* Nothing to define. */ + } +} else { + trait AssertMatchesRegularExpressionTrait { + public function assertMatchesRegularExpression($pattern, $string, $message = '') { + self::assertRegExp($pattern, $string, $message); + } + } +} + /* * TestCaseCompat (public). * @@ -240,4 +262,5 @@ trait TestCaseCompat use SetUpTearDownTrait; use AssertStringContainsStringTrait; use ExpectExceptionMessageMatchesTrait; + use AssertMatchesRegularExpressionTrait; }