Skip to content

Commit 18d0fe0

Browse files
authored
Merge pull request #3411 from williamdes/phpunit-upgrades
Allow PHPUnit 10, 11 and 12
2 parents 17eba51 + d2a9975 commit 18d0fe0

15 files changed

+73
-59
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
/.gitignore export-ignore
1111
/CODE_OF_CONDUCT.md export-ignore
1212
/CONTRIBUTING.md export-ignore
13+
/MAINTAINERS.md export-ignore
1314
/README.md export-ignore
1415
/UPGRADING.md export-ignore
1516
/phpcs.xml.dist export-ignore
1617
/phpstan.neon.dist export-ignore
1718
/phpunit.xml.dist export-ignore
19+
/psalm.xml export-ignore
1820
/tests export-ignore

.github/workflows/tests.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Tests
22

3+
permissions:
4+
contents: read
5+
36
on: [push, pull_request]
47

58
jobs:
@@ -12,13 +15,17 @@ jobs:
1215
matrix:
1316
php: [7.4, 8.0, 8.1, 8.2, 8.3, 8.4]
1417
experimental: [false]
18+
composer-options: ['']
1519
include:
1620
- php: 8.2
1721
analysis: true
22+
- php: nightly
23+
experimental: true
24+
composer-options: '--ignore-platform-req=php+'
1825

1926
steps:
2027
- name: Checkout
21-
uses: actions/checkout@v4
28+
uses: actions/checkout@v5
2229

2330
- name: Set up PHP ${{ matrix.php }}
2431
uses: shivammathur/setup-php@v2
@@ -27,12 +34,7 @@ jobs:
2734
coverage: xdebug
2835

2936
- name: Install dependencies with Composer
30-
if: matrix.php < '8.4'
31-
run: composer update --prefer-dist --no-progress --no-interaction --ansi
32-
33-
- name: Install dependencies with Composer
34-
if: matrix.php >= '8.4'
35-
run: composer update --prefer-dist --no-progress --no-interaction --ansi --ignore-platform-reqs
37+
run: composer update --prefer-dist --no-progress --no-interaction --ansi ${{ matrix.composer-options }}
3638

3739
- name: Coding standards
3840
if: matrix.analysis
@@ -43,12 +45,11 @@ jobs:
4345
run: vendor/bin/phpstan
4446

4547
- name: Tests
46-
run: vendor/bin/phpunit --coverage-clover clover.xml
48+
run: vendor/bin/phpunit ${{ matrix.analysis && '--coverage-clover clover.xml' || '--no-coverage' }}
4749

4850
- name: Upload coverage results to Coveralls
4951
if: matrix.analysis
50-
env:
51-
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52-
run: |
53-
composer require php-coveralls/php-coveralls -n -W
54-
vendor/bin/php-coveralls --coverage_clover=clover.xml -v
52+
uses: coverallsapp/github-action@v2
53+
with:
54+
flag-name: php-${{ matrix.php }}
55+
files: clover.xml

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"phpspec/prophecy": "^1.19",
6666
"phpspec/prophecy-phpunit": "^2.1",
6767
"phpstan/phpstan": "^1 || ^2",
68-
"phpunit/phpunit": "^9.6",
68+
"phpunit/phpunit": "^9.6 || ^10 || ^11 || ^12",
6969
"slim/http": "^1.3",
7070
"slim/psr7": "^1.6",
7171
"squizlabs/php_codesniffer": "^3.10",

phpunit.xml.dist

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.3/phpunit.xsd"
44
beStrictAboutChangesToGlobalState="true"
55
beStrictAboutOutputDuringTests="true"
66
colors="true"
77
bootstrap="tests/bootstrap.php"
88
executionOrder="random"
9+
cacheDirectory=".phpunit.cache"
910
>
1011
<testsuites>
1112
<testsuite name="Slim Test Suite">
1213
<directory>tests</directory>
14+
<exclude>tests/Mocks</exclude>
1315
</testsuite>
1416
</testsuites>
15-
16-
<coverage processUncoveredFiles="true">
17-
<include>
18-
<directory>Slim</directory>
19-
</include>
17+
<coverage>
2018
<report>
2119
<html outputDirectory="coverage" lowUpperBound="20" highLowerBound="50"/>
2220
</report>
2321
</coverage>
22+
<source>
23+
<include>
24+
<directory>Slim</directory>
25+
</include>
26+
</source>
2427
</phpunit>

tests/AppTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function testGetMiddlewareDispatcherGetsSeededAndReturnsInjectedInstance(
155155
$this->assertSame($middlewareDispatcherProphecy->reveal(), $app->getMiddlewareDispatcher());
156156
}
157157

158-
public function lowerCaseRequestMethodsProvider(): array
158+
public static function lowerCaseRequestMethodsProvider(): array
159159
{
160160
return [
161161
['get'],
@@ -171,6 +171,7 @@ public function lowerCaseRequestMethodsProvider(): array
171171
* @param string $method
172172
* @dataProvider upperCaseRequestMethodsProvider()
173173
*/
174+
#[\PHPUnit\Framework\Attributes\DataProvider('upperCaseRequestMethodsProvider')]
174175
public function testGetPostPutPatchDeleteOptionsMethods(string $method): void
175176
{
176177
$streamProphecy = $this->prophesize(StreamInterface::class);
@@ -244,7 +245,7 @@ public function testAnyRoute(): void
244245
* Route collector proxy methods
245246
*******************************************************************************/
246247

247-
public function upperCaseRequestMethodsProvider(): array
248+
public static function upperCaseRequestMethodsProvider(): array
248249
{
249250
return [
250251
['GET'],
@@ -261,6 +262,8 @@ public function upperCaseRequestMethodsProvider(): array
261262
* @dataProvider lowerCaseRequestMethodsProvider
262263
* @dataProvider upperCaseRequestMethodsProvider
263264
*/
265+
#[\PHPUnit\Framework\Attributes\DataProvider('lowerCaseRequestMethodsProvider')]
266+
#[\PHPUnit\Framework\Attributes\DataProvider('upperCaseRequestMethodsProvider')]
264267
public function testMapRoute(string $method): void
265268
{
266269
$streamProphecy = $this->prophesize(StreamInterface::class);
@@ -376,7 +379,7 @@ public function testRouteWithInternationalCharacters(): void
376379
* Route Patterns
377380
*******************************************************************************/
378381

379-
public function routePatternsProvider(): array
382+
public static function routePatternsProvider(): array
380383
{
381384
return [
382385
[''], // Empty Route
@@ -391,6 +394,7 @@ public function routePatternsProvider(): array
391394
* @param string $pattern
392395
* @dataProvider routePatternsProvider
393396
*/
397+
#[\PHPUnit\Framework\Attributes\DataProvider('routePatternsProvider')]
394398
public function testRoutePatterns(string $pattern): void
395399
{
396400
$responseFactoryProphecy = $this->prophesize(ResponseFactoryInterface::class);
@@ -409,7 +413,7 @@ public function testRoutePatterns(string $pattern): void
409413
* Route Groups
410414
*******************************************************************************/
411415

412-
public function routeGroupsDataProvider(): array
416+
public static function routeGroupsDataProvider(): array
413417
{
414418
return [
415419
'empty group with empty route' => [
@@ -539,6 +543,7 @@ public function testGroupClosureIsBoundToThisClass(): void
539543
* @param array $sequence
540544
* @param string $expectedPath
541545
*/
546+
#[\PHPUnit\Framework\Attributes\DataProvider('routeGroupsDataProvider')]
542547
public function testRouteGroupCombinations(array $sequence, string $expectedPath): void
543548
{
544549
$responseFactoryProphecy = $this->prophesize(ResponseFactoryInterface::class);

tests/Factory/AppFactoryTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function tearDown(): void
5050
$reflectionClass->setStaticPropertyValue('responseFactoryClass', DecoratedResponseFactory::class);
5151
}
5252

53-
public function provideImplementations()
53+
public static function provideImplementations()
5454
{
5555
return [
5656
[SlimPsr17Factory::class, SlimResponseFactory::class],
@@ -66,6 +66,7 @@ public function provideImplementations()
6666
* @param string $psr17factory
6767
* @param string $expectedResponseFactoryClass
6868
*/
69+
#[\PHPUnit\Framework\Attributes\DataProvider('provideImplementations')]
6970
public function testCreateAppWithAllImplementations(string $psr17factory, string $expectedResponseFactoryClass)
7071
{
7172
Psr17FactoryProvider::setFactories([$psr17factory]);
@@ -134,6 +135,7 @@ public function testSetPsr17FactoryProvider()
134135
/**
135136
* @runInSeparateProcess - Psr17FactoryProvider::setFactories breaks other tests
136137
*/
138+
#[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
137139
public function testResponseFactoryIsStillReturnedIfStreamFactoryIsNotAvailable()
138140
{
139141
Psr17FactoryProvider::setFactories([MockPsr17FactoryWithoutStreamFactory::class]);
@@ -147,6 +149,7 @@ public function testResponseFactoryIsStillReturnedIfStreamFactoryIsNotAvailable(
147149
/**
148150
* @runInSeparateProcess - AppFactory::setResponseFactory breaks other tests
149151
*/
152+
#[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
150153
public function testAppIsCreatedWithInstancesFromSetters()
151154
{
152155
$responseFactoryProphecy = $this->prophesize(ResponseFactoryInterface::class);
@@ -204,6 +207,7 @@ public function testAppIsCreatedWithInstancesFromSetters()
204207
* @runInSeparateProcess - AppFactory::create saves $responseFactory into static::$responseFactory,
205208
* this breaks other tests
206209
*/
210+
#[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
207211
public function testAppIsCreatedWithInjectedInstancesFromFunctionArguments()
208212
{
209213
$responseFactoryProphecy = $this->prophesize(ResponseFactoryInterface::class);
@@ -254,6 +258,7 @@ public function testAppIsCreatedWithInjectedInstancesFromFunctionArguments()
254258
/**
255259
* @runInSeparateProcess - AppFactory::setResponseFactory breaks other tests
256260
*/
261+
#[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
257262
public function testResponseAndStreamFactoryIsBeingInjectedInDecoratedResponseFactory()
258263
{
259264
$responseProphecy = $this->prophesize(ResponseInterface::class);

tests/Factory/Psr17/Psr17FactoryProviderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Psr17FactoryProviderTest extends TestCase
1818
/**
1919
* @runInSeparateProcess - Psr17FactoryProvider::setFactories breaks other tests
2020
*/
21+
#[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
2122
public function testGetSetFactories()
2223
{
2324
Psr17FactoryProvider::setFactories([]);
@@ -29,6 +30,7 @@ public function testGetSetFactories()
2930
/**
3031
* @runInSeparateProcess - Psr17FactoryProvider::setFactories breaks other tests
3132
*/
33+
#[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
3234
public function testAddFactory()
3335
{
3436
Psr17FactoryProvider::setFactories(['Factory 1']);

tests/Factory/ServerRequestCreatorFactoryTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
class ServerRequestCreatorFactoryTest extends TestCase
3333
{
34-
public function provideImplementations()
34+
public static function provideImplementations()
3535
{
3636
return [
3737
[SlimPsr17Factory::class, SlimServerRequest::class],
@@ -47,6 +47,7 @@ public function provideImplementations()
4747
* @param string $psr17factory
4848
* @param string $expectedServerRequestClass
4949
*/
50+
#[\PHPUnit\Framework\Attributes\DataProvider('provideImplementations')]
5051
public function testCreateAppWithAllImplementations(string $psr17factory, string $expectedServerRequestClass)
5152
{
5253
Psr17FactoryProvider::setFactories([$psr17factory]);
@@ -72,6 +73,7 @@ public function testDetermineServerRequestCreatorReturnsDecoratedServerRequestCr
7273
/**
7374
* @runInSeparateProcess - Psr17FactoryProvider::setFactories breaks other tests
7475
*/
76+
#[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
7577
public function testDetermineServerRequestCreatorThrowsRuntimeException()
7678
{
7779
$this->expectException(RuntimeException::class);
@@ -96,6 +98,7 @@ public function testSetPsr17FactoryProvider()
9698
/**
9799
* @runInSeparateProcess - ServerRequestCreatorFactory::setServerRequestCreator breaks other tests
98100
*/
101+
#[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
99102
public function testSetServerRequestCreatorWithoutDecorators()
100103
{
101104
ServerRequestCreatorFactory::setSlimHttpDecoratorsAutomaticDetection(false);
@@ -117,6 +120,7 @@ public function testSetServerRequestCreatorWithoutDecorators()
117120
/**
118121
* @runInSeparateProcess - ServerRequestCreatorFactory::setServerRequestCreator breaks other tests
119122
*/
123+
#[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
120124
public function testSetServerRequestCreatorWithDecorators()
121125
{
122126
ServerRequestCreatorFactory::setSlimHttpDecoratorsAutomaticDetection(true);

tests/Handlers/ErrorHandlerTest.php

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ private function getMockLogger(): LoggerInterface
3636

3737
public function testDetermineRenderer()
3838
{
39-
$handler = $this
40-
->getMockBuilder(ErrorHandler::class)
41-
->disableOriginalConstructor()
42-
->getMock();
39+
$handler = $this->createMock(ErrorHandler::class);
4340
$class = new ReflectionClass(ErrorHandler::class);
4441

4542
$callableResolverProperty = $class->getProperty('callableResolver');
@@ -77,10 +74,7 @@ public function testDetermineRenderer()
7774
public function testDetermineStatusCode()
7875
{
7976
$request = $this->createServerRequest('/');
80-
$handler = $this
81-
->getMockBuilder(ErrorHandler::class)
82-
->disableOriginalConstructor()
83-
->getMock();
77+
$handler = $this->createMock(ErrorHandler::class);
8478
$class = new ReflectionClass(ErrorHandler::class);
8579

8680
$reflectionProperty = $class->getProperty('responseFactory');
@@ -129,10 +123,7 @@ public function testHalfValidContentType()
129123
->createServerRequest('/', 'GET')
130124
->withHeader('Content-Type', 'unknown/json+');
131125

132-
$handler = $this
133-
->getMockBuilder(ErrorHandler::class)
134-
->disableOriginalConstructor()
135-
->getMock();
126+
$handler = $this->createMock(ErrorHandler::class);
136127
$newErrorRenderers = [
137128
'application/xml' => XmlErrorRenderer::class,
138129
'text/xml' => XmlErrorRenderer::class,
@@ -164,10 +155,7 @@ public function testDetermineContentTypeTextPlainMultiAcceptHeader()
164155
->withHeader('Content-Type', 'text/plain')
165156
->withHeader('Accept', 'text/plain,text/xml');
166157

167-
$handler = $this
168-
->getMockBuilder(ErrorHandler::class)
169-
->disableOriginalConstructor()
170-
->getMock();
158+
$handler = $this->createMock(ErrorHandler::class);
171159

172160
$errorRenderers = [
173161
'text/plain' => PlainTextErrorRenderer::class,
@@ -199,10 +187,7 @@ public function testDetermineContentTypeApplicationJsonOrXml()
199187
->withHeader('Content-Type', 'text/json')
200188
->withHeader('Accept', 'application/xhtml+xml');
201189

202-
$handler = $this
203-
->getMockBuilder(ErrorHandler::class)
204-
->disableOriginalConstructor()
205-
->getMock();
190+
$handler = $this->createMock(ErrorHandler::class);
206191

207192
$errorRenderers = [
208193
'application/xml' => XmlErrorRenderer::class
@@ -242,10 +227,7 @@ public function testAcceptableMediaTypeIsNotFirstInList()
242227
$method->setAccessible(true);
243228

244229
// use a mock object here as ErrorHandler cannot be directly instantiated
245-
$handler = $this
246-
->getMockBuilder(ErrorHandler::class)
247-
->disableOriginalConstructor()
248-
->getMock();
230+
$handler = $this->createMock(ErrorHandler::class);
249231

250232
// call determineContentType()
251233
$return = $method->invoke($handler, $request);

tests/Middleware/BodyParsingMiddlewareTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function createRequestWithBody($contentType, $body)
6464
}
6565

6666

67-
public function parsingProvider()
67+
public static function parsingProvider()
6868
{
6969
return [
7070
'form' => [
@@ -148,6 +148,7 @@ public function parsingProvider()
148148
/**
149149
* @dataProvider parsingProvider
150150
*/
151+
#[\PHPUnit\Framework\Attributes\DataProvider('parsingProvider')]
151152
public function testParsing($contentType, $body, $expected)
152153
{
153154
$request = $this->createRequestWithBody($contentType, $body);

0 commit comments

Comments
 (0)