From 5f0aeb3bb1f52f92ceaf42b9890ecef65ae86019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20S=C5=82owik?= Date: Fri, 6 Nov 2020 13:19:09 +0100 Subject: [PATCH 1/2] Fix the setServerRequestCreator test The test assumes that createServerRequestFromGlobals must always return a request object created by the previously set creator. But this is only true if automatic request object decoration is disabled. --- tests/Factory/ServerRequestCreatorFactoryTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Factory/ServerRequestCreatorFactoryTest.php b/tests/Factory/ServerRequestCreatorFactoryTest.php index f6c4a6996..cb6bddc26 100644 --- a/tests/Factory/ServerRequestCreatorFactoryTest.php +++ b/tests/Factory/ServerRequestCreatorFactoryTest.php @@ -90,8 +90,9 @@ public function testSetPsr17FactoryProvider() $this->assertInstanceOf(SlimServerRequest::class, $serverRequestCreator->createServerRequestFromGlobals()); } - public function testSetServerRequestCreator() + public function testSetServerRequestCreatorWithoutDecorators() { + ServerRequestCreatorFactory::setSlimHttpDecoratorsAutomaticDetection(false); $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class); $serverRequestCreatorProphecy = $this->prophesize(ServerRequestCreatorInterface::class); From c69917c9eb6c923167f97c72125de947f1c984f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20S=C5=82owik?= Date: Fri, 6 Nov 2020 16:34:58 +0100 Subject: [PATCH 2/2] Add a test for setServerRequestCreator with automatic decoration enabled --- .../ServerRequestCreatorFactoryTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/Factory/ServerRequestCreatorFactoryTest.php b/tests/Factory/ServerRequestCreatorFactoryTest.php index cb6bddc26..a4c196169 100644 --- a/tests/Factory/ServerRequestCreatorFactoryTest.php +++ b/tests/Factory/ServerRequestCreatorFactoryTest.php @@ -107,4 +107,22 @@ public function testSetServerRequestCreatorWithoutDecorators() $this->assertSame($serverRequestProphecy->reveal(), $serverRequestCreator->createServerRequestFromGlobals()); } + + public function testSetServerRequestCreatorWithDecorators() + { + ServerRequestCreatorFactory::setSlimHttpDecoratorsAutomaticDetection(true); + $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class); + + $serverRequestCreatorProphecy = $this->prophesize(ServerRequestCreatorInterface::class); + $serverRequestCreatorProphecy + ->createServerRequestFromGlobals() + ->willReturn($serverRequestProphecy->reveal()) + ->shouldBeCalledOnce(); + + ServerRequestCreatorFactory::setServerRequestCreator($serverRequestCreatorProphecy->reveal()); + + $serverRequestCreator = ServerRequestCreatorFactory::create(); + + $this->assertInstanceOf(ServerRequest::class, $serverRequestCreator->createServerRequestFromGlobals()); + } }