diff --git a/composer.json b/composer.json index 0d4f54a..81dc76e 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "psr/http-server-handler": "^1.0", "psr/log": "^1.1||^3", "ramsey/uuid": "^4.1", - "shrikeh/teapot": "^2.3" + "teapot/status-code": "^1.1" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 33fe41d..ccf823f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7387cdbed2655f11315d053f326ad7ef", + "content-hash": "734c128880f55c480a02853bf875417a", "packages": [ { "name": "brick/math", @@ -386,16 +386,16 @@ }, { "name": "psr/http-message", - "version": "1.1", + "version": "2.0", "source": { "type": "git", "url": "https://github.com/php-fig/http-message.git", - "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba" + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/cb6ce4845ce34a8ad9e68117c10ee90a29919eba", - "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", "shasum": "" }, "require": { @@ -404,7 +404,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -419,7 +419,7 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "homepage": "https://www.php-fig.org/" } ], "description": "Common interface for HTTP messages", @@ -433,9 +433,9 @@ "response" ], "support": { - "source": "https://github.com/php-fig/http-message/tree/1.1" + "source": "https://github.com/php-fig/http-message/tree/2.0" }, - "time": "2023-04-04T09:50:52+00:00" + "time": "2023-04-04T09:54:51+00:00" }, { "name": "psr/http-server-handler", @@ -724,63 +724,6 @@ ], "time": "2023-11-08T05:53:05+00:00" }, - { - "name": "shrikeh/teapot", - "version": "v2.3.1", - "source": { - "type": "git", - "url": "https://github.com/shrikeh/teapot.git", - "reference": "2fea5720963f22eedb920ee65b9d643bfa3e8daf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/shrikeh/teapot/zipball/2fea5720963f22eedb920ee65b9d643bfa3e8daf", - "reference": "2fea5720963f22eedb920ee65b9d643bfa3e8daf", - "shasum": "" - }, - "require": { - "php": ">=5.5", - "psr/http-message": "^1.0", - "teapot/status-code": "^1.0" - }, - "require-dev": { - "behat/behat": "^3.2", - "bossa/phpspec2-expect": "^2.0", - "escapestudios/symfony2-coding-standard": "^2.9", - "phpspec/phpspec": "~3.0.0", - "squizlabs/php_codesniffer": "^2.7" - }, - "type": "library", - "autoload": { - "psr-4": { - "Teapot\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Barney Hanlon", - "email": "barney@shrikeh.net" - }, - { - "name": "Andreas Möller", - "email": "am@localheinz.com" - } - ], - "description": "PHP HTTP Response Status library", - "homepage": "https://shrikeh.github.io/teapot/", - "keywords": [ - "http" - ], - "support": { - "issues": "https://github.com/shrikeh/teapot/issues", - "source": "https://github.com/shrikeh/teapot/tree/master" - }, - "time": "2017-09-01T13:56:48+00:00" - }, { "name": "teapot/status-code", "version": "v1.1.2", diff --git a/src/Dispatch/MethodDispatcher.php b/src/Dispatch/MethodDispatcher.php index 12b0eda..e327fbe 100644 --- a/src/Dispatch/MethodDispatcher.php +++ b/src/Dispatch/MethodDispatcher.php @@ -7,7 +7,7 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Log\LoggerInterface; use stdClass; -use Teapot\StatusCode; +use Teapot\StatusCode\Http; use Usox\JsonSchemaApi\Contract\ApiMethodInterface; use Usox\JsonSchemaApi\Contract\MethodProviderInterface; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaInvalidException; @@ -65,7 +65,7 @@ public function dispatch( if (!$handler instanceof ApiMethodInterface) { throw new MethodNotFoundException( 'Method not found', - StatusCode::BAD_REQUEST + Http::BAD_REQUEST ); } diff --git a/src/Dispatch/MethodValidator.php b/src/Dispatch/MethodValidator.php index d4fca20..4c1fe31 100644 --- a/src/Dispatch/MethodValidator.php +++ b/src/Dispatch/MethodValidator.php @@ -8,7 +8,7 @@ use Opis\JsonSchema\Helper; use Opis\JsonSchema\Validator; use stdClass; -use Teapot\StatusCode; +use Teapot\StatusCode\Http; use Usox\JsonSchemaApi\Exception\RequestMalformedException; use Usox\JsonSchemaApi\Exception\ResponseMalformedException; @@ -40,7 +40,7 @@ public function validateInput( if (!$validationResult->isValid()) { throw new RequestMalformedException( 'Bad Request', - StatusCode::BAD_REQUEST + Http::BAD_REQUEST ); } } @@ -78,7 +78,7 @@ public function validateOutput( if ($error !== null) { throw new ResponseMalformedException( 'Internal Server Error', - StatusCode::INTERNAL_SERVER_ERROR, + Http::INTERNAL_SERVER_ERROR, null, $this->errorFormatter->format($error) ); diff --git a/src/Dispatch/RequestValidator.php b/src/Dispatch/RequestValidator.php index 9829189..edd6ebc 100644 --- a/src/Dispatch/RequestValidator.php +++ b/src/Dispatch/RequestValidator.php @@ -4,13 +4,13 @@ namespace Usox\JsonSchemaApi\Dispatch; +use Teapot\StatusCode\Http; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaInvalidException; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotFoundException; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotLoadableException; use Opis\JsonSchema\Validator; use Psr\Http\Message\ServerRequestInterface; use stdClass; -use Teapot\StatusCode; use Usox\JsonSchemaApi\Dispatch\Exception\JsonInvalidException; use Usox\JsonSchemaApi\Exception\RequestMalformedException; @@ -40,7 +40,7 @@ public function validate(ServerRequestInterface $request): stdClass if (json_last_error() !== JSON_ERROR_NONE) { throw new JsonInvalidException( sprintf('Input is no valid json (%s)', json_last_error_msg()), - StatusCode::BAD_REQUEST + Http::BAD_REQUEST ); } @@ -57,7 +57,7 @@ public function validate(ServerRequestInterface $request): stdClass if (!$validationResult->isValid()) { throw new RequestMalformedException( 'Request is invalid', - StatusCode::BAD_REQUEST + Http::BAD_REQUEST ); } diff --git a/src/Dispatch/SchemaLoader.php b/src/Dispatch/SchemaLoader.php index 5b00c61..84b5f7c 100644 --- a/src/Dispatch/SchemaLoader.php +++ b/src/Dispatch/SchemaLoader.php @@ -4,10 +4,10 @@ namespace Usox\JsonSchemaApi\Dispatch; +use Teapot\StatusCode\Http; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotFoundException; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotLoadableException; use stdClass; -use Teapot\StatusCode; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaInvalidException; /** @@ -28,7 +28,7 @@ public function load( if (!file_exists($schemaFilePath)) { throw new SchemaNotFoundException( sprintf('Schema file `%s` not found', $schemaFilePath), - StatusCode::INTERNAL_SERVER_ERROR + Http::INTERNAL_SERVER_ERROR ); } @@ -37,7 +37,7 @@ public function load( if ($fileContent === false) { throw new SchemaNotLoadableException( sprintf('Schema file `%s` not loadable', $schemaFilePath), - StatusCode::INTERNAL_SERVER_ERROR + Http::INTERNAL_SERVER_ERROR ); } @@ -47,7 +47,7 @@ public function load( if (json_last_error() !== JSON_ERROR_NONE) { throw new SchemaInvalidException( sprintf('Schema does not contain valid json (%s)', json_last_error_msg()), - StatusCode::INTERNAL_SERVER_ERROR + Http::INTERNAL_SERVER_ERROR ); } diff --git a/src/Endpoint.php b/src/Endpoint.php index 8c75544..e25efbb 100644 --- a/src/Endpoint.php +++ b/src/Endpoint.php @@ -15,7 +15,7 @@ use Ramsey\Uuid\UuidFactory; use Ramsey\Uuid\UuidFactoryInterface; use Ramsey\Uuid\UuidInterface; -use Teapot\StatusCode; +use Teapot\StatusCode\Http; use Throwable; use Usox\JsonSchemaApi\Contract\MethodProviderInterface; use Usox\JsonSchemaApi\Dispatch\MethodDispatcher; @@ -52,7 +52,7 @@ public function __construct( public function serve( ServerRequestInterface $request, ): ResponseInterface { - $statusCode = StatusCode::OK; + $statusCode = Http::OK; $responseData = null; try { @@ -71,7 +71,7 @@ public function serve( // Build an error response $responseData = $this->responseBuilder->buildErrorResponse($e, $uuid); - $statusCode = StatusCode::BAD_REQUEST; + $statusCode = Http::BAD_REQUEST; } catch (InternalException $e) { $this->logError( $e, @@ -79,14 +79,14 @@ public function serve( $e->getContext() ); - $statusCode = StatusCode::INTERNAL_SERVER_ERROR; + $statusCode = Http::INTERNAL_SERVER_ERROR; } catch (Throwable $e) { $this->logError( $e, $this->uuidFactory->uuid4() ); - $statusCode = StatusCode::INTERNAL_SERVER_ERROR; + $statusCode = Http::INTERNAL_SERVER_ERROR; } $response = $this->responseFactory->createResponse($statusCode); diff --git a/tests/Dispatch/MethodDispatcherTest.php b/tests/Dispatch/MethodDispatcherTest.php index 16cb0d9..6a8ebdd 100644 --- a/tests/Dispatch/MethodDispatcherTest.php +++ b/tests/Dispatch/MethodDispatcherTest.php @@ -9,7 +9,7 @@ use Mockery\MockInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Log\LoggerInterface; -use Teapot\StatusCode; +use Teapot\StatusCode\Http; use Usox\JsonSchemaApi\Contract\ApiMethodInterface; use Usox\JsonSchemaApi\Contract\MethodProviderInterface; use Usox\JsonSchemaApi\Exception\MethodNotFoundException; @@ -50,7 +50,7 @@ public function testDispatchThrowsExceptionIfMethodDoesNotExist(): void $this->expectException(MethodNotFoundException::class); $this->expectExceptionMessage('Method not found'); - $this->expectExceptionCode(StatusCode::BAD_REQUEST); + $this->expectExceptionCode(Http::BAD_REQUEST); $method = 'some-method'; $parameter = (object) ['some-parameter']; diff --git a/tests/Dispatch/MethodValidatorTest.php b/tests/Dispatch/MethodValidatorTest.php index 58dbfa9..201f00b 100644 --- a/tests/Dispatch/MethodValidatorTest.php +++ b/tests/Dispatch/MethodValidatorTest.php @@ -11,7 +11,7 @@ use Opis\JsonSchema\Errors\ValidationError; use Opis\JsonSchema\ValidationResult; use Opis\JsonSchema\Validator; -use Teapot\StatusCode; +use Teapot\StatusCode\Http; use Usox\JsonSchemaApi\Exception\RequestMalformedException; use Usox\JsonSchemaApi\Exception\ResponseMalformedException; @@ -46,7 +46,7 @@ public function testValidateInputThrowsExceptionIfInputDoesNotValidate(): void $this->expectException(RequestMalformedException::class); $this->expectExceptionMessage('Bad Request'); - $this->expectExceptionCode(StatusCode::BAD_REQUEST); + $this->expectExceptionCode(Http::BAD_REQUEST); $this->schemaValidator->shouldReceive('validate') ->with( @@ -111,7 +111,7 @@ public function testValidateOutputThrowsExceptionIfOutputDoesNotValidate(): void $this->expectException(ResponseMalformedException::class); $this->expectExceptionMessage('Internal Server Error'); - $this->expectExceptionCode(StatusCode::INTERNAL_SERVER_ERROR); + $this->expectExceptionCode(Http::INTERNAL_SERVER_ERROR); $this->schemaValidator->shouldReceive('validate') ->with( diff --git a/tests/Dispatch/RequestValidatorTest.php b/tests/Dispatch/RequestValidatorTest.php index 8215895..4bb9c25 100644 --- a/tests/Dispatch/RequestValidatorTest.php +++ b/tests/Dispatch/RequestValidatorTest.php @@ -11,7 +11,7 @@ use Opis\JsonSchema\Validator; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamInterface; -use Teapot\StatusCode; +use Teapot\StatusCode\Http; use Usox\JsonSchemaApi\Dispatch\Exception\JsonInvalidException; use Usox\JsonSchemaApi\Exception\RequestMalformedException; @@ -40,7 +40,7 @@ public function testValidateThrowsExceptionIfInputIsInvalid(): void { $this->expectException(JsonInvalidException::class); $this->expectExceptionMessage('Input is no valid json (Syntax error)'); - $this->expectExceptionCode(StatusCode::BAD_REQUEST); + $this->expectExceptionCode(Http::BAD_REQUEST); $stream = Mockery::mock(StreamInterface::class); $request = Mockery::mock(ServerRequestInterface::class); @@ -64,7 +64,7 @@ public function testValidateThrowsExceptionIfInputDoesNotValidate(): void { $this->expectException(RequestMalformedException::class); $this->expectExceptionMessage('Request is invalid'); - $this->expectExceptionCode(StatusCode::BAD_REQUEST); + $this->expectExceptionCode(Http::BAD_REQUEST); $stream = Mockery::mock(StreamInterface::class); $request = Mockery::mock(ServerRequestInterface::class); diff --git a/tests/Dispatch/SchemaLoaderTest.php b/tests/Dispatch/SchemaLoaderTest.php index cb6ab58..a4e16b8 100644 --- a/tests/Dispatch/SchemaLoaderTest.php +++ b/tests/Dispatch/SchemaLoaderTest.php @@ -6,7 +6,7 @@ use Mockery\Adapter\Phpunit\MockeryTestCase; use org\bovigo\vfs\vfsStream; -use Teapot\StatusCode; +use Teapot\StatusCode\Http; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaInvalidException; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotFoundException; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotLoadableException; @@ -29,7 +29,7 @@ public function testLoadThrowsExceptionIfSchemaWasNotFound(): void $this->expectExceptionMessage( sprintf('Schema file `%s` not found', $path) ); - $this->expectExceptionCode(StatusCode::INTERNAL_SERVER_ERROR); + $this->expectExceptionCode(Http::INTERNAL_SERVER_ERROR); $this->subject->load($path); } @@ -46,7 +46,7 @@ public function testLoadThrowsExceptionIfSchemaDoesNotContainValidJson(): void $this->expectExceptionMessage( 'Schema does not contain valid json (Syntax error)' ); - $this->expectExceptionCode(StatusCode::INTERNAL_SERVER_ERROR); + $this->expectExceptionCode(Http::INTERNAL_SERVER_ERROR); $this->subject->load($path); } @@ -60,7 +60,7 @@ public function testLoadThrowsExceptionIfSchemaIsNotLoadable(): void $this->expectExceptionMessage( sprintf('Schema file `%s` not loadable', $path), ); - $this->expectExceptionCode(StatusCode::INTERNAL_SERVER_ERROR); + $this->expectExceptionCode(Http::INTERNAL_SERVER_ERROR); $this->subject->load($path); diff --git a/tests/EndpointTest.php b/tests/EndpointTest.php index e3d99f6..fc298a2 100644 --- a/tests/EndpointTest.php +++ b/tests/EndpointTest.php @@ -17,7 +17,7 @@ use Ramsey\Uuid\UuidFactoryInterface; use Ramsey\Uuid\UuidInterface; use stdClass; -use Teapot\StatusCode; +use Teapot\StatusCode\Http; use Usox\JsonSchemaApi\Contract\MethodProviderInterface; use Usox\JsonSchemaApi\Dispatch\MethodDispatcherInterface; use Usox\JsonSchemaApi\Dispatch\RequestValidatorInterface; @@ -92,7 +92,7 @@ public function testServeReturnsHandlerOutput(): void ->andReturn($processedResponse); $this->responseFactory->shouldReceive('createResponse') - ->with(StatusCode::OK) + ->with(Http::OK) ->once() ->andReturn($response); @@ -142,7 +142,7 @@ public function testServeCatchesApiMethodException(): void ->andReturn($uuidValue); $this->responseFactory->shouldReceive('createResponse') - ->with(StatusCode::BAD_REQUEST) + ->with(Http::BAD_REQUEST) ->once() ->andReturn($response); @@ -199,7 +199,7 @@ public function testServeCatchesApiException(): void ->andReturn($uuidValue); $this->responseFactory->shouldReceive('createResponse') - ->with(StatusCode::BAD_REQUEST) + ->with(Http::BAD_REQUEST) ->once() ->andReturn($response); @@ -249,7 +249,7 @@ public function testServeCatchesGenericException(): void ->andReturn($uuidValue); $this->responseFactory->shouldReceive('createResponse') - ->with(StatusCode::INTERNAL_SERVER_ERROR) + ->with(Http::INTERNAL_SERVER_ERROR) ->once() ->andReturn($response); @@ -300,7 +300,7 @@ public function testServeCatchesInternalException(): void ->andReturn($uuidValue); $this->responseFactory->shouldReceive('createResponse') - ->with(StatusCode::INTERNAL_SERVER_ERROR) + ->with(Http::INTERNAL_SERVER_ERROR) ->once() ->andReturn($response); @@ -371,7 +371,7 @@ public function testHandleWorks(): void ->andReturn($processedResponse); $this->responseFactory->shouldReceive('createResponse') - ->with(StatusCode::OK) + ->with(Http::OK) ->once() ->andReturn($response);