Skip to content
Open
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
73 changes: 59 additions & 14 deletions test/RequestFactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,81 @@
<?php
/**
* @author http-factory-tests Contributors
* @license MIT
* @link https://github.com/http-interop/http-factory-tests
*
* @noinspection PhpUndefinedConstantInspection
*/

namespace Interop\Http\Factory;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;
use function class_exists;
use function defined;

final class RequestFactoryTest extends RequestFactoryTestCase
class RequestFactoryTest extends TestCase
{
/**
* {@inheritdoc}
*/
protected function createRequestFactory()

protected RequestFactoryInterface $requestFactory;
protected UriFactoryInterface $uriFactory;

public function setUp(): void
{
$this->requestFactory = $this->createRequestFactory();
$this->uriFactory = $this->createUriFactory();
}

protected function createRequestFactory(): RequestFactoryInterface
{
if (!defined('REQUEST_FACTORY') || !class_exists(REQUEST_FACTORY)) {
self::markTestSkipped('REQUEST_FACTORY class name not provided');
if(!defined('REQUEST_FACTORY') || !class_exists(REQUEST_FACTORY)){
static::markTestSkipped('REQUEST_FACTORY class name not provided');
}

return new (REQUEST_FACTORY);
}

/**
* {@inheritdoc}
*/
protected function createUri($uri)
protected function createUriFactory(): UriFactoryInterface
{
if (!defined('URI_FACTORY') || !class_exists(URI_FACTORY)) {
self::markTestSkipped('URI_FACTORY class name not provided');
if(!defined('URI_FACTORY') || !class_exists(URI_FACTORY)){
static::markTestSkipped('URI_FACTORY class name not provided');
}

return (new (URI_FACTORY))->createUri($uri);
return new (URI_FACTORY);
}

public static function dataMethods(): array
{
return [
'GET' => ['GET'],
'POST' => ['POST'],
'PUT' => ['PUT'],
'DELETE' => ['DELETE'],
'OPTIONS' => ['OPTIONS'],
'HEAD' => ['HEAD'],
];
}

#[DataProvider('dataMethods')]
public function testCreateRequest(string $method): void
{
$uri = 'https://example.com/';
$request = $this->requestFactory->createRequest($method, $uri);

static::assertSame($method, $request->getMethod());
static::assertSame($uri, (string) $request->getUri());
}

public function testCreateRequestWithUri(): void
{
$method = 'GET';
$uri = 'https://example.com/';
$request = $this->requestFactory->createRequest($method, $this->uriFactory->createUri($uri));

static::assertSame($method, $request->getMethod());
static::assertSame($uri, (string) $request->getUri());
}

}
73 changes: 0 additions & 73 deletions test/RequestFactoryTestCase.php

This file was deleted.

45 changes: 38 additions & 7 deletions test/ResponseFactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,55 @@
<?php
/**
* @author http-factory-tests Contributors
* @license MIT
* @link https://github.com/http-interop/http-factory-tests
*
* @noinspection PhpUndefinedConstantInspection
*/

namespace Interop\Http\Factory;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseFactoryInterface;
use function class_exists;
use function defined;

final class ResponseFactoryTest extends ResponseFactoryTestCase
class ResponseFactoryTest extends TestCase
{
/**
* {@inheritdoc}
*/
protected function createResponseFactory()

protected ResponseFactoryInterface $responseFactory;

public function setUp(): void
{
if (!defined('RESPONSE_FACTORY') || !class_exists(RESPONSE_FACTORY)) {
self::markTestSkipped('RESPONSE_FACTORY class name not provided');
$this->responseFactory = $this->createResponseFactory();
}

protected function createResponseFactory(): ResponseFactoryInterface
{
if(!defined('RESPONSE_FACTORY') || !class_exists(RESPONSE_FACTORY)){
static::markTestSkipped('RESPONSE_FACTORY class name not provided');
}

return new (RESPONSE_FACTORY);
}

public static function dataCodes(): array
{
return [
'HTTP/200' => [200],
'HTTP/301' => [301],
'HTTP/404' => [404],
'HTTP/500' => [500],
];
}

#[DataProvider('dataCodes')]
public function testCreateResponse(int $code): void
{
$response = $this->responseFactory->createResponse($code);

static::assertSame($code, $response->getStatusCode());
}

}
50 changes: 0 additions & 50 deletions test/ResponseFactoryTestCase.php

This file was deleted.

Loading