1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
<?php
namespace Interop\Http\Factory;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
abstract class ResponseFactoryTestCase extends TestCase
{
/**
* @var ResponseFactoryInterface
*/
protected $factory;
/**
* @return ResponseFactoryInterface
*/
abstract protected function createResponseFactory();
public function setUp(): void
{
$this->factory = $this->createResponseFactory();
}
protected function assertResponse($response, $code)
{
static::assertInstanceOf(ResponseInterface::class, $response);
static::assertSame($code, $response->getStatusCode());
}
public static function dataCodes()
{
return [
'HTTP/200' => [200],
'HTTP/301' => [301],
'HTTP/404' => [404],
'HTTP/500' => [500],
];
}
#[DataProvider('dataCodes')]
public function testCreateResponse($code)
{
$response = $this->factory->createResponse($code);
$this->assertResponse($response, $code);
}
}
|