Skip to content

Commit 1c75bcc

Browse files
authored
Merge pull request #3415 from akrabat/support-php8.5
Add support for PHP 8.5
2 parents 18d0fe0 + e1fa9aa commit 1c75bcc

File tree

11 files changed

+74
-48
lines changed

11 files changed

+74
-48
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
include:
2020
- php: 8.2
2121
analysis: true
22+
- php: 8.5
23+
experimental: true
24+
composer-options: '--ignore-platform-req=php+'
2225
- php: nightly
2326
experimental: true
2427
composer-options: '--ignore-platform-req=php+'

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"wiki": "https://github.com/slimphp/Slim/wiki"
4444
},
4545
"require": {
46-
"php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
46+
"php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
4747
"ext-json": "*",
4848
"nikic/fast-route": "^1.3",
4949
"psr/container": "^1.0 || ^2.0",

tests/AppTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -703,18 +703,18 @@ public function testAddRoutingMiddleware(): void
703703

704704
// Check that the routing middleware really has been added to the tip of the app middleware stack.
705705
$middlewareDispatcherProperty = new ReflectionProperty(App::class, 'middlewareDispatcher');
706-
$middlewareDispatcherProperty->setAccessible(true);
706+
$this->setAccessible($middlewareDispatcherProperty);
707707
/** @var MiddlewareDispatcher $middlewareDispatcher */
708708
$middlewareDispatcher = $middlewareDispatcherProperty->getValue($app);
709709

710710
$tipProperty = new ReflectionProperty(MiddlewareDispatcher::class, 'tip');
711-
$tipProperty->setAccessible(true);
711+
$this->setAccessible($tipProperty);
712712
/** @var RequestHandlerInterface $tip */
713713
$tip = $tipProperty->getValue($middlewareDispatcher);
714714

715715
$reflection = new ReflectionClass($tip);
716716
$middlewareProperty = $reflection->getProperty('middleware');
717-
$middlewareProperty->setAccessible(true);
717+
$this->setAccessible($middlewareProperty);
718718

719719
$this->assertSame($routingMiddleware, $middlewareProperty->getValue($tip));
720720
$this->assertInstanceOf(RoutingMiddleware::class, $routingMiddleware);
@@ -736,18 +736,18 @@ public function testAddErrorMiddleware(): void
736736

737737
// Check that the error middleware really has been added to the tip of the app middleware stack.
738738
$middlewareDispatcherProperty = new ReflectionProperty(App::class, 'middlewareDispatcher');
739-
$middlewareDispatcherProperty->setAccessible(true);
739+
$this->setAccessible($middlewareDispatcherProperty);
740740
/** @var MiddlewareDispatcher $middlewareDispatcher */
741741
$middlewareDispatcher = $middlewareDispatcherProperty->getValue($app);
742742

743743
$tipProperty = new ReflectionProperty(MiddlewareDispatcher::class, 'tip');
744-
$tipProperty->setAccessible(true);
744+
$this->setAccessible($tipProperty);
745745
/** @var RequestHandlerInterface $tip */
746746
$tip = $tipProperty->getValue($middlewareDispatcher);
747747

748748
$reflection = new ReflectionClass($tip);
749749
$middlewareProperty = $reflection->getProperty('middleware');
750-
$middlewareProperty->setAccessible(true);
750+
$this->setAccessible($middlewareProperty);
751751

752752
$this->assertSame($errorMiddleware, $middlewareProperty->getValue($tip));
753753
$this->assertInstanceOf(ErrorMiddleware::class, $errorMiddleware);
@@ -766,18 +766,18 @@ public function testAddBodyParsingMiddleware(): void
766766

767767
// Check that the body parsing middleware really has been added to the tip of the app middleware stack.
768768
$middlewareDispatcherProperty = new ReflectionProperty(App::class, 'middlewareDispatcher');
769-
$middlewareDispatcherProperty->setAccessible(true);
769+
$this->setAccessible($middlewareDispatcherProperty);
770770
/** @var MiddlewareDispatcher $middlewareDispatcher */
771771
$middlewareDispatcher = $middlewareDispatcherProperty->getValue($app);
772772

773773
$tipProperty = new ReflectionProperty(MiddlewareDispatcher::class, 'tip');
774-
$tipProperty->setAccessible(true);
774+
$this->setAccessible($tipProperty);
775775
/** @var RequestHandlerInterface $tip */
776776
$tip = $tipProperty->getValue($middlewareDispatcher);
777777

778778
$reflection = new ReflectionClass($tip);
779779
$middlewareProperty = $reflection->getProperty('middleware');
780-
$middlewareProperty->setAccessible(true);
780+
$this->setAccessible($middlewareProperty);
781781

782782
$this->assertSame($bodyParsingMiddleware, $middlewareProperty->getValue($tip));
783783
$this->assertInstanceOf(BodyParsingMiddleware::class, $bodyParsingMiddleware);

tests/Error/AbstractErrorRendererTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testHTMLErrorRendererRenderFragmentMethod()
6060
$reflectionRenderer = new ReflectionClass(HtmlErrorRenderer::class);
6161

6262
$method = $reflectionRenderer->getMethod('renderExceptionFragment');
63-
$method->setAccessible(true);
63+
$this->setAccessible($method);
6464
$output = $method->invoke($renderer, $exception);
6565

6666
$this->assertMatchesRegularExpression('/.*Type:*/', $output);
@@ -101,7 +101,7 @@ public function testJSONErrorRendererDisplaysErrorDetails()
101101
$reflectionRenderer = new ReflectionClass(JsonErrorRenderer::class);
102102

103103
$method = $reflectionRenderer->getMethod('formatExceptionFragment');
104-
$method->setAccessible(true);
104+
$this->setAccessible($method);
105105

106106
$fragment = $method->invoke($renderer, $exception);
107107
$output = json_encode(json_decode($renderer->__invoke($exception, true)));
@@ -128,7 +128,7 @@ public function testJSONErrorRendererDisplaysPreviousError()
128128
$renderer = new JsonErrorRenderer();
129129
$reflectionRenderer = new ReflectionClass(JsonErrorRenderer::class);
130130
$method = $reflectionRenderer->getMethod('formatExceptionFragment');
131-
$method->setAccessible(true);
131+
$this->setAccessible($method);
132132

133133
$output = json_encode(json_decode($renderer->__invoke($exception, true)));
134134

@@ -208,7 +208,7 @@ public function testPlainTextErrorRendererFormatFragmentMethod()
208208
$reflectionRenderer = new ReflectionClass(PlainTextErrorRenderer::class);
209209

210210
$method = $reflectionRenderer->getMethod('formatExceptionFragment');
211-
$method->setAccessible(true);
211+
$this->setAccessible($method);
212212
$output = $method->invoke($renderer, $exception);
213213
$this->assertIsString($output);
214214

tests/Factory/AppFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function testCreateAppWithAllImplementations(string $psr17factory, string
7777
$routeCollector = $app->getRouteCollector();
7878

7979
$responseFactoryProperty = new ReflectionProperty(RouteCollector::class, 'responseFactory');
80-
$responseFactoryProperty->setAccessible(true);
80+
$this->setAccessible($responseFactoryProperty);
8181

8282
$responseFactory = $responseFactoryProperty->getValue($routeCollector);
8383

@@ -281,7 +281,7 @@ public function testResponseAndStreamFactoryIsBeingInjectedInDecoratedResponseFa
281281
$response = $responseFactory->createResponse();
282282

283283
$streamFactoryProperty = new ReflectionProperty(DecoratedResponse::class, 'streamFactory');
284-
$streamFactoryProperty->setAccessible(true);
284+
$this->setAccessible($streamFactoryProperty);
285285

286286
$this->assertSame($streamFactoryProphecy->reveal(), $streamFactoryProperty->getValue($response));
287287
}

tests/Factory/Psr17/SlimHttpServerRequestCreatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function tearDown(): void
3636
SlimHttpServerRequestCreator::class,
3737
'serverRequestDecoratorClass'
3838
);
39-
$serverRequestDecoratorClassProperty->setAccessible(true);
39+
$this->setAccessible($serverRequestDecoratorClassProperty);
4040
$serverRequestDecoratorClassProperty->setValue($slimHttpServerRequestCreator, ServerRequest::class);
4141
}
4242

@@ -69,7 +69,7 @@ public function testCreateServerRequestFromGlobalsThrowsRuntimeException()
6969
SlimHttpServerRequestCreator::class,
7070
'serverRequestDecoratorClass'
7171
);
72-
$serverRequestDecoratorClassProperty->setAccessible(true);
72+
$this->setAccessible($serverRequestDecoratorClassProperty);
7373
$serverRequestDecoratorClassProperty->setValue($slimHttpServerRequestCreator, '');
7474

7575
$slimHttpServerRequestCreator->createServerRequestFromGlobals();

tests/Handlers/ErrorHandlerTest.php

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Slim\Tests\Handlers;
1212

13+
use Prophecy\Argument;
1314
use Psr\Http\Message\ResponseInterface;
1415
use Psr\Log\LoggerInterface;
1516
use ReflectionClass;
@@ -40,15 +41,15 @@ public function testDetermineRenderer()
4041
$class = new ReflectionClass(ErrorHandler::class);
4142

4243
$callableResolverProperty = $class->getProperty('callableResolver');
43-
$callableResolverProperty->setAccessible(true);
44+
$this->setAccessible($callableResolverProperty);
4445
$callableResolverProperty->setValue($handler, $this->getCallableResolver());
4546

4647
$reflectionProperty = $class->getProperty('contentType');
47-
$reflectionProperty->setAccessible(true);
48+
$this->setAccessible($reflectionProperty);
4849
$reflectionProperty->setValue($handler, 'application/json');
4950

5051
$method = $class->getMethod('determineRenderer');
51-
$method->setAccessible(true);
52+
$this->setAccessible($method);
5253

5354
$renderer = $method->invoke($handler);
5455
$this->assertIsCallable($renderer);
@@ -78,15 +79,15 @@ public function testDetermineStatusCode()
7879
$class = new ReflectionClass(ErrorHandler::class);
7980

8081
$reflectionProperty = $class->getProperty('responseFactory');
81-
$reflectionProperty->setAccessible(true);
82+
$this->setAccessible($reflectionProperty);
8283
$reflectionProperty->setValue($handler, $this->getResponseFactory());
8384

8485
$reflectionProperty = $class->getProperty('exception');
85-
$reflectionProperty->setAccessible(true);
86+
$this->setAccessible($reflectionProperty);
8687
$reflectionProperty->setValue($handler, new HttpNotFoundException($request));
8788

8889
$method = $class->getMethod('determineStatusCode');
89-
$method->setAccessible(true);
90+
$this->setAccessible($method);
9091

9192
$statusCode = $method->invoke($handler);
9293
$this->assertSame($statusCode, 404);
@@ -133,15 +134,15 @@ public function testHalfValidContentType()
133134
$class = new ReflectionClass(ErrorHandler::class);
134135

135136
$reflectionProperty = $class->getProperty('responseFactory');
136-
$reflectionProperty->setAccessible(true);
137+
$this->setAccessible($reflectionProperty);
137138
$reflectionProperty->setValue($handler, $this->getResponseFactory());
138139

139140
$reflectionProperty = $class->getProperty('errorRenderers');
140-
$reflectionProperty->setAccessible(true);
141+
$this->setAccessible($reflectionProperty);
141142
$reflectionProperty->setValue($handler, $newErrorRenderers);
142143

143144
$method = $class->getMethod('determineContentType');
144-
$method->setAccessible(true);
145+
$this->setAccessible($method);
145146

146147
$contentType = $method->invoke($handler, $request);
147148

@@ -165,15 +166,15 @@ public function testDetermineContentTypeTextPlainMultiAcceptHeader()
165166
$class = new ReflectionClass(ErrorHandler::class);
166167

167168
$reflectionProperty = $class->getProperty('responseFactory');
168-
$reflectionProperty->setAccessible(true);
169+
$this->setAccessible($reflectionProperty);
169170
$reflectionProperty->setValue($handler, $this->getResponseFactory());
170171

171172
$reflectionProperty = $class->getProperty('errorRenderers');
172-
$reflectionProperty->setAccessible(true);
173+
$this->setAccessible($reflectionProperty);
173174
$reflectionProperty->setValue($handler, $errorRenderers);
174175

175176
$method = $class->getMethod('determineContentType');
176-
$method->setAccessible(true);
177+
$this->setAccessible($method);
177178

178179
$contentType = $method->invoke($handler, $request);
179180

@@ -196,15 +197,15 @@ public function testDetermineContentTypeApplicationJsonOrXml()
196197
$class = new ReflectionClass(ErrorHandler::class);
197198

198199
$reflectionProperty = $class->getProperty('responseFactory');
199-
$reflectionProperty->setAccessible(true);
200+
$this->setAccessible($reflectionProperty);
200201
$reflectionProperty->setValue($handler, $this->getResponseFactory());
201202

202203
$reflectionProperty = $class->getProperty('errorRenderers');
203-
$reflectionProperty->setAccessible(true);
204+
$this->setAccessible($reflectionProperty);
204205
$reflectionProperty->setValue($handler, $errorRenderers);
205206

206207
$method = $class->getMethod('determineContentType');
207-
$method->setAccessible(true);
208+
$this->setAccessible($method);
208209

209210
$contentType = $method->invoke($handler, $request);
210211

@@ -224,7 +225,7 @@ public function testAcceptableMediaTypeIsNotFirstInList()
224225
// provide access to the determineContentType() as it's a protected method
225226
$class = new ReflectionClass(ErrorHandler::class);
226227
$method = $class->getMethod('determineContentType');
227-
$method->setAccessible(true);
228+
$this->setAccessible($method);
228229

229230
// use a mock object here as ErrorHandler cannot be directly instantiated
230231
$handler = $this->createMock(ErrorHandler::class);
@@ -242,7 +243,7 @@ public function testRegisterErrorRenderer()
242243

243244
$reflectionClass = new ReflectionClass(ErrorHandler::class);
244245
$reflectionProperty = $reflectionClass->getProperty('errorRenderers');
245-
$reflectionProperty->setAccessible(true);
246+
$this->setAccessible($reflectionProperty);
246247
$errorRenderers = $reflectionProperty->getValue($handler);
247248

248249
$this->assertArrayHasKey('application/slim', $errorRenderers);
@@ -255,11 +256,11 @@ public function testSetDefaultErrorRenderer()
255256

256257
$reflectionClass = new ReflectionClass(ErrorHandler::class);
257258
$reflectionProperty = $reflectionClass->getProperty('defaultErrorRenderer');
258-
$reflectionProperty->setAccessible(true);
259+
$this->setAccessible($reflectionProperty);
259260
$defaultErrorRenderer = $reflectionProperty->getValue($handler);
260261

261262
$defaultErrorRendererContentTypeProperty = $reflectionClass->getProperty('defaultErrorRendererContentType');
262-
$defaultErrorRendererContentTypeProperty->setAccessible(true);
263+
$this->setAccessible($defaultErrorRendererContentTypeProperty);
263264
$defaultErrorRendererContentType = $defaultErrorRendererContentTypeProperty->getValue($handler);
264265

265266
$this->assertSame(PlainTextErrorRenderer::class, $defaultErrorRenderer);
@@ -392,20 +393,29 @@ public function testLogErrorRenderer()
392393
->willReturn($renderer)
393394
->shouldBeCalledOnce();
394395

395-
$handler = new ErrorHandler($callableResolverProphecy->reveal(), $this->getResponseFactory());
396+
$loggerProphecy = $this->prophesize(LoggerInterface::class);
397+
$loggerProphecy
398+
->error(Argument::type('string'))
399+
->shouldBeCalled();
400+
401+
$handler = new ErrorHandler(
402+
$callableResolverProphecy->reveal(),
403+
$this->getResponseFactory(),
404+
$loggerProphecy->reveal()
405+
);
396406
$handler->setLogErrorRenderer('logErrorRenderer');
397407

398408
$displayErrorDetailsProperty = new ReflectionProperty($handler, 'displayErrorDetails');
399-
$displayErrorDetailsProperty->setAccessible(true);
409+
$this->setAccessible($displayErrorDetailsProperty);
400410
$displayErrorDetailsProperty->setValue($handler, true);
401411

402412
$exception = new RuntimeException();
403413
$exceptionProperty = new ReflectionProperty($handler, 'exception');
404-
$exceptionProperty->setAccessible(true);
414+
$this->setAccessible($exceptionProperty);
405415
$exceptionProperty->setValue($handler, $exception);
406416

407417
$writeToErrorLogMethod = new ReflectionMethod($handler, 'writeToErrorLog');
408-
$writeToErrorLogMethod->setAccessible(true);
418+
$this->setAccessible($writeToErrorLogMethod);
409419
$writeToErrorLogMethod->invoke($handler);
410420
}
411421
}

tests/Middleware/OutputBufferingMiddlewareTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testStyleDefaultValid()
2626
$middleware = new OutputBufferingMiddleware($this->getStreamFactory());
2727

2828
$reflectionProperty = new ReflectionProperty($middleware, 'style');
29-
$reflectionProperty->setAccessible(true);
29+
$this->setAccessible($reflectionProperty);
3030
$value = $reflectionProperty->getValue($middleware);
3131

3232
$this->assertSame('append', $value);
@@ -37,7 +37,7 @@ public function testStyleCustomValid()
3737
$middleware = new OutputBufferingMiddleware($this->getStreamFactory(), 'prepend');
3838

3939
$reflectionProperty = new ReflectionProperty($middleware, 'style');
40-
$reflectionProperty->setAccessible(true);
40+
$this->setAccessible($reflectionProperty);
4141
$value = $reflectionProperty->getValue($middleware);
4242

4343
$this->assertSame('prepend', $value);

tests/ResponseEmitterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function testWillHandleInvalidConnectionStatusWithAnIndeterminateBody():
280280

281281
$mirror = new ReflectionClass(ResponseEmitter::class);
282282
$emitBodyMethod = $mirror->getMethod('emitBody');
283-
$emitBodyMethod->setAccessible(true);
283+
$this->setAccessible($emitBodyMethod);
284284
$emitBodyMethod->invoke($responseEmitter, $response);
285285

286286
$this->expectOutputString("");

tests/Routing/DispatcherTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testCreateDispatcher()
3434
$dispatcher = new Dispatcher($routeCollector);
3535

3636
$method = new ReflectionMethod(Dispatcher::class, 'createDispatcher');
37-
$method->setAccessible(true);
37+
$this->setAccessible($method);
3838

3939
$this->assertInstanceOf(FastRouteDispatcher::class, $method->invoke($dispatcher));
4040
}
@@ -57,7 +57,7 @@ public function testRouteCacheFileCanBeDispatched()
5757
$routeCollector->setCacheFile($cacheFile);
5858

5959
$method = new ReflectionMethod(Dispatcher::class, 'createDispatcher');
60-
$method->setAccessible(true);
60+
$this->setAccessible($method);
6161
$method->invoke($dispatcher);
6262
$this->assertFileExists($cacheFile, 'cache file was not created');
6363

@@ -66,7 +66,7 @@ public function testRouteCacheFileCanBeDispatched()
6666
$dispatcher2 = new Dispatcher($routeCollector2);
6767

6868
$method = new ReflectionMethod(Dispatcher::class, 'createDispatcher');
69-
$method->setAccessible(true);
69+
$this->setAccessible($method);
7070
$method->invoke($dispatcher2);
7171

7272
/** @var RoutingResults $result */
@@ -88,7 +88,7 @@ public function testCreateDispatcherReturnsSameDispatcherASecondTime()
8888
$dispatcher = new Dispatcher($routeCollector);
8989

9090
$method = new ReflectionMethod(Dispatcher::class, 'createDispatcher');
91-
$method->setAccessible(true);
91+
$this->setAccessible($method);
9292

9393
$fastRouteDispatcher = $method->invoke($dispatcher);
9494
$fastRouteDispatcher2 = $method->invoke($dispatcher);

0 commit comments

Comments
 (0)