Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests and add PHP 8.3 to the CI matrix #3299

Merged
merged 6 commits into from
Dec 14, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 5 additions & 12 deletions tests/Factory/AppFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 3 additions & 6 deletions tests/Factory/Psr17/SlimHttpServerRequestCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 0 additions & 4 deletions tests/Handlers/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions tests/Middleware/BodyParsingMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}
};
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down