[ SlimServerRequestFactory::class, 'Slim PSR-7', ], 'guzzlehttp/psr7' => [ GuzzleHttpFactory::class, 'Guzzle PSR-7', ], 'nyholm/psr7' => [ NyholmPsr17Factory::class, 'Nyholm PSR-7', ], 'laminas/laminas-diactoros' => [ LaminasServerRequestFactory::class, 'Laminas diactoros PSR-7', ], ]; public function dataProviderPsr7Implementations(): array { return self::IMPLEMENTATION_CLASSES; } /** * @phpstan-param class-string $className */ private function testOrSkip(string $className, string $humanName): void { if (! class_exists($className)) { $this->markTestSkipped($humanName . ' is missing'); } foreach (self::IMPLEMENTATION_CLASSES as $libName => $details) { /** @phpstan-var class-string */ $classImpl = $details[0]; if ($classImpl === $className) { continue; } if (! class_exists($classImpl)) { continue; } $this->markTestSkipped($libName . ' exists and will conflict with the test results'); } } /** * @phpstan-param class-string $className * * @dataProvider dataProviderPsr7Implementations */ public function testPsr7Implementation(string $className, string $humanName): void { $this->testOrSkip($className, $humanName); $_GET['foo'] = 'bar'; $_SERVER['QUERY_STRING'] = 'foo=bar&blob=baz'; $_SERVER['REQUEST_URI'] = '/test-page.php'; $_SERVER['REQUEST_METHOD'] = 'PATCH'; $_SERVER['HTTP_HOST'] = 'phpmyadmin.local'; $request = ServerRequestFactory::createFromGlobals(); $this->assertSame( 'PATCH', $request->getMethod() ); $this->assertSame( 'http://phpmyadmin.local/test-page.php?foo=bar&blob=baz', $request->getUri()->__toString() ); $this->assertFalse( $request->isPost() ); $this->assertSame( 'default', $request->getParam('not-exists', 'default') ); $this->assertSame( 'bar', $request->getParam('foo') ); $this->assertSame( 'baz', $request->getParam('blob') ); $this->assertSame([ 'foo' => 'bar', 'blob' => 'baz', ], $request->getQueryParams()); } /** * @phpstan-param class-string $className * * @dataProvider dataProviderPsr7Implementations */ public function testPsr7ImplementationCreateServerRequestFactory(string $className, string $humanName): void { $this->testOrSkip($className, $humanName); $serverRequestFactory = new $className(); $this->assertInstanceOf(ServerRequestFactoryInterface::class, $serverRequestFactory); $factory = new ServerRequestFactory( $serverRequestFactory ); $this->assertInstanceOf(ServerRequestFactory::class, $factory); } }