diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 86f06735c..4a2f660be 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,10 +10,10 @@ jobs: strategy: fail-fast: false matrix: - php: [7.4, 8.0, 8.1, 8.2] + php: [7.4, 8.0, 8.1, 8.2, 8.3] experimental: [false] include: - - php: 8.1 + - php: 8.2 analysis: true steps: diff --git a/tests/Factory/AppFactoryTest.php b/tests/Factory/AppFactoryTest.php index b802c2dc9..25349ffc8 100644 --- a/tests/Factory/AppFactoryTest.php +++ b/tests/Factory/AppFactoryTest.php @@ -18,6 +18,7 @@ use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamFactoryInterface; +use ReflectionClass; use ReflectionProperty; use RuntimeException; use Slim\Factory\AppFactory; @@ -45,12 +46,8 @@ class AppFactoryTest extends TestCase { protected function tearDown(): void { - $responseFactoryDecoratorClassProperty = new ReflectionProperty( - SlimHttpPsr17Factory::class, - 'responseFactoryClass' - ); - $responseFactoryDecoratorClassProperty->setAccessible(true); - $responseFactoryDecoratorClassProperty->setValue(DecoratedResponseFactory::class); + $reflectionClass = new ReflectionClass(SlimHttpPsr17Factory::class); + $reflectionClass->setStaticPropertyValue('responseFactoryClass', DecoratedResponseFactory::class); } public function provideImplementations() @@ -103,12 +100,8 @@ public function testDetermineResponseFactoryThrowsRuntimeExceptionIfDecoratedNot 'Slim\\Factory\\Psr17\\SlimHttpPsr17Factory could not instantiate a decorated response factory.' ); - $responseFactoryDecoratorClassProperty = new ReflectionProperty( - SlimHttpPsr17Factory::class, - 'responseFactoryClass' - ); - $responseFactoryDecoratorClassProperty->setAccessible(true); - $responseFactoryDecoratorClassProperty->setValue(stdClass::class); + $reflectionClass = new ReflectionClass(SlimHttpPsr17Factory::class); + $reflectionClass->setStaticPropertyValue('responseFactoryClass', SlimHttpPsr17Factory::class); Psr17FactoryProvider::setFactories([SlimPsr17Factory::class]); AppFactory::setSlimHttpDecoratorsAutomaticDetection(true); diff --git a/tests/Factory/Psr17/SlimHttpServerRequestCreatorTest.php b/tests/Factory/Psr17/SlimHttpServerRequestCreatorTest.php index 98c23e0b5..328f4cb4c 100644 --- a/tests/Factory/Psr17/SlimHttpServerRequestCreatorTest.php +++ b/tests/Factory/Psr17/SlimHttpServerRequestCreatorTest.php @@ -11,6 +11,7 @@ namespace Slim\Tests\Factory\Psr17; use Psr\Http\Message\ServerRequestInterface; +use ReflectionClass; use ReflectionProperty; use RuntimeException; use Slim\Factory\Psr17\SlimHttpServerRequestCreator; @@ -91,12 +92,8 @@ public function testCreateServerRequestFromGlobalsThrowsRuntimeExceptionIfNotIns $slimHttpServerRequestCreator = new SlimHttpServerRequestCreator($serverRequestCreatorProphecy->reveal()); - $serverRequestDecoratorClassProperty = new ReflectionProperty( - SlimHttpServerRequestCreator::class, - 'serverRequestDecoratorClass' - ); - $serverRequestDecoratorClassProperty->setAccessible(true); - $serverRequestDecoratorClassProperty->setValue(stdClass::class); + $reflectionClass = new ReflectionClass(SlimHttpServerRequestCreator::class); + $reflectionClass->setStaticPropertyValue('serverRequestDecoratorClass', stdClass::class); $slimHttpServerRequestCreator->createServerRequestFromGlobals(); } diff --git a/tests/Handlers/ErrorHandlerTest.php b/tests/Handlers/ErrorHandlerTest.php index f23acd6b3..9346f1c7e 100644 --- a/tests/Handlers/ErrorHandlerTest.php +++ b/tests/Handlers/ErrorHandlerTest.php @@ -241,10 +241,6 @@ public function testAcceptableMediaTypeIsNotFirstInList() $method = $class->getMethod('determineContentType'); $method->setAccessible(true); - $reflectionProperty = $class->getProperty('responseFactory'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue($class, $this->getResponseFactory()); - // use a mock object here as ErrorHandler cannot be directly instantiated $handler = $this ->getMockBuilder(ErrorHandler::class) diff --git a/tests/Middleware/BodyParsingMiddlewareTest.php b/tests/Middleware/BodyParsingMiddlewareTest.php index 75f0df3c4..30cba022c 100644 --- a/tests/Middleware/BodyParsingMiddlewareTest.php +++ b/tests/Middleware/BodyParsingMiddlewareTest.php @@ -31,6 +31,7 @@ protected function createRequestHandler(): RequestHandlerInterface $response = $this->createResponse(); return new class ($response) implements RequestHandlerInterface { private $response; + public $request; public function __construct(ResponseInterface $response) { @@ -39,7 +40,7 @@ public function __construct(ResponseInterface $response) public function handle(ServerRequestInterface $request): ResponseInterface { - $this->response->request = $request; + $this->request = $request; return $this->response; } }; @@ -152,9 +153,10 @@ public function testParsing($contentType, $body, $expected) $request = $this->createRequestWithBody($contentType, $body); $middleware = new BodyParsingMiddleware(); - $response = $middleware->process($request, $this->createRequestHandler()); + $requestHandler = $this->createRequestHandler(); + $middleware->process($request, $requestHandler); - $this->assertEquals($expected, $response->request->getParsedBody()); + $this->assertEquals($expected, $requestHandler->request->getParsedBody()); } public function testParsingWithARegisteredParser() @@ -167,9 +169,10 @@ public function testParsingWithARegisteredParser() }, ]; $middleware = new BodyParsingMiddleware($parsers); - $response = $middleware->process($request, $this->createRequestHandler()); + $requestHandler = $this->createRequestHandler(); + $middleware->process($request, $requestHandler); - $this->assertSame(['data' => '{"foo":"bar"}'], $response->request->getParsedBody()); + $this->assertSame(['data' => '{"foo":"bar"}'], $requestHandler->request->getParsedBody()); } public function testParsingFailsWhenAnInvalidTypeIsReturned()