Skip to content

Commit cb9a4f4

Browse files
committed
use the right method for phpunit < 9
1 parent 62f8d79 commit cb9a4f4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tests/Functional/RepeatTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Functional\Exceptions\InvalidArgumentException;
1414
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Runner\Version as PHPUnitVersion;
1516

1617
use function Functional\repeat;
1718

@@ -48,11 +49,20 @@ public function testNegativeRepeatedTimes(): void
4849

4950
// See https://3v4l.org/Ms79G for message formats
5051
// See https://regex101.com/r/hTvW3o/1 for regex setup
51-
$this->expectExceptionMessageMatches(
52-
'/(Functional\\\\{closure}' // PHP < 8.4
52+
if (\version_compare(PHPUnitVersion::id(), '9.0.0', '>=') >= 0) {
53+
// PHPUnit 10 changed the wording of the exception message
54+
$this->expectExceptionMessageMatches(
55+
'/(Functional\\\\{closure}' // PHP < 8.4
5356
. '|{closure:Functional\\\\repeat\(\):[0-9]+})' // PHP 8.4+
5457
. '\(\) expects parameter 1 to be positive integer, negative integer given/'
55-
);
58+
);
59+
} else {
60+
$this->expectExceptionMessageRegExp(
61+
'/(Functional\\\\{closure}' // PHP < 8.4
62+
. '|{closure:Functional\\\\repeat\(\):[0-9]+})' // PHP 8.4+
63+
. '\(\) expects parameter 1 to be positive integer, negative integer given/'
64+
);
65+
}
5666

5767
repeat([$this->repeated, 'foo'])(-1);
5868
}

0 commit comments

Comments
 (0)