Skip to content

Commit

Permalink
Fix test run with PHPUnit 11.2.4
Browse files Browse the repository at this point in the history
The patch replaces `assertRegExp` with `assertMatchesRegularExpression`
because the first one is outdated.

Closes #157
  • Loading branch information
oleg-jukovec committed Jun 25, 2024
1 parent 1324c35 commit b4e82b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/DMLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand All @@ -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());
}
}

Expand Down
23 changes: 23 additions & 0 deletions test/PhpUnitCompat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*
Expand All @@ -240,4 +262,5 @@ trait TestCaseCompat
use SetUpTearDownTrait;
use AssertStringContainsStringTrait;
use ExpectExceptionMessageMatchesTrait;
use AssertMatchesRegularExpressionTrait;
}

0 comments on commit b4e82b7

Please sign in to comment.