Skip to content

Commit 27d099a

Browse files
committed
test: support phpunit-9
Updated the PhpUnitCompat compatibility layer to support both expectExceptionMessageMatches() method on phpunit-6 and phpunit-7/ See the phpunit-9 announcement [1], where expectExceptionMessageRegExp() method removal was announced. We're going to use phpunit-9 for testing the connector on PHP 7.3 and PHP 7.4. [1]: https://phpunit.de/announcements/phpunit-9.html
1 parent 3d0962b commit 27d099a

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

test/CreateTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function test_02_create_error_host() {
5151
$c = new Tarantool('very_bad_host');
5252

5353
$this->expectException(TarantoolException::class);
54-
$this->expectExceptionMessageRegExp(
54+
$this->expectExceptionMessageMatches(
5555
'/Name or service not known' .
5656
'|nodename nor servname provided' .
5757
'|Temporary failure in name resolution/');
@@ -62,7 +62,7 @@ public function test_03_00_create_error_port() {
6262
$c = new Tarantool('127.0.0.1', 65500);
6363

6464
$this->expectException(TarantoolException::class);
65-
$this->expectExceptionMessageRegExp(
65+
$this->expectExceptionMessageMatches(
6666
'/Connection refused|Network is unreachable/');
6767
$c->connect();
6868
}

test/PhpUnitCompat.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
* different phpunit versions (phpunit-6 and phpunit-7 at the
88
* moment).
99
*
10-
* Now it contains workarounds for two problems:
10+
* Now it contains workarounds for the following problems:
1111
*
1212
* - phpunit-7 requirement to use `void` return type declaration
1313
* for several methods.
1414
* - phpunit-8 deprecation warning re using assertContains() for
1515
* search a substring in a string.
16+
* - phpunit-9 removes expectExceptionMessageRegExp() method.
1617
*
1718
* Usage: add `use TestCaseCompat;` in a TestCase derived class
1819
* and follow instructions and examples below.
@@ -74,6 +75,13 @@
7475
* substring in a string. Add `use TestCaseCompat;` to a TestCase
7576
* derived class and use assertStringContainsString() on any
7677
* phpunit-6+ version.
78+
*
79+
* expectExceptionMessageRegExp() removal
80+
* --------------------------------------
81+
*
82+
* phpunit-8 and newer provides the same function under
83+
* expectExceptionMessageMatches() name. phpunit-9 removes the old
84+
* expectExceptionMessageRegExp() alias.
7785
*/
7886

7987
use PHPUnit\Framework\TestCase;
@@ -200,6 +208,28 @@ public static function assertStringContainsString(
200208
}
201209
}
202210

211+
/*
212+
* ExpectExceptionMessageMatchesTrait (private).
213+
*
214+
* phpunit-8 provides the new name for
215+
* expectExceptionMessageRegExp() method:
216+
* expectExceptionMessageMatches(). phpunit-9 removes the old name.
217+
*
218+
* This trait adds expectExceptionMessageMatches() method for
219+
* phpunit-6 and phpunit-7.
220+
*/
221+
if ($testCaseRef->hasMethod('expectExceptionMessageMatches')) {
222+
trait ExpectExceptionMessageMatchesTrait {
223+
/* Nothing to define. */
224+
}
225+
} else {
226+
trait ExpectExceptionMessageMatchesTrait {
227+
public function expectExceptionMessageMatches($regularExpression) {
228+
self::expectExceptionMessageRegExp($regularExpression);
229+
}
230+
}
231+
}
232+
203233
/*
204234
* TestCaseCompat (public).
205235
*
@@ -209,4 +239,5 @@ trait TestCaseCompat
209239
{
210240
use SetUpTearDownTrait;
211241
use AssertStringContainsStringTrait;
242+
use ExpectExceptionMessageMatchesTrait;
212243
}

0 commit comments

Comments
 (0)