Skip to content

Commit d032286

Browse files
committed
Drop support for PHPUnit < 8.5
Older PHPUnit versions no longer need to be supported now support for PHP < 7.2 has been dropped. Includes removing the `UnitTestCase::assertStringContains()`, `UnitTestCase::expectErrorException()` and `UnitTestCase::expectExceptionMsgRegex()` methods, which are no longer needed now the tests won't need to run on PHPUnit < 8.5 anymore.
1 parent 89a0de2 commit d032286

File tree

7 files changed

+10
-83
lines changed

7 files changed

+10
-83
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Via Composer following packages are required:
2424

2525
When installed for development, following packages are also required:
2626

27-
* [phpunit/phpunit](https://packagist.org/packages/phpunit/phpunit) version 5.7 or higher \(BSD-3-Clause\)
27+
* [phpunit/phpunit](https://packagist.org/packages/phpunit/phpunit) version 8.5 or higher \(BSD-3-Clause\)
2828

2929
## License
3030

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"antecedent/patchwork": "^2.2.3"
3333
},
3434
"require-dev": {
35-
"phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.49 || ^9.6.30",
35+
"phpunit/phpunit": "^8.5.49 || ^9.6.30",
3636
"phpcompatibility/php-compatibility": "^9.3.0",
3737
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0"
3838
},

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
2+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
33
beStrictAboutTestsThatDoNotTestAnything="false"
44
bootstrap="tests/bootstrap.php"
55
colors="true"

tests/bootstrap.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,3 @@
1616
echo 'Autoload file not found. Please run `composer install`.';
1717
die(1);
1818
}
19-
20-
// PHPUnit cross version compatibility.
21-
if (class_exists('PHPUnit_Framework_Error') === true
22-
&& class_exists('PHPUnit\Framework\Error\Error') === false
23-
) {
24-
class_alias('PHPUnit_Framework_Error', 'PHPUnit\Framework\Error\Error');
25-
}

tests/cases/unit/Api/FunctionsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function testUndefinedFunctionThrowsExceptionRightAfterDefinition()
151151
{
152152
$this->expectException(MissingFunctionExpectations::class);
153153
Functions\when('since_i_am_not_defined_i_will_throw_exception');
154-
$this->expectExceptionMsgRegex('/since_i_am_not_defined_i_will_throw_exception.+not defined/');
154+
$this->expectExceptionMessageMatches('/since_i_am_not_defined_i_will_throw_exception.+not defined/');
155155
/** @noinspection PhpUndefinedFunctionInspection */
156156
since_i_am_not_defined_i_will_throw_exception();
157157
}
@@ -170,7 +170,7 @@ public function testUndefinedFunctionSurviveTests()
170170
public function testSurvivedFunctionStillThrowsException()
171171
{
172172
$this->expectException(MissingFunctionExpectations::class);
173-
$this->expectExceptionMsgRegex('/since_i_am_not_defined_i_will_throw_exception.+not defined/');
173+
$this->expectExceptionMessageMatches('/since_i_am_not_defined_i_will_throw_exception.+not defined/');
174174
/** @noinspection PhpUndefinedFunctionInspection */
175175
since_i_am_not_defined_i_will_throw_exception();
176176
}
@@ -191,7 +191,7 @@ public function testNothingJustMockASurvivedFunction()
191191
public function testSurvivedFunctionStillThrowsExceptionAfterBeingMocked()
192192
{
193193
$this->expectException(MissingFunctionExpectations::class);
194-
$this->expectExceptionMsgRegex('/since_i_am_not_defined_i_will_throw_exception.+not defined/');
194+
$this->expectExceptionMessageMatches('/since_i_am_not_defined_i_will_throw_exception.+not defined/');
195195
/** @noinspection PhpUndefinedFunctionInspection */
196196
since_i_am_not_defined_i_will_throw_exception();
197197
}

tests/cases/unit/Expectation/Exception/ExpectationArgsRequiredTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testBecauseOf($type, $message_part)
2929
new ExpectationTarget($type, 'foo')
3030
)->getMessage();
3131

32-
static::assertStringContains($message_part, $message);
32+
static::assertStringContainsString($message_part, $message);
3333
}
3434

3535
public function expectationTargets()

tests/src/UnitTestCase.php

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
namespace Brain\Monkey\Tests;
1212

1313
use Brain\Monkey;
14-
use PHPUnit\Framework\Error\Error as PHPUnit_Error;
1514
use PHPUnit\Framework\TestCase;
1615

1716
/**
@@ -49,60 +48,6 @@ protected function tearDownFixtures()
4948
$this->tearDownMakingSureExpectedExceptionIsThrown();
5049
}
5150

52-
/**
53-
* PHPUnit cross-version support.
54-
*
55-
* @param string $needle
56-
* @param string $haystack
57-
* @param string $message
58-
* @return void
59-
*/
60-
public static function assertStringContains($needle, $haystack, $message = '') {
61-
62-
if (method_exists(TestCase::class, 'assertStringContainsString')) {
63-
// PHPUnit 7.5+.
64-
TestCase::assertStringContainsString($needle, $haystack, $message);
65-
66-
return;
67-
}
68-
69-
// PHPUnit < 7.5.
70-
static::assertContains($needle, $haystack, $message);
71-
}
72-
73-
/**
74-
* PHPUnit cross-version support.
75-
*/
76-
protected function expectErrorException()
77-
{
78-
if (method_exists($this, 'expectError')) {
79-
// PHPUnit 8.4+.
80-
$this->expectError();
81-
return;
82-
}
83-
84-
// PHPUnit < 8.4.
85-
$this->expectException(PHPUnit_Error::class);
86-
}
87-
88-
/**
89-
* PHPUnit cross-version support.
90-
*
91-
* @param string $msgRegex
92-
* @return void
93-
*/
94-
protected function expectExceptionMsgRegex($msgRegex)
95-
{
96-
if (method_exists($this, 'expectExceptionMessageMatches')) {
97-
// PHPUnit 8.4+.
98-
$this->expectExceptionMessageMatches($msgRegex);
99-
return;
100-
}
101-
102-
// PHPUnit < 8.4.
103-
$this->expectExceptionMessageRegExp($msgRegex);
104-
}
105-
10651
/**
10752
* We can't use PHPUnit expectException() because we need to wait for `Monkey\tearDown` and that
10853
* does not work for `expectException()`.
@@ -123,13 +68,8 @@ protected function tearDownMakingSureExpectedExceptionIsThrown()
12368
$this->expect_mockery_exception
12469
);
12570

126-
if (class_exists('PHPUnit\\Framework\\ExpectationFailedException')) {
127-
// PHPUnit 6.0+.
128-
throw new \PHPUnit\Framework\ExpectationFailedException($message);
129-
} else {
130-
// PHPUnit 5.x.
131-
throw new \PHPUnit_Framework_ExpectationFailedException($message);
132-
}
71+
throw new \PHPUnit\Framework\ExpectationFailedException($message);
72+
13373
} catch (\Throwable $e) {
13474
if (get_class($e) !== $this->expect_mockery_exception) {
13575
throw $e;
@@ -148,13 +88,7 @@ protected function expectMockeryException($class)
14888
$class
14989
);
15090

151-
if (class_exists('PHPUnit\\Framework\\Exception')) {
152-
// PHPUnit 6.0+.
153-
throw new \PHPUnit\Framework\Exception($message);
154-
} else {
155-
// PHPUnit 5.x.
156-
throw new \PHPUnit_Framework_Exception($message);
157-
}
91+
throw new \PHPUnit\Framework\Exception($message);
15892
}
15993

16094
$this->expect_mockery_exception = $class;

0 commit comments

Comments
 (0)