Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
include:
- php: 8.2
analysis: true
- php: 8.5
experimental: true
composer-options: '--ignore-platform-req=php+'
- php: nightly
experimental: true
composer-options: '--ignore-platform-req=php+'
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"wiki": "https://github.com/slimphp/Slim/wiki"
},
"require": {
"php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
"php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
"ext-json": "*",
"nikic/fast-route": "^1.3",
"psr/container": "^1.0 || ^2.0",
Expand Down
18 changes: 9 additions & 9 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,18 +703,18 @@ public function testAddRoutingMiddleware(): void

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

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

$reflection = new ReflectionClass($tip);
$middlewareProperty = $reflection->getProperty('middleware');
$middlewareProperty->setAccessible(true);
$this->setAccessible($middlewareProperty);

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

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

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

$reflection = new ReflectionClass($tip);
$middlewareProperty = $reflection->getProperty('middleware');
$middlewareProperty->setAccessible(true);
$this->setAccessible($middlewareProperty);

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

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

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

$reflection = new ReflectionClass($tip);
$middlewareProperty = $reflection->getProperty('middleware');
$middlewareProperty->setAccessible(true);
$this->setAccessible($middlewareProperty);

$this->assertSame($bodyParsingMiddleware, $middlewareProperty->getValue($tip));
$this->assertInstanceOf(BodyParsingMiddleware::class, $bodyParsingMiddleware);
Expand Down
8 changes: 4 additions & 4 deletions tests/Error/AbstractErrorRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testHTMLErrorRendererRenderFragmentMethod()
$reflectionRenderer = new ReflectionClass(HtmlErrorRenderer::class);

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

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

$method = $reflectionRenderer->getMethod('formatExceptionFragment');
$method->setAccessible(true);
$this->setAccessible($method);

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

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

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

$method = $reflectionRenderer->getMethod('formatExceptionFragment');
$method->setAccessible(true);
$this->setAccessible($method);
$output = $method->invoke($renderer, $exception);
$this->assertIsString($output);

Expand Down
4 changes: 2 additions & 2 deletions tests/Factory/AppFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testCreateAppWithAllImplementations(string $psr17factory, string
$routeCollector = $app->getRouteCollector();

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

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

Expand Down Expand Up @@ -281,7 +281,7 @@ public function testResponseAndStreamFactoryIsBeingInjectedInDecoratedResponseFa
$response = $responseFactory->createResponse();

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

$this->assertSame($streamFactoryProphecy->reveal(), $streamFactoryProperty->getValue($response));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Factory/Psr17/SlimHttpServerRequestCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function tearDown(): void
SlimHttpServerRequestCreator::class,
'serverRequestDecoratorClass'
);
$serverRequestDecoratorClassProperty->setAccessible(true);
$this->setAccessible($serverRequestDecoratorClassProperty);
$serverRequestDecoratorClassProperty->setValue($slimHttpServerRequestCreator, ServerRequest::class);
}

Expand Down Expand Up @@ -69,7 +69,7 @@ public function testCreateServerRequestFromGlobalsThrowsRuntimeException()
SlimHttpServerRequestCreator::class,
'serverRequestDecoratorClass'
);
$serverRequestDecoratorClassProperty->setAccessible(true);
$this->setAccessible($serverRequestDecoratorClassProperty);
$serverRequestDecoratorClassProperty->setValue($slimHttpServerRequestCreator, '');

$slimHttpServerRequestCreator->createServerRequestFromGlobals();
Expand Down
56 changes: 33 additions & 23 deletions tests/Handlers/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Slim\Tests\Handlers;

use Prophecy\Argument;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use ReflectionClass;
Expand Down Expand Up @@ -40,15 +41,15 @@ public function testDetermineRenderer()
$class = new ReflectionClass(ErrorHandler::class);

$callableResolverProperty = $class->getProperty('callableResolver');
$callableResolverProperty->setAccessible(true);
$this->setAccessible($callableResolverProperty);
$callableResolverProperty->setValue($handler, $this->getCallableResolver());

$reflectionProperty = $class->getProperty('contentType');
$reflectionProperty->setAccessible(true);
$this->setAccessible($reflectionProperty);
$reflectionProperty->setValue($handler, 'application/json');

$method = $class->getMethod('determineRenderer');
$method->setAccessible(true);
$this->setAccessible($method);

$renderer = $method->invoke($handler);
$this->assertIsCallable($renderer);
Expand Down Expand Up @@ -78,15 +79,15 @@ public function testDetermineStatusCode()
$class = new ReflectionClass(ErrorHandler::class);

$reflectionProperty = $class->getProperty('responseFactory');
$reflectionProperty->setAccessible(true);
$this->setAccessible($reflectionProperty);
$reflectionProperty->setValue($handler, $this->getResponseFactory());

$reflectionProperty = $class->getProperty('exception');
$reflectionProperty->setAccessible(true);
$this->setAccessible($reflectionProperty);
$reflectionProperty->setValue($handler, new HttpNotFoundException($request));

$method = $class->getMethod('determineStatusCode');
$method->setAccessible(true);
$this->setAccessible($method);

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

$reflectionProperty = $class->getProperty('responseFactory');
$reflectionProperty->setAccessible(true);
$this->setAccessible($reflectionProperty);
$reflectionProperty->setValue($handler, $this->getResponseFactory());

$reflectionProperty = $class->getProperty('errorRenderers');
$reflectionProperty->setAccessible(true);
$this->setAccessible($reflectionProperty);
$reflectionProperty->setValue($handler, $newErrorRenderers);

$method = $class->getMethod('determineContentType');
$method->setAccessible(true);
$this->setAccessible($method);

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

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

$reflectionProperty = $class->getProperty('responseFactory');
$reflectionProperty->setAccessible(true);
$this->setAccessible($reflectionProperty);
$reflectionProperty->setValue($handler, $this->getResponseFactory());

$reflectionProperty = $class->getProperty('errorRenderers');
$reflectionProperty->setAccessible(true);
$this->setAccessible($reflectionProperty);
$reflectionProperty->setValue($handler, $errorRenderers);

$method = $class->getMethod('determineContentType');
$method->setAccessible(true);
$this->setAccessible($method);

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

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

$reflectionProperty = $class->getProperty('responseFactory');
$reflectionProperty->setAccessible(true);
$this->setAccessible($reflectionProperty);
$reflectionProperty->setValue($handler, $this->getResponseFactory());

$reflectionProperty = $class->getProperty('errorRenderers');
$reflectionProperty->setAccessible(true);
$this->setAccessible($reflectionProperty);
$reflectionProperty->setValue($handler, $errorRenderers);

$method = $class->getMethod('determineContentType');
$method->setAccessible(true);
$this->setAccessible($method);

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

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

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

$reflectionClass = new ReflectionClass(ErrorHandler::class);
$reflectionProperty = $reflectionClass->getProperty('errorRenderers');
$reflectionProperty->setAccessible(true);
$this->setAccessible($reflectionProperty);
$errorRenderers = $reflectionProperty->getValue($handler);

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

$reflectionClass = new ReflectionClass(ErrorHandler::class);
$reflectionProperty = $reflectionClass->getProperty('defaultErrorRenderer');
$reflectionProperty->setAccessible(true);
$this->setAccessible($reflectionProperty);
$defaultErrorRenderer = $reflectionProperty->getValue($handler);

$defaultErrorRendererContentTypeProperty = $reflectionClass->getProperty('defaultErrorRendererContentType');
$defaultErrorRendererContentTypeProperty->setAccessible(true);
$this->setAccessible($defaultErrorRendererContentTypeProperty);
$defaultErrorRendererContentType = $defaultErrorRendererContentTypeProperty->getValue($handler);

$this->assertSame(PlainTextErrorRenderer::class, $defaultErrorRenderer);
Expand Down Expand Up @@ -392,20 +393,29 @@ public function testLogErrorRenderer()
->willReturn($renderer)
->shouldBeCalledOnce();

$handler = new ErrorHandler($callableResolverProphecy->reveal(), $this->getResponseFactory());
$loggerProphecy = $this->prophesize(LoggerInterface::class);
$loggerProphecy
->error(Argument::type('string'))
->shouldBeCalled();

$handler = new ErrorHandler(
$callableResolverProphecy->reveal(),
$this->getResponseFactory(),
$loggerProphecy->reveal()
);
$handler->setLogErrorRenderer('logErrorRenderer');

$displayErrorDetailsProperty = new ReflectionProperty($handler, 'displayErrorDetails');
$displayErrorDetailsProperty->setAccessible(true);
$this->setAccessible($displayErrorDetailsProperty);
$displayErrorDetailsProperty->setValue($handler, true);

$exception = new RuntimeException();
$exceptionProperty = new ReflectionProperty($handler, 'exception');
$exceptionProperty->setAccessible(true);
$this->setAccessible($exceptionProperty);
$exceptionProperty->setValue($handler, $exception);

$writeToErrorLogMethod = new ReflectionMethod($handler, 'writeToErrorLog');
$writeToErrorLogMethod->setAccessible(true);
$this->setAccessible($writeToErrorLogMethod);
$writeToErrorLogMethod->invoke($handler);
}
}
4 changes: 2 additions & 2 deletions tests/Middleware/OutputBufferingMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testStyleDefaultValid()
$middleware = new OutputBufferingMiddleware($this->getStreamFactory());

$reflectionProperty = new ReflectionProperty($middleware, 'style');
$reflectionProperty->setAccessible(true);
$this->setAccessible($reflectionProperty);
$value = $reflectionProperty->getValue($middleware);

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

$reflectionProperty = new ReflectionProperty($middleware, 'style');
$reflectionProperty->setAccessible(true);
$this->setAccessible($reflectionProperty);
$value = $reflectionProperty->getValue($middleware);

$this->assertSame('prepend', $value);
Expand Down
2 changes: 1 addition & 1 deletion tests/ResponseEmitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function testWillHandleInvalidConnectionStatusWithAnIndeterminateBody():

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

$this->expectOutputString("");
Expand Down
8 changes: 4 additions & 4 deletions tests/Routing/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testCreateDispatcher()
$dispatcher = new Dispatcher($routeCollector);

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

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

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

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

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

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

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

$fastRouteDispatcher = $method->invoke($dispatcher);
$fastRouteDispatcher2 = $method->invoke($dispatcher);
Expand Down
Loading