From dd781e1f6946cfff407263e0e683f5c55353b2ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 2 Jul 2020 16:56:27 +0200 Subject: [PATCH 1/3] Use Laminas namespace in docs --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 77b13be9..7db714a6 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ composer require lcobucci/content-negotiation-middleware middlewares/negotiation ### Adventure mode If you're ready for an adventure and don't want to use `middlewares/negotiation` -to handle the detection or `zendframework/zend-diactoros` to create the response +to handle the detection or `laminas/diactoros` to create the response body (`StreamInterface` implementation), don't despair! You'll only have to use the normal `ContentTypeMiddleware::__construct()` instead of `ContentTypeMiddleware::fromRecommendedSettings()`. @@ -53,7 +53,7 @@ The nice thing about `assert()` is that we can (and should) disable it in produc so that we don't have useless statements. So, for production mode, we recommend you to set `zend.assertions` to `-1` in your `php.ini`. -For development you should leave `zend.assertions` as `1` and set `assert.exception` to `1`, which +For development, you should leave `zend.assertions` as `1` and set `assert.exception` to `1`, which will make PHP throw an [`AssertionError`](https://secure.php.net/manual/en/class.assertionerror.php) when things go wrong. @@ -70,7 +70,7 @@ declare(strict_types=1); use Lcobucci\ContentNegotiation\ContentTypeMiddleware; use Lcobucci\ContentNegotiation\Formatter\Json; use Lcobucci\ContentNegotiation\Formatter\StringCast; -use Zend\Diactoros\StreamFactory; +use Laminas\Diactoros\StreamFactory; $middleware = ContentTypeMiddleware::fromRecommendedSettings( // First argument is the list of formats you want to support: @@ -130,7 +130,7 @@ use Lcobucci\ContentNegotiation\UnformattedResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; -use Zend\Diactoros\Response; +use Laminas\Diactoros\Response; final class MyHandler implements RequestHandlerInterface { From 795132f470957a2f24f5c663141ce86c04e05b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 2 Jul 2020 17:16:59 +0200 Subject: [PATCH 2/3] Bump up version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 284912ec..0d4a11ed 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3.x-dev" + "dev-master": "3.0.x-dev" } }, "require": { From 90b7f26d3e4785aed68f0ef2064dea47bae217d6 Mon Sep 17 00:00:00 2001 From: Andrii Vasyliev Date: Wed, 24 Jun 2020 17:47:25 +0000 Subject: [PATCH 3/3] Make formatters rely on PSR-7 responses Providing more flexibility to users and simplifying the API. --- README.md | 10 +++++--- src/ContentTypeMiddleware.php | 23 +++-------------- src/Formatter.php | 8 +++--- src/Formatter/ContentOnly.php | 29 ++++++++++++++++++++++ src/Formatter/JmsSerializer.php | 5 ++-- src/Formatter/Json.php | 5 ++-- src/Formatter/NotAcceptable.php | 19 ++++++++++++++ src/Formatter/Plates.php | 5 ++-- src/Formatter/StringCast.php | 5 ++-- src/Formatter/Twig.php | 5 ++-- tests/ContentTypeMiddlewareTest.php | 9 ++++--- tests/Formatter/ContentOnlyTest.php | 33 +++++++++++++++++++++++++ tests/Formatter/JmsSerializerTest.php | 8 +++--- tests/Formatter/JsonTest.php | 25 ++++++++++--------- tests/Formatter/NaiveTemplateEngine.php | 6 ++--- tests/Formatter/NotAcceptableTest.php | 33 +++++++++++++++++++++++++ tests/Formatter/PlatesTest.php | 12 ++++----- tests/Formatter/StringCastTest.php | 8 +++--- tests/Formatter/TwigTest.php | 12 ++++----- 19 files changed, 178 insertions(+), 82 deletions(-) create mode 100644 src/Formatter/ContentOnly.php create mode 100644 src/Formatter/NotAcceptable.php create mode 100644 tests/Formatter/ContentOnlyTest.php create mode 100644 tests/Formatter/NotAcceptableTest.php diff --git a/README.md b/README.md index 7db714a6..932f5285 100644 --- a/README.md +++ b/README.md @@ -167,15 +167,17 @@ declare(strict_types=1); namespace Me\MyApp; use Lcobucci\ContentNegotiation\Formatter; +use Lcobucci\ContentNegotiation\UnformattedResponse; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamFactoryInterface; final class MyFancyFormatter implements Formatter { - public function format($content, array $attributes = []): string + public function format(UnformattedResponse $response, StreamFactoryInterface $streamFactory): ResponseInterface { - // Performs all the magic with $content and creates $result with a - // `string` containing the formatted data. + $content = ''; // Do some fancy formatting of $response->getUnformattedContent() and put into $content - return $result; + return $response->withBody($streamFactory->createStream($content)); } } ``` diff --git a/src/ContentTypeMiddleware.php b/src/ContentTypeMiddleware.php index e4da09d5..96a90473 100644 --- a/src/ContentTypeMiddleware.php +++ b/src/ContentTypeMiddleware.php @@ -3,7 +3,7 @@ namespace Lcobucci\ContentNegotiation; -use Fig\Http\Message\StatusCodeInterface; +use Lcobucci\ContentNegotiation\Formatter\NotAcceptable; use Middlewares\ContentType; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -66,9 +66,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface } $contentType = $this->extractContentType($response->getHeaderLine('Content-Type')); - $formatter = $this->formatters[$contentType] ?? null; + $formatter = $this->formatters[$contentType] ?? new NotAcceptable(); - return $this->formatResponse($response, $formatter); + return $formatter->format($response, $this->streamFactory); } private function extractContentType(string $contentType): string @@ -81,21 +81,4 @@ private function extractContentType(string $contentType): string return substr($contentType, 0, $charsetSeparatorPosition); } - - /** - * @throws ContentCouldNotBeFormatted - */ - private function formatResponse(UnformattedResponse $response, ?Formatter $formatter): ResponseInterface - { - if ($formatter === null) { - return $response->withBody($this->streamFactory->createStream()) - ->withStatus(StatusCodeInterface::STATUS_NOT_ACCEPTABLE); - } - - return $response->withBody( - $this->streamFactory->createStream( - $formatter->format($response->getUnformattedContent(), $response->getAttributes()) - ) - ); - } } diff --git a/src/Formatter.php b/src/Formatter.php index d4ed94a7..ad1afce5 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -3,13 +3,13 @@ namespace Lcobucci\ContentNegotiation; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamFactoryInterface; + interface Formatter { /** - * @param mixed $content - * @param mixed[] $attributes - * * @throws ContentCouldNotBeFormatted */ - public function format($content, array $attributes = []): string; + public function format(UnformattedResponse $response, StreamFactoryInterface $streamFactory): ResponseInterface; } diff --git a/src/Formatter/ContentOnly.php b/src/Formatter/ContentOnly.php new file mode 100644 index 00000000..fb83bad6 --- /dev/null +++ b/src/Formatter/ContentOnly.php @@ -0,0 +1,29 @@ +withBody( + $streamFactory->createStream( + $this->formatContent($response->getUnformattedContent(), $response->getAttributes()) + ) + ); + } + + /** + * @param mixed $content + * @param mixed[] $attributes + */ + abstract public function formatContent($content, array $attributes = []): string; +} diff --git a/src/Formatter/JmsSerializer.php b/src/Formatter/JmsSerializer.php index d414d16d..fb14ef0c 100644 --- a/src/Formatter/JmsSerializer.php +++ b/src/Formatter/JmsSerializer.php @@ -5,11 +5,10 @@ use JMS\Serializer\SerializerInterface; use Lcobucci\ContentNegotiation\ContentCouldNotBeFormatted; -use Lcobucci\ContentNegotiation\Formatter; use Throwable; use function sprintf; -final class JmsSerializer implements Formatter +final class JmsSerializer extends ContentOnly { private SerializerInterface $serializer; private string $format; @@ -23,7 +22,7 @@ public function __construct(SerializerInterface $serializer, string $format) /** * {@inheritdoc} */ - public function format($content, array $attributes = []): string + public function formatContent($content, array $attributes = []): string { try { return $this->serializer->serialize($content, $this->format); diff --git a/src/Formatter/Json.php b/src/Formatter/Json.php index e8887bcc..5c1c657e 100644 --- a/src/Formatter/Json.php +++ b/src/Formatter/Json.php @@ -4,7 +4,6 @@ namespace Lcobucci\ContentNegotiation\Formatter; use Lcobucci\ContentNegotiation\ContentCouldNotBeFormatted; -use Lcobucci\ContentNegotiation\Formatter; use Throwable; use function json_encode; use function sprintf; @@ -15,7 +14,7 @@ use const JSON_THROW_ON_ERROR; use const JSON_UNESCAPED_SLASHES; -final class Json implements Formatter +final class Json extends ContentOnly { private const DEFAULT_FLAGS = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES; @@ -29,7 +28,7 @@ public function __construct(int $flags = self::DEFAULT_FLAGS) /** * {@inheritdoc} */ - public function format($content, array $attributes = []): string + public function formatContent($content, array $attributes = []): string { try { return json_encode($content, $this->flags | JSON_THROW_ON_ERROR); diff --git a/src/Formatter/NotAcceptable.php b/src/Formatter/NotAcceptable.php new file mode 100644 index 00000000..ad0c0b2f --- /dev/null +++ b/src/Formatter/NotAcceptable.php @@ -0,0 +1,19 @@ +withBody($streamFactory->createStream()) + ->withStatus(StatusCodeInterface::STATUS_NOT_ACCEPTABLE); + } +} diff --git a/src/Formatter/Plates.php b/src/Formatter/Plates.php index 80a14d76..2f852830 100644 --- a/src/Formatter/Plates.php +++ b/src/Formatter/Plates.php @@ -4,11 +4,10 @@ namespace Lcobucci\ContentNegotiation\Formatter; use Lcobucci\ContentNegotiation\ContentCouldNotBeFormatted; -use Lcobucci\ContentNegotiation\Formatter; use League\Plates\Engine; use Throwable; -final class Plates implements Formatter +final class Plates extends ContentOnly { private const DEFAULT_ATTRIBUTE = 'template'; @@ -24,7 +23,7 @@ public function __construct(Engine $engine, string $attributeName = self::DEFAUL /** * {@inheritdoc} */ - public function format($content, array $attributes = []): string + public function formatContent($content, array $attributes = []): string { try { return $this->render($content, $attributes); diff --git a/src/Formatter/StringCast.php b/src/Formatter/StringCast.php index 22a70f01..f0d2bc7f 100644 --- a/src/Formatter/StringCast.php +++ b/src/Formatter/StringCast.php @@ -4,16 +4,15 @@ namespace Lcobucci\ContentNegotiation\Formatter; use Lcobucci\ContentNegotiation\ContentCouldNotBeFormatted; -use Lcobucci\ContentNegotiation\Formatter; use function is_object; use function method_exists; -final class StringCast implements Formatter +final class StringCast extends ContentOnly { /** * {@inheritdoc} */ - public function format($content, array $attributes = []): string + public function formatContent($content, array $attributes = []): string { if (is_object($content) && ! method_exists($content, '__toString')) { throw new ContentCouldNotBeFormatted('Given data could not be cast to string'); diff --git a/src/Formatter/Twig.php b/src/Formatter/Twig.php index 4018b15c..9f28f80e 100644 --- a/src/Formatter/Twig.php +++ b/src/Formatter/Twig.php @@ -4,11 +4,10 @@ namespace Lcobucci\ContentNegotiation\Formatter; use Lcobucci\ContentNegotiation\ContentCouldNotBeFormatted; -use Lcobucci\ContentNegotiation\Formatter; use Throwable; use Twig\Environment; -final class Twig implements Formatter +final class Twig extends ContentOnly { private const DEFAULT_ATTRIBUTE = 'template'; @@ -26,7 +25,7 @@ public function __construct( /** * {@inheritdoc} */ - public function format($content, array $attributes = []): string + public function formatContent($content, array $attributes = []): string { try { return $this->render($content, $attributes); diff --git a/tests/ContentTypeMiddlewareTest.php b/tests/ContentTypeMiddlewareTest.php index bdf1c9ed..030632ff 100644 --- a/tests/ContentTypeMiddlewareTest.php +++ b/tests/ContentTypeMiddlewareTest.php @@ -46,6 +46,7 @@ final class ContentTypeMiddlewareTest extends TestCase * @covers ::process() * * @uses \Lcobucci\ContentNegotiation\Formatter\Json + * @uses \Lcobucci\ContentNegotiation\Formatter\ContentOnly */ public function processShouldReturnFormattedResponseDirectly(): void { @@ -64,10 +65,10 @@ public function processShouldReturnFormattedResponseDirectly(): void * @covers ::fromRecommendedSettings() * @covers ::process() * @covers ::extractContentType() - * @covers ::formatResponse() * * @uses \Lcobucci\ContentNegotiation\UnformattedResponse * @uses \Lcobucci\ContentNegotiation\Formatter\Json + * @uses \Lcobucci\ContentNegotiation\Formatter\NotAcceptable */ public function processShouldReturnAResponseWithErrorWhenFormatterWasNotFound(): void { @@ -90,9 +91,9 @@ public function processShouldReturnAResponseWithErrorWhenFormatterWasNotFound(): * @covers ::fromRecommendedSettings() * @covers ::process() * @covers ::extractContentType() - * @covers ::formatResponse() * * @uses \Lcobucci\ContentNegotiation\UnformattedResponse + * @uses \Lcobucci\ContentNegotiation\Formatter\ContentOnly * @uses \Lcobucci\ContentNegotiation\Formatter\Json */ public function processShouldReturnAResponseWithFormattedContent(): void @@ -117,9 +118,9 @@ public function processShouldReturnAResponseWithFormattedContent(): void * @covers ::fromRecommendedSettings() * @covers ::process() * @covers ::extractContentType() - * @covers ::formatResponse() * * @uses \Lcobucci\ContentNegotiation\UnformattedResponse + * @uses \Lcobucci\ContentNegotiation\Formatter\ContentOnly * @uses \Lcobucci\ContentNegotiation\Formatter\Json */ public function processShouldPassAttributesToTheFormatterProperly(): void @@ -148,9 +149,9 @@ public function processShouldPassAttributesToTheFormatterProperly(): void * @covers ::fromRecommendedSettings() * @covers ::process() * @covers ::extractContentType() - * @covers ::formatResponse() * * @uses \Lcobucci\ContentNegotiation\UnformattedResponse + * @uses \Lcobucci\ContentNegotiation\Formatter\ContentOnly * @uses \Lcobucci\ContentNegotiation\Formatter\Json */ public function processShouldReturnAResponseWithFormattedContentEvenWithoutForcingTheCharset(): void diff --git a/tests/Formatter/ContentOnlyTest.php b/tests/Formatter/ContentOnlyTest.php new file mode 100644 index 00000000..08c4f7f4 --- /dev/null +++ b/tests/Formatter/ContentOnlyTest.php @@ -0,0 +1,33 @@ +getMockForAbstractClass(ContentOnly::class); + $formatter->method('formatContent')->willReturn('A fancy result'); + + $response = $formatter->format(new UnformattedResponse(new Response(), 'testing'), new StreamFactory()); + + self::assertSame('A fancy result', $response->getBody()->getContents()); + } +} diff --git a/tests/Formatter/JmsSerializerTest.php b/tests/Formatter/JmsSerializerTest.php index d3f269f1..aa18b663 100644 --- a/tests/Formatter/JmsSerializerTest.php +++ b/tests/Formatter/JmsSerializerTest.php @@ -32,7 +32,7 @@ public function createSerializer(): void * @test * * @covers ::__construct() - * @covers ::format() + * @covers ::formatContent() */ public function formatShouldSimplyForwardCallToSerializer(): void { @@ -45,14 +45,14 @@ public function formatShouldSimplyForwardCallToSerializer(): void $formatter = new JmsSerializer($this->serializer, 'json'); - self::assertSame('{"a":"test"}', $formatter->format($content)); + self::assertSame('{"a":"test"}', $formatter->formatContent($content)); } /** * @test * * @covers ::__construct() - * @covers ::format() + * @covers ::formatContent() */ public function formatShouldConvertAnyRaisedException(): void { @@ -62,6 +62,6 @@ public function formatShouldConvertAnyRaisedException(): void ->willThrowException(new RuntimeException()); $formatter = new JmsSerializer($this->serializer, 'json'); - $formatter->format(['a' => 'test']); + $formatter->formatContent(['a' => 'test']); } } diff --git a/tests/Formatter/JsonTest.php b/tests/Formatter/JsonTest.php index ee845895..6ae06d28 100644 --- a/tests/Formatter/JsonTest.php +++ b/tests/Formatter/JsonTest.php @@ -22,13 +22,14 @@ final class JsonTest extends TestCase * * @covers ::__construct() * - * @uses \Lcobucci\ContentNegotiation\Formatter\Json::format() + * @uses \Lcobucci\ContentNegotiation\Formatter\Json::formatContent() */ public function constructorShouldAllowTheConfigurationOfEncodingFlags(): void { self::assertSame( '["","\'bar\'","\"baz\"","&blong&","\u00e9","http://"]', - (new Json(JSON_UNESCAPED_SLASHES))->format(['', "'bar'", '"baz"', '&blong&', "\xc3\xa9", 'http://']) + (new Json(JSON_UNESCAPED_SLASHES)) + ->formatContent(['', "'bar'", '"baz"', '&blong&', "\xc3\xa9", 'http://']) ); } @@ -37,20 +38,20 @@ public function constructorShouldAllowTheConfigurationOfEncodingFlags(): void * * @covers ::__construct() * - * @uses \Lcobucci\ContentNegotiation\Formatter\Json::format() + * @uses \Lcobucci\ContentNegotiation\Formatter\Json::formatContent() */ public function constructorShouldUseDefaultFlagsWhenNothingWasSet(): void { self::assertSame( '["\u003Cfoo\u003E","\u0027bar\u0027","\u0022baz\u0022","\u0026blong\u0026","\u00e9","http://"]', - $this->format(['', "'bar'", '"baz"', '&blong&', "\xc3\xa9", 'http://']) + $this->formatContent(['', "'bar'", '"baz"', '&blong&', "\xc3\xa9", 'http://']) ); } /** * @test * - * @covers ::format() + * @covers ::formatContent() * * @uses \Lcobucci\ContentNegotiation\Formatter\Json::__construct() */ @@ -58,14 +59,14 @@ public function formatShouldReturnAJsonEncodedValue(): void { self::assertJsonStringEqualsJsonString( '{"id":1,"name":"Test"}', - $this->format(new PersonDto(1, 'Test')) + $this->formatContent(new PersonDto(1, 'Test')) ); } /** * @test * - * @covers ::format() + * @covers ::formatContent() * * @uses \Lcobucci\ContentNegotiation\Formatter\Json::__construct() */ @@ -74,13 +75,13 @@ public function formatShouldRaiseExceptionWhenContentCouldNotBeEncoded(): void $this->expectException(ContentCouldNotBeFormatted::class); $this->expectExceptionMessage('Inf and NaN cannot be JSON encoded'); - $this->format(acos(8)); + $this->formatContent(acos(8)); } /** * @test * - * @covers ::format() + * @covers ::formatContent() * * @uses \Lcobucci\ContentNegotiation\Formatter\Json::__construct() */ @@ -89,7 +90,7 @@ public function formatShouldConvertAnyExceptionDuringJsonSerialization(): void $this->expectException(ContentCouldNotBeFormatted::class); $this->expectExceptionMessage('An exception was thrown during JSON formatting'); - $this->format( + $this->formatContent( new class implements JsonSerializable { public function jsonSerialize(): void @@ -103,10 +104,10 @@ public function jsonSerialize(): void /** * @param mixed $content */ - private function format($content): string + private function formatContent($content): string { $formatter = new Json(); - return $formatter->format($content); + return $formatter->formatContent($content); } } diff --git a/tests/Formatter/NaiveTemplateEngine.php b/tests/Formatter/NaiveTemplateEngine.php index 5cc9b428..56504d72 100644 --- a/tests/Formatter/NaiveTemplateEngine.php +++ b/tests/Formatter/NaiveTemplateEngine.php @@ -3,7 +3,7 @@ namespace Lcobucci\ContentNegotiation\Tests\Formatter; -use Lcobucci\ContentNegotiation\Formatter; +use Lcobucci\ContentNegotiation\Formatter\ContentOnly; use SplFileObject; use function array_keys; use function array_map; @@ -12,7 +12,7 @@ use function str_replace; use function trim; -final class NaiveTemplateEngine implements Formatter +final class NaiveTemplateEngine extends ContentOnly { private const BASE_DIR = __DIR__ . '/../../templates/naive/'; private const EXTENSION = 'html'; @@ -20,7 +20,7 @@ final class NaiveTemplateEngine implements Formatter /** * {@inheritdoc} */ - public function format($content, array $attributes = []): string + public function formatContent($content, array $attributes = []): string { $template = $this->getTemplateContent($attributes); diff --git a/tests/Formatter/NotAcceptableTest.php b/tests/Formatter/NotAcceptableTest.php new file mode 100644 index 00000000..6729269f --- /dev/null +++ b/tests/Formatter/NotAcceptableTest.php @@ -0,0 +1,33 @@ +format(new UnformattedResponse(new Response(), 'testing'), new StreamFactory()); + + self::assertSame('', $response->getBody()->getContents()); + self::assertSame(StatusCodeInterface::STATUS_NOT_ACCEPTABLE, $response->getStatusCode()); + } +} diff --git a/tests/Formatter/PlatesTest.php b/tests/Formatter/PlatesTest.php index ccbd0e04..52a16ef1 100644 --- a/tests/Formatter/PlatesTest.php +++ b/tests/Formatter/PlatesTest.php @@ -29,13 +29,13 @@ public function configureEngine(): void * @test * * @covers ::__construct() - * @covers ::format() + * @covers ::formatContent() * @covers ::render() */ public function formatShouldReturnContentFormattedByPlates(): void { $formatter = new Plates($this->engine); - $content = $formatter->format(new PersonDto(1, 'Testing'), ['template' => 'person']); + $content = $formatter->formatContent(new PersonDto(1, 'Testing'), ['template' => 'person']); self::assertStringContainsString('
1
', $content); self::assertStringContainsString('
Testing
', $content); @@ -45,13 +45,13 @@ public function formatShouldReturnContentFormattedByPlates(): void * @test * * @covers ::__construct() - * @covers ::format() + * @covers ::formatContent() * @covers ::render() */ public function formatShouldReadTemplateNameFromCustomAttribute(): void { $formatter = new Plates($this->engine, 'fancy!'); - $content = $formatter->format(new PersonDto(1, 'Testing'), ['fancy!' => 'person']); + $content = $formatter->formatContent(new PersonDto(1, 'Testing'), ['fancy!' => 'person']); self::assertStringContainsString('
1
', $content); self::assertStringContainsString('
Testing
', $content); @@ -61,7 +61,7 @@ public function formatShouldReadTemplateNameFromCustomAttribute(): void * @test * * @covers ::__construct() - * @covers ::format() + * @covers ::formatContent() * @covers ::render() */ public function formatShouldConvertAnyPlatesException(): void @@ -71,6 +71,6 @@ public function formatShouldConvertAnyPlatesException(): void $this->expectException(ContentCouldNotBeFormatted::class); $this->expectExceptionMessage('An error occurred while formatting using plates'); - $formatter->format(new PersonDto(1, 'Testing'), ['template' => 'no-template-at-all']); + $formatter->formatContent(new PersonDto(1, 'Testing'), ['template' => 'no-template-at-all']); } } diff --git a/tests/Formatter/StringCastTest.php b/tests/Formatter/StringCastTest.php index 0efc8af2..e225527c 100644 --- a/tests/Formatter/StringCastTest.php +++ b/tests/Formatter/StringCastTest.php @@ -16,7 +16,7 @@ final class StringCastTest extends TestCase * @test * @dataProvider validData * - * @covers ::format() + * @covers ::formatContent() * * @param mixed $content */ @@ -26,7 +26,7 @@ public function formatShouldSimplyReturnTheStringRepresentationOfTheContent( ): void { $formatter = new StringCast(); - self::assertSame($expected, $formatter->format($content)); + self::assertSame($expected, $formatter->formatContent($content)); } /** @@ -55,7 +55,7 @@ public function __toString(): string /** * @test * - * @covers ::format() + * @covers ::formatContent() */ public function formatShouldRaiseExceptionWhenContentCouldNotBeCastToString(): void { @@ -66,6 +66,6 @@ public function formatShouldRaiseExceptionWhenContentCouldNotBeCastToString(): v }; $formatter = new StringCast(); - $formatter->format($content); + $formatter->formatContent($content); } } diff --git a/tests/Formatter/TwigTest.php b/tests/Formatter/TwigTest.php index 337dc3a8..d1fda680 100644 --- a/tests/Formatter/TwigTest.php +++ b/tests/Formatter/TwigTest.php @@ -32,13 +32,13 @@ public function configureEngine(): void * @test * * @covers ::__construct() - * @covers ::format() + * @covers ::formatContent() * @covers ::render() */ public function formatShouldReturnContentFormattedByPlates(): void { $formatter = new Twig($this->environment); - $content = $formatter->format(new PersonDto(1, 'Testing'), ['template' => 'person.twig']); + $content = $formatter->formatContent(new PersonDto(1, 'Testing'), ['template' => 'person.twig']); self::assertStringContainsString('
1
', $content); self::assertStringContainsString('
Testing
', $content); @@ -48,13 +48,13 @@ public function formatShouldReturnContentFormattedByPlates(): void * @test * * @covers ::__construct() - * @covers ::format() + * @covers ::formatContent() * @covers ::render() */ public function formatShouldReadTemplateNameFromCustomAttribute(): void { $formatter = new Twig($this->environment, 'fancy!'); - $content = $formatter->format(new PersonDto(1, 'Testing'), ['fancy!' => 'person.twig']); + $content = $formatter->formatContent(new PersonDto(1, 'Testing'), ['fancy!' => 'person.twig']); self::assertStringContainsString('
1
', $content); self::assertStringContainsString('
Testing
', $content); @@ -64,7 +64,7 @@ public function formatShouldReadTemplateNameFromCustomAttribute(): void * @test * * @covers ::__construct() - * @covers ::format() + * @covers ::formatContent() * @covers ::render() */ public function formatShouldConvertAnyTwigException(): void @@ -74,6 +74,6 @@ public function formatShouldConvertAnyTwigException(): void $this->expectException(ContentCouldNotBeFormatted::class); $this->expectExceptionMessage('An error occurred while formatting using twig'); - $formatter->format(new PersonDto(1, 'Testing'), ['template' => 'no-template-at-all']); + $formatter->formatContent(new PersonDto(1, 'Testing'), ['template' => 'no-template-at-all']); } }