From fb9d6a054f896f310e17d7761f6c5894c461b6b1 Mon Sep 17 00:00:00 2001 From: George Steel Date: Wed, 3 Mar 2021 11:37:53 +0000 Subject: [PATCH 1/4] qa: consistent use of static PHPUnit assertions --- test/Unit/Container/ApiFactoryTest.php | 6 +-- .../Container/LinkResolverFactoryTest.php | 4 +- test/Unit/Event/WebhookEventTest.php | 4 +- .../Http/PrismicHttpClientFactoryTest.php | 8 ++-- .../Container/DocumentResolverFactoryTest.php | 2 +- .../ExpiredPreviewHandlerFactoryTest.php | 2 +- .../InjectRequestCookiesFactoryTest.php | 2 +- .../PreviewCacheHeadersFactoryTest.php | 2 +- .../Container/PreviewHandlerFactoryTest.php | 4 +- .../Container/PrismicTemplateFactoryTest.php | 4 +- .../Container/WebhookHandlerFactoryTest.php | 6 +-- test/Unit/Middleware/DocumentResolverTest.php | 8 ++-- .../Middleware/ExpiredPreviewHandlerTest.php | 4 +- .../Middleware/InjectRequestCookiesTest.php | 6 +-- .../Middleware/PreviewCacheHeadersTest.php | 2 +- test/Unit/Middleware/PreviewHandlerTest.php | 14 +++---- test/Unit/Middleware/PrismicTemplateTest.php | 20 ++++----- .../HydratingResultSetFactoryFactoryTest.php | 2 +- .../Container/TypeMapFactoryTest.php | 24 +++++------ test/Unit/ResultSet/TypeMapTest.php | 8 ++-- .../Container/DocumentResolverFactoryTest.php | 2 +- .../Container/RouteMatcherFactoryTest.php | 2 +- .../Container/RouteParamsFactoryTest.php | 20 ++++----- test/Unit/Router/DocumentResolverTest.php | 38 ++++++++--------- test/Unit/Router/RouteMatcherTest.php | 42 +++++++++---------- test/Unit/Router/RouteParamsTest.php | 12 +++--- 26 files changed, 124 insertions(+), 124 deletions(-) diff --git a/test/Unit/Container/ApiFactoryTest.php b/test/Unit/Container/ApiFactoryTest.php index 04ef951..2213f85 100644 --- a/test/Unit/Container/ApiFactoryTest.php +++ b/test/Unit/Container/ApiFactoryTest.php @@ -18,7 +18,7 @@ class ApiFactoryTest extends TestCase public function testAnExceptionIsThrownWhenAnApiUrlHasNotBeenConfigured() : void { $container = $this->createMock(ContainerInterface::class); - $container->expects($this->once()) + $container->expects(self::once()) ->method('has') ->with('config') ->willReturn(false); @@ -33,7 +33,7 @@ public function testAnExceptionIsThrownWhenAnApiUrlHasNotBeenConfigured() : void public function testFactoryWithNoDependenciesSatisfied() : void { $container = $this->createMock(ContainerInterface::class); - $container->expects($this->exactly(6)) + $container->expects(self::exactly(6)) ->method('has') ->willReturnMap([ ['config', true], @@ -44,7 +44,7 @@ public function testFactoryWithNoDependenciesSatisfied() : void [PrismicApiCache::class, false], ]); - $container->expects($this->once()) + $container->expects(self::once()) ->method('get') ->with('config') ->willReturn(['prismic' => ['api' => 'https://example.com']]); diff --git a/test/Unit/Container/LinkResolverFactoryTest.php b/test/Unit/Container/LinkResolverFactoryTest.php index 32f1a76..6895b41 100644 --- a/test/Unit/Container/LinkResolverFactoryTest.php +++ b/test/Unit/Container/LinkResolverFactoryTest.php @@ -102,12 +102,12 @@ public function testFactory() : void } }')); $api = $this->createMock(ApiClient::class); - $api->expects($this->once()) + $api->expects(self::once()) ->method('data') ->willReturn($data); $container = $this->createMock(ContainerInterface::class); - $container->expects($this->exactly(4)) + $container->expects(self::exactly(4)) ->method('get') ->willReturnMap([ [RouteParams::class, RouteParams::fromArray([])], diff --git a/test/Unit/Event/WebhookEventTest.php b/test/Unit/Event/WebhookEventTest.php index 0f6943b..d5ef317 100644 --- a/test/Unit/Event/WebhookEventTest.php +++ b/test/Unit/Event/WebhookEventTest.php @@ -24,11 +24,11 @@ public function testThatEventsCanBeSerialised() : void $copy = unserialize($data); assert($copy instanceof WebhookEvent); - $this->assertEquals( + self::assertEquals( $event->received(), $copy->received() ); - $this->assertSame( + self::assertSame( $event->payload()->foo, $copy->payload()->foo ); diff --git a/test/Unit/Http/PrismicHttpClientFactoryTest.php b/test/Unit/Http/PrismicHttpClientFactoryTest.php index 5ab3103..82823d2 100644 --- a/test/Unit/Http/PrismicHttpClientFactoryTest.php +++ b/test/Unit/Http/PrismicHttpClientFactoryTest.php @@ -22,7 +22,7 @@ protected function setUp() : void private function clientInContainer(bool $value) : void { - $this->container->expects($this->once()) + $this->container->expects(self::once()) ->method('has') ->with(ClientInterface::class) ->willReturn($value); @@ -33,19 +33,19 @@ public function testThatClientInContainerWillBeReturnedWhenAvailable() : void $client = $this->createMock(ClientInterface::class); $this->clientInContainer(true); - $this->container->expects($this->once()) + $this->container->expects(self::once()) ->method('get') ->with(ClientInterface::class) ->willReturn($client); $factory = new PrismicHttpClientFactory(); - $this->assertSame($client, $factory($this->container)); + self::assertSame($client, $factory($this->container)); } public function testThatClientDiscoveryWillBeUsedWhenNoClientIsInTheContainer() : void { $this->clientInContainer(false); - $this->container->expects($this->never())->method('get'); + $this->container->expects(self::never())->method('get'); $factory = new PrismicHttpClientFactory(); $factory($this->container); $this->addToAssertionCount(1); diff --git a/test/Unit/Middleware/Container/DocumentResolverFactoryTest.php b/test/Unit/Middleware/Container/DocumentResolverFactoryTest.php index 25dc4e2..264c724 100644 --- a/test/Unit/Middleware/Container/DocumentResolverFactoryTest.php +++ b/test/Unit/Middleware/Container/DocumentResolverFactoryTest.php @@ -14,7 +14,7 @@ public function testFactory() : void { $resolver = $this->createMock(DocumentResolver::class); $container = $this->createMock(ContainerInterface::class); - $container->expects($this->once()) + $container->expects(self::once()) ->method('get') ->with(DocumentResolver::class) ->willReturn($resolver); diff --git a/test/Unit/Middleware/Container/ExpiredPreviewHandlerFactoryTest.php b/test/Unit/Middleware/Container/ExpiredPreviewHandlerFactoryTest.php index 1ba22b6..c2be2bf 100644 --- a/test/Unit/Middleware/Container/ExpiredPreviewHandlerFactoryTest.php +++ b/test/Unit/Middleware/Container/ExpiredPreviewHandlerFactoryTest.php @@ -12,7 +12,7 @@ class ExpiredPreviewHandlerFactoryTest extends TestCase public function testFactoryWhenNoConfigIsAvailable() : void { $container = $this->createMock(ContainerInterface::class); - $container->expects($this->once()) + $container->expects(self::once()) ->method('has') ->with('config') ->willReturn(false); diff --git a/test/Unit/Middleware/Container/InjectRequestCookiesFactoryTest.php b/test/Unit/Middleware/Container/InjectRequestCookiesFactoryTest.php index 804e881..742ff4a 100644 --- a/test/Unit/Middleware/Container/InjectRequestCookiesFactoryTest.php +++ b/test/Unit/Middleware/Container/InjectRequestCookiesFactoryTest.php @@ -14,7 +14,7 @@ public function testFactory() : void { $api = $this->createMock(ApiClient::class); $container = $this->createMock(ContainerInterface::class); - $container->expects($this->once()) + $container->expects(self::once()) ->method('get') ->with(ApiClient::class) ->willReturn($api); diff --git a/test/Unit/Middleware/Container/PreviewCacheHeadersFactoryTest.php b/test/Unit/Middleware/Container/PreviewCacheHeadersFactoryTest.php index d642633..9a036de 100644 --- a/test/Unit/Middleware/Container/PreviewCacheHeadersFactoryTest.php +++ b/test/Unit/Middleware/Container/PreviewCacheHeadersFactoryTest.php @@ -13,7 +13,7 @@ class PreviewCacheHeadersFactoryTest extends TestCase public function testFactory() : void { $container = $this->createMock(ContainerInterface::class); - $container->expects($this->once()) + $container->expects(self::once()) ->method('get') ->with(ApiClient::class) ->willReturn($this->createMock(ApiClient::class)); diff --git a/test/Unit/Middleware/Container/PreviewHandlerFactoryTest.php b/test/Unit/Middleware/Container/PreviewHandlerFactoryTest.php index 58bb05f..0f1a2e2 100644 --- a/test/Unit/Middleware/Container/PreviewHandlerFactoryTest.php +++ b/test/Unit/Middleware/Container/PreviewHandlerFactoryTest.php @@ -14,7 +14,7 @@ class PreviewHandlerFactoryTest extends TestCase public function testFactoryExecutesWhenConfigIsNotAvailable() : void { $container = $this->createMock(ContainerInterface::class); - $container->expects($this->once()) + $container->expects(self::once()) ->method('has') ->with('config') ->willReturn(false); @@ -30,7 +30,7 @@ public function testFactoryExecutesWhenConfigIsNotAvailable() : void ], ]; - $container->expects($this->exactly(2)) + $container->expects(self::exactly(2)) ->method('get') ->willReturnMap($map); diff --git a/test/Unit/Middleware/Container/PrismicTemplateFactoryTest.php b/test/Unit/Middleware/Container/PrismicTemplateFactoryTest.php index 52ca23c..d945a7c 100644 --- a/test/Unit/Middleware/Container/PrismicTemplateFactoryTest.php +++ b/test/Unit/Middleware/Container/PrismicTemplateFactoryTest.php @@ -13,11 +13,11 @@ class PrismicTemplateFactoryTest extends TestCase public function testFactory() : void { $container = $this->createMock(ContainerInterface::class); - $container->expects($this->once()) + $container->expects(self::once()) ->method('has') ->willReturn(false); - $container->expects($this->once()) + $container->expects(self::once()) ->method('get') ->with(TemplateRendererInterface::class) ->willReturn($this->createMock(TemplateRendererInterface::class)); diff --git a/test/Unit/Middleware/Container/WebhookHandlerFactoryTest.php b/test/Unit/Middleware/Container/WebhookHandlerFactoryTest.php index 54ac8c8..5e0028f 100644 --- a/test/Unit/Middleware/Container/WebhookHandlerFactoryTest.php +++ b/test/Unit/Middleware/Container/WebhookHandlerFactoryTest.php @@ -14,7 +14,7 @@ class WebhookHandlerFactoryTest extends TestCase public function testThatAnExceptionIsThrownWhenNoEventDispatcherIsAvailable() : void { $container = $this->createMock(ContainerInterface::class); - $container->expects($this->exactly(2)) + $container->expects(self::exactly(2)) ->method('has') ->willReturnMap([ ['config', false], @@ -31,14 +31,14 @@ public function testThatAnExceptionIsThrownWhenNoEventDispatcherIsAvailable() : public function testFactoryWhenDispatcherCanBeFound() : void { $container = $this->createMock(ContainerInterface::class); - $container->expects($this->exactly(2)) + $container->expects(self::exactly(2)) ->method('has') ->willReturnMap([ ['config', false], [EventDispatcherInterface::class, true], ]); - $container->expects($this->once()) + $container->expects(self::once()) ->method('get') ->willReturn($this->createMock(EventDispatcherInterface::class)); diff --git a/test/Unit/Middleware/DocumentResolverTest.php b/test/Unit/Middleware/DocumentResolverTest.php index 89c6484..9c96f4b 100644 --- a/test/Unit/Middleware/DocumentResolverTest.php +++ b/test/Unit/Middleware/DocumentResolverTest.php @@ -68,11 +68,11 @@ public function testThatGivenADocumentCanBeResolvedTheDocumentIsInjectedToReques $this->document ); $request = $this->request->withAttribute(RouteResult::class, $this->routeResult); - $this->assertNull($request->getAttribute(Document::class)); + self::assertNull($request->getAttribute(Document::class)); $subject = new DocumentResolver($this->resolver); $response = $subject->process($request, $this->handler); - $this->assertSame($this->document, $this->handler->lastRequest->getAttribute(Document::class)); + self::assertSame($this->document, $this->handler->lastRequest->getAttribute(Document::class)); return $response; } @@ -82,9 +82,9 @@ public function testThatRequestAttributeIsNotPresentWhenADocumentCannotBeResolve $this->resolver->method('resolve')->with($this->routeResult)->willReturn(null); $request = $this->request->withAttribute(RouteResult::class, $this->routeResult); - $this->assertNull($request->getAttribute(Document::class)); + self::assertNull($request->getAttribute(Document::class)); $subject = new DocumentResolver($this->resolver); $subject->process($request, $this->handler); - $this->assertNull($this->handler->lastRequest->getAttribute(Document::class)); + self::assertNull($this->handler->lastRequest->getAttribute(Document::class)); } } diff --git a/test/Unit/Middleware/ExpiredPreviewHandlerTest.php b/test/Unit/Middleware/ExpiredPreviewHandlerTest.php index 6a568f9..21e051f 100644 --- a/test/Unit/Middleware/ExpiredPreviewHandlerTest.php +++ b/test/Unit/Middleware/ExpiredPreviewHandlerTest.php @@ -43,7 +43,7 @@ public function handle(ServerRequestInterface $request) : ResponseInterface public function testThatMiddlewareIsNoOpByDefault() : void { $response = $this->subject->process($this->request, $this->handler); - $this->assertSame('Boom', (string) $response->getBody()); + self::assertSame('Boom', (string) $response->getBody()); } public function testThatResponseIsRedirectWithCookieWhenExpiryErrorIsPresent() : void @@ -53,6 +53,6 @@ public function testThatResponseIsRedirectWithCookieWhenExpiryErrorIsPresent() : $response = $this->subject->process($request, $this->handler); self::assertResponseHasStatus($response, 302); - self::assertMessageHasHeader($response, 'Set-Cookie', $this->stringStartsWith(ApiClient::PREVIEW_COOKIE)); + self::assertMessageHasHeader($response, 'Set-Cookie', self::stringStartsWith(ApiClient::PREVIEW_COOKIE)); } } diff --git a/test/Unit/Middleware/InjectRequestCookiesTest.php b/test/Unit/Middleware/InjectRequestCookiesTest.php index 8be1b28..3542dba 100644 --- a/test/Unit/Middleware/InjectRequestCookiesTest.php +++ b/test/Unit/Middleware/InjectRequestCookiesTest.php @@ -37,11 +37,11 @@ public function handle(ServerRequestInterface $request) : ResponseInterface public function testThatRequestCookiesAreProvidedToTheApi() : void { - $this->assertFalse($this->api->inPreview()); + self::assertFalse($this->api->inPreview()); $request = Psr17FactoryDiscovery::findServerRequestFactory()->createServerRequest('GET', '/foo'); $request = $request->withCookieParams([Api::PREVIEW_COOKIE => 'cookieValue']); $this->subject->process($request, $this->handler); - $this->assertTrue($this->api->inPreview()); - $this->assertSame('cookieValue', (string) $this->api->ref()); + self::assertTrue($this->api->inPreview()); + self::assertSame('cookieValue', (string) $this->api->ref()); } } diff --git a/test/Unit/Middleware/PreviewCacheHeadersTest.php b/test/Unit/Middleware/PreviewCacheHeadersTest.php index faba0ba..ba0ce6e 100644 --- a/test/Unit/Middleware/PreviewCacheHeadersTest.php +++ b/test/Unit/Middleware/PreviewCacheHeadersTest.php @@ -43,7 +43,7 @@ public function testThatNoCacheControlHeaderIsSetWhenPreviewIsNotActive() : void $this->api->method('inPreview')->willReturn(false); $response = $this->subject->process($this->request, $this->handler); - $this->assertEmpty($response->getHeader('Cache-Control')); + self::assertEmpty($response->getHeader('Cache-Control')); } public function testThatCacheControlHeaderIsSetWhenPreviewIsActive() : void diff --git a/test/Unit/Middleware/PreviewHandlerTest.php b/test/Unit/Middleware/PreviewHandlerTest.php index ce64af2..7a45d6a 100644 --- a/test/Unit/Middleware/PreviewHandlerTest.php +++ b/test/Unit/Middleware/PreviewHandlerTest.php @@ -52,9 +52,9 @@ public function handle(ServerRequestInterface $request) : ResponseInterface public function testThatWhenTheTokenIsEmptyNoRedirectWillOccur() : void { - $this->assertEmpty($this->request->getQueryParams()); + self::assertEmpty($this->request->getQueryParams()); $response = $this->subject->process($this->request, $this->handler); - $this->assertSame('Boom', (string) $response->getBody()); + self::assertSame('Boom', (string) $response->getBody()); } public function testThatWhenTheTokenIsInvalidNoRedirectWillOccur() : void @@ -62,12 +62,12 @@ public function testThatWhenTheTokenIsInvalidNoRedirectWillOccur() : void $token = 'expected-token'; $request = $this->request->withQueryParams(['token' => $token]); $this->api - ->expects($this->once()) + ->expects(self::once()) ->method('previewSession') ->with($token) ->willThrowException(new InvalidPreviewToken('bad news')); $response = $this->subject->process($request, $this->handler); - $this->assertSame('Boom', (string) $response->getBody()); + self::assertSame('Boom', (string) $response->getBody()); } public function testThatWhenTheTokenHasExpiredNoRedirectOccursAndRequestAttributeIsGiven() : void @@ -76,15 +76,15 @@ public function testThatWhenTheTokenHasExpiredNoRedirectOccursAndRequestAttribut $request = $this->request->withQueryParams(['token' => $token]); $error = new PreviewTokenExpired('bad news'); $this->api - ->expects($this->once()) + ->expects(self::once()) ->method('previewSession') ->with($token) ->willThrowException($error); $response = $this->subject->process($request, $this->handler); - $this->assertSame('Boom', (string) $response->getBody()); + self::assertSame('Boom', (string) $response->getBody()); - $this->assertSame($error, $this->handler->lastRequest->getAttribute(PreviewTokenExpired::class)); + self::assertSame($error, $this->handler->lastRequest->getAttribute(PreviewTokenExpired::class)); } public function testThatTheRedirectWillBeTheDefaultUrlWhenTheApiDoesNotReturnALink() : void diff --git a/test/Unit/Middleware/PrismicTemplateTest.php b/test/Unit/Middleware/PrismicTemplateTest.php index 44b0432..f4d1862 100644 --- a/test/Unit/Middleware/PrismicTemplateTest.php +++ b/test/Unit/Middleware/PrismicTemplateTest.php @@ -63,11 +63,11 @@ private function requestHasTemplate() : ServerRequestInterface public function testThatRequestIsDelegatedWhenADocumentIsNotFound() : void { $request = $this->requestHasTemplate(); - $this->assertNull($this->handler->lastRequest); + self::assertNull($this->handler->lastRequest); $this->subject->process($request, $this->handler); - $this->assertSame($request, $this->handler->lastRequest); + self::assertSame($request, $this->handler->lastRequest); } private function requestHasDocument() : ServerRequestInterface @@ -79,26 +79,26 @@ private function requestHasDocument() : ServerRequestInterface public function testThatTheTemplateWillBeRenderedWhenRequestCriteriaAreMet() : void { - $this->templates->expects($this->once()) + $this->templates->expects(self::once()) ->method('addDefaultParam') ->with( - $this->equalTo(TemplateRendererInterface::TEMPLATE_ALL), - $this->equalTo('document'), - $this->equalTo($this->document) + self::equalTo(TemplateRendererInterface::TEMPLATE_ALL), + self::equalTo('document'), + self::equalTo($this->document) ); - $this->templates->expects($this->once()) + $this->templates->expects(self::once()) ->method('render') - ->with($this->equalTo('template::foo')) + ->with(self::equalTo('template::foo')) ->willReturn('Some Markup'); - $this->document->expects($this->once()) + $this->document->expects(self::once()) ->method('lang') ->willReturn('en-gb'); $response = $this->subject->process($this->requestHasDocument(), $this->handler); self::assertResponseIsSuccess($response); - self::assertMessageBodyMatches($response, $this->equalTo('Some Markup')); + self::assertMessageBodyMatches($response, self::equalTo('Some Markup')); self::assertMessageHasHeader($response, 'content-language', 'en-gb'); } } diff --git a/test/Unit/ResultSet/Container/HydratingResultSetFactoryFactoryTest.php b/test/Unit/ResultSet/Container/HydratingResultSetFactoryFactoryTest.php index 1b32e89..b91848f 100644 --- a/test/Unit/ResultSet/Container/HydratingResultSetFactoryFactoryTest.php +++ b/test/Unit/ResultSet/Container/HydratingResultSetFactoryFactoryTest.php @@ -14,7 +14,7 @@ public function testFactory() : void { $map = new TypeMap([]); $container = $this->createMock(ContainerInterface::class); - $container->expects($this->once()) + $container->expects(self::once()) ->method('get') ->with(TypeMap::class) ->willReturn($map); diff --git a/test/Unit/ResultSet/Container/TypeMapFactoryTest.php b/test/Unit/ResultSet/Container/TypeMapFactoryTest.php index ee78893..a54f625 100644 --- a/test/Unit/ResultSet/Container/TypeMapFactoryTest.php +++ b/test/Unit/ResultSet/Container/TypeMapFactoryTest.php @@ -14,12 +14,12 @@ class TypeMapFactoryTest extends TestCase public function testFactoryWithConfig() : void { $container = $this->createMock(ContainerInterface::class); - $container->expects($this->once()) + $container->expects(self::once()) ->method('has') ->with('config') ->willReturn(true); - $container->expects($this->once()) + $container->expects(self::once()) ->method('get') ->with('config') ->willReturn([ @@ -37,28 +37,28 @@ public function testFactoryWithConfig() : void $factory = new TypeMapFactory(); $map = $factory->__invoke($container); - $this->assertSame(SimpleDocument::class, $map->className('a')); - $this->assertSame(SimpleDocument::class, $map->className('b')); - $this->assertSame(Document::class, $map->className('c')); - $this->assertSame(SimpleDocument::class, $map->className('d')); + self::assertSame(SimpleDocument::class, $map->className('a')); + self::assertSame(SimpleDocument::class, $map->className('b')); + self::assertSame(Document::class, $map->className('c')); + self::assertSame(SimpleDocument::class, $map->className('d')); } public function testFactoryWithoutConfig() : void { $container = $this->createMock(ContainerInterface::class); - $container->expects($this->once()) + $container->expects(self::once()) ->method('has') ->with('config') ->willReturn(false); - $container->expects($this->never()) + $container->expects(self::never()) ->method('get'); $factory = new TypeMapFactory(); $map = $factory->__invoke($container); - $this->assertSame(Document::class, $map->className('a')); - $this->assertSame(Document::class, $map->className('b')); - $this->assertSame(Document::class, $map->className('c')); - $this->assertSame(Document::class, $map->className('d')); + self::assertSame(Document::class, $map->className('a')); + self::assertSame(Document::class, $map->className('b')); + self::assertSame(Document::class, $map->className('c')); + self::assertSame(Document::class, $map->className('d')); } } diff --git a/test/Unit/ResultSet/TypeMapTest.php b/test/Unit/ResultSet/TypeMapTest.php index 88a49e6..5535a8a 100644 --- a/test/Unit/ResultSet/TypeMapTest.php +++ b/test/Unit/ResultSet/TypeMapTest.php @@ -16,7 +16,7 @@ class TypeMapTest extends TestCase public function testGivenAnyTypeTheDefaultWillBeReturned() : void { $map = new TypeMap([]); - $this->assertSame(Document::class, $map->className('whatever')); + self::assertSame(Document::class, $map->className('whatever')); } public function testGivenSpecificTypeTheCorrectClassWillBeReturned() : void @@ -25,14 +25,14 @@ public function testGivenSpecificTypeTheCorrectClassWillBeReturned() : void SimpleDocument::class => ['a', 'b'], ]); - $this->assertSame(SimpleDocument::class, $map->className('a')); - $this->assertSame(SimpleDocument::class, $map->className('b')); + self::assertSame(SimpleDocument::class, $map->className('a')); + self::assertSame(SimpleDocument::class, $map->className('b')); } public function testThatMappingCanBeString() : void { $map = new TypeMap([SimpleDocument::class => 'c']); - $this->assertSame(SimpleDocument::class, $map->className('c')); + self::assertSame(SimpleDocument::class, $map->className('c')); } public function testThatAnExceptionIsThrownWhenAClassDoesNotExist() : void diff --git a/test/Unit/Router/Container/DocumentResolverFactoryTest.php b/test/Unit/Router/Container/DocumentResolverFactoryTest.php index 51adf48..0b039bf 100644 --- a/test/Unit/Router/Container/DocumentResolverFactoryTest.php +++ b/test/Unit/Router/Container/DocumentResolverFactoryTest.php @@ -15,7 +15,7 @@ public function testFactory() : void { $container = $this->createMock(ContainerInterface::class); $api = $this->createMock(ApiClient::class); - $container->expects($this->exactly(2)) + $container->expects(self::exactly(2)) ->method('get') ->willReturnMap([ [ApiClient::class, $api], diff --git a/test/Unit/Router/Container/RouteMatcherFactoryTest.php b/test/Unit/Router/Container/RouteMatcherFactoryTest.php index d095f52..7f797fd 100644 --- a/test/Unit/Router/Container/RouteMatcherFactoryTest.php +++ b/test/Unit/Router/Container/RouteMatcherFactoryTest.php @@ -14,7 +14,7 @@ class RouteMatcherFactoryTest extends TestCase public function testFactory() : void { $container = $this->createMock(ContainerInterface::class); - $container->expects($this->exactly(2)) + $container->expects(self::exactly(2)) ->method('get') ->willReturnMap([ [RouteParams::class, RouteParams::fromArray([])], diff --git a/test/Unit/Router/Container/RouteParamsFactoryTest.php b/test/Unit/Router/Container/RouteParamsFactoryTest.php index fec6a3a..90bccfa 100644 --- a/test/Unit/Router/Container/RouteParamsFactoryTest.php +++ b/test/Unit/Router/Container/RouteParamsFactoryTest.php @@ -24,27 +24,27 @@ protected function setUp() : void public function testContainerWithoutConfigWillYieldParamsWithDefaultValues() : void { - $this->container->expects($this->once()) + $this->container->expects(self::once()) ->method('has') ->with('config') ->willReturn(false); - $this->container->expects($this->never()) + $this->container->expects(self::never()) ->method('get') ->with('config'); $params = $this->factory->__invoke($this->container); - $this->assertSame('document-id', $params->id()); + self::assertSame('document-id', $params->id()); } public function testContainerWithConfiguredParamsWillYieldParamsWithConfiguredValues() : void { - $this->container->expects($this->once()) + $this->container->expects(self::once()) ->method('has') ->with('config') ->willReturn(true); - $this->container->expects($this->once()) + $this->container->expects(self::once()) ->method('get') ->with('config') ->willReturn([ @@ -62,10 +62,10 @@ public function testContainerWithConfiguredParamsWillYieldParamsWithConfiguredVa ]); $params = $this->factory->__invoke($this->container); - $this->assertSame('a', $params->id()); - $this->assertSame('b', $params->uid()); - $this->assertSame('c', $params->type()); - $this->assertSame('d', $params->bookmark()); - $this->assertSame('e', $params->lang()); + self::assertSame('a', $params->id()); + self::assertSame('b', $params->uid()); + self::assertSame('c', $params->type()); + self::assertSame('d', $params->bookmark()); + self::assertSame('e', $params->lang()); } } diff --git a/test/Unit/Router/DocumentResolverTest.php b/test/Unit/Router/DocumentResolverTest.php index 5e46738..8ea611e 100644 --- a/test/Unit/Router/DocumentResolverTest.php +++ b/test/Unit/Router/DocumentResolverTest.php @@ -48,13 +48,13 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface public function testRouteResultWithoutMatchingParamsWillReturnNull() : void { $result = RouteResult::fromRoute(new Route('/foo', $this->middleware, ['GET']), []); - $this->assertNull($this->resolver->resolve($result)); + self::assertNull($this->resolver->resolve($result)); } public function testThatResultFromApiWillBeReturnedWhenBookmarkMatches() : void { $document = $this->createMock(Document::class); - $this->api->expects($this->once()) + $this->api->expects(self::once()) ->method('findByBookmark') ->with('bookmark-name') ->willReturn($document); @@ -64,13 +64,13 @@ public function testThatResultFromApiWillBeReturnedWhenBookmarkMatches() : void [$this->params->bookmark() => 'bookmark-name'] ); - $this->assertSame($document, $this->resolver->resolve($result)); + self::assertSame($document, $this->resolver->resolve($result)); } public function testThatResultFromApiWillBeReturnedWhenRouteMatchesDocumentId() : void { $document = $this->createMock(Document::class); - $this->api->expects($this->once()) + $this->api->expects(self::once()) ->method('findById') ->with('doc-id') ->willReturn($document); @@ -80,7 +80,7 @@ public function testThatResultFromApiWillBeReturnedWhenRouteMatchesDocumentId() [$this->params->id() => 'doc-id'] ); - $this->assertSame($document, $this->resolver->resolve($result)); + self::assertSame($document, $this->resolver->resolve($result)); } private function apiWillReturnSingleDocumentInLanguage(string $lang) : Document @@ -89,28 +89,28 @@ private function apiWillReturnSingleDocumentInLanguage(string $lang) : Document $query = $this->createMock(Query::class); $resultSet = $this->createMock(ResultSet::class); - $query->expects($this->once()) + $query->expects(self::once()) ->method('query') ->willReturnSelf(); - $query->expects($this->once()) + $query->expects(self::once()) ->method('lang') ->with($lang) ->willReturnSelf(); - $this->api->expects($this->once()) + $this->api->expects(self::once()) ->method('createQuery') ->willReturn($query); - $this->api->expects($this->once()) + $this->api->expects(self::once()) ->method('query') ->with($query) ->willReturn($resultSet); - $resultSet->expects($this->once()) + $resultSet->expects(self::once()) ->method('count') ->willReturn(1); - $resultSet->expects($this->once()) + $resultSet->expects(self::once()) ->method('first') ->willReturn($document); @@ -129,7 +129,7 @@ public function testThatResultFromApiIsReturnedWhenRouteMatchesTypeAndUid() : vo ] ); - $this->assertSame($document, $this->resolver->resolve($result)); + self::assertSame($document, $this->resolver->resolve($result)); } public function testThatLanguageIsProvidedToApiMethodWhenFoundInTheRouteParams() : void @@ -145,7 +145,7 @@ public function testThatLanguageIsProvidedToApiMethodWhenFoundInTheRouteParams() ] ); - $this->assertSame($document, $this->resolver->resolve($result)); + self::assertSame($document, $this->resolver->resolve($result)); } public function testThatTypeMustBeKnownInOrderToResolveByUid() : void @@ -169,7 +169,7 @@ public function testThatItIsPossibleToQueryOnASingleType() : void [$this->params->type() => 'type'] ); - $this->assertSame($document, $this->resolver->resolve($result)); + self::assertSame($document, $this->resolver->resolve($result)); } public function testThatItIsPossibleToQueryByTag() : void @@ -181,7 +181,7 @@ public function testThatItIsPossibleToQueryByTag() : void [$this->params->tag() => 'my-tag'] ); - $this->assertSame($document, $this->resolver->resolve($result)); + self::assertSame($document, $this->resolver->resolve($result)); } public function testAnExceptionIsThrownWhenAResultSetContainsMultipleResults() : void @@ -189,19 +189,19 @@ public function testAnExceptionIsThrownWhenAResultSetContainsMultipleResults() : $query = $this->createMock(Query::class); $resultSet = $this->createMock(ResultSet::class); - $query->expects($this->once()) + $query->expects(self::once()) ->method('query') ->willReturnSelf(); - $query->expects($this->once()) + $query->expects(self::once()) ->method('lang') ->with('*') ->willReturnSelf(); - $this->api->expects($this->once()) + $this->api->expects(self::once()) ->method('createQuery') ->willReturn($query); - $this->api->expects($this->once()) + $this->api->expects(self::once()) ->method('query') ->with($query) ->willReturn($resultSet); diff --git a/test/Unit/Router/RouteMatcherTest.php b/test/Unit/Router/RouteMatcherTest.php index 3adbaf9..8b618ad 100644 --- a/test/Unit/Router/RouteMatcherTest.php +++ b/test/Unit/Router/RouteMatcherTest.php @@ -48,13 +48,13 @@ private function matcher() : RouteMatcher public function testThatBookmarkedRouteIsNullWhenThereAreNoMatchingRoutes() : void { $matcher = $this->matcher(); - $this->assertNull($matcher->getBookmarkedRoute('anything')); + self::assertNull($matcher->getBookmarkedRoute('anything')); } public function testThatTypedRouteIsNullWhenThereAreNoMatchingRoutes() : void { $matcher = $this->matcher(); - $this->assertNull($matcher->getTypedRoute('any-type')); + self::assertNull($matcher->getTypedRoute('any-type')); } public function testThatTheRouteMatcherCanFindABookmarkedRoute() : void @@ -63,7 +63,7 @@ public function testThatTheRouteMatcherCanFindABookmarkedRoute() : void $bookmarkedRoute->setOptions(['defaults' => [$this->params->bookmark() => 'bookmark-name']]); $matcher = $this->matcher(); $route = $matcher->getBookmarkedRoute('bookmark-name'); - $this->assertSame($bookmarkedRoute, $route); + self::assertSame($bookmarkedRoute, $route); } public function testThatATypedRouteIsMatchedWhenTypeIsDefinedAsAString() : void @@ -72,7 +72,7 @@ public function testThatATypedRouteIsMatchedWhenTypeIsDefinedAsAString() : void $typedRoute->setOptions(['defaults' => [$this->params->type() => 'some-type']]); $matcher = $this->matcher(); $route = $matcher->getTypedRoute('some-type'); - $this->assertSame($typedRoute, $route); + self::assertSame($typedRoute, $route); } public function testThatATypedRouteIsMatchedWhenTheTypeIsDefinedAsAnArray() : void @@ -87,9 +87,9 @@ public function testThatATypedRouteIsMatchedWhenTheTypeIsDefinedAsAnArray() : vo ], ]); $matcher = $this->matcher(); - $this->assertSame($typedRoute, $matcher->getTypedRoute('some-type')); - $this->assertSame($typedRoute, $matcher->getTypedRoute('other-type')); - $this->assertNull($matcher->getTypedRoute('wrong-type')); + self::assertSame($typedRoute, $matcher->getTypedRoute('some-type')); + self::assertSame($typedRoute, $matcher->getTypedRoute('other-type')); + self::assertNull($matcher->getTypedRoute('wrong-type')); } public function testThatMatchingIsFifoByDefault() : void @@ -99,7 +99,7 @@ public function testThatMatchingIsFifoByDefault() : void $second = $this->collector->get('/other-path', $this->middleware, 'route-two'); $second->setOptions(['defaults' => [$this->params->type() => 'type']]); $matcher = $this->matcher(); - $this->assertSame($first, $matcher->getTypedRoute('type')); + self::assertSame($first, $matcher->getTypedRoute('type')); } public function testThatMultipleRoutesMatchingATypeCanBeFound() : void @@ -112,8 +112,8 @@ public function testThatMultipleRoutesMatchingATypeCanBeFound() : void $third->setOptions(['defaults' => []]); $matcher = $this->matcher(); $results = $matcher->routesMatchingType('type'); - $this->assertCount(2, $results); - $this->assertNotContains($third, $results); + self::assertCount(2, $results); + self::assertNotContains($third, $results); } public function testThatMultipleRoutesMatchingATagCanBeFound() : void @@ -126,8 +126,8 @@ public function testThatMultipleRoutesMatchingATagCanBeFound() : void $third->setOptions(['defaults' => [$this->params->tag() => 'b']]); $matcher = $this->matcher(); $results = $matcher->routesMatchingTag('a'); - $this->assertCount(2, $results); - $this->assertNotContains($third, $results); + self::assertCount(2, $results); + self::assertNotContains($third, $results); } public function testThatMatchingTagsIsCaseSensitive() : void @@ -139,17 +139,17 @@ public function testThatMatchingTagsIsCaseSensitive() : void $matcher = $this->matcher(); $results = $matcher->routesMatchingTag('a'); - $this->assertCount(1, $results); - $this->assertContains($first, $results); + self::assertCount(1, $results); + self::assertContains($first, $results); $results = $matcher->routesMatchingTag('A'); - $this->assertCount(1, $results); - $this->assertContains($second, $results); + self::assertCount(1, $results); + self::assertContains($second, $results); } public function testThatUidRouteIsNullWhenThereAreNoMatchingRoutes() : void { $matcher = $this->matcher(); - $this->assertNull($matcher->getUidRoute('foo', 'bar')); + self::assertNull($matcher->getUidRoute('foo', 'bar')); } public function testThatUidRouteIsNullWhenTypeMatchesButUidDoesNot() : void @@ -157,7 +157,7 @@ public function testThatUidRouteIsNullWhenTypeMatchesButUidDoesNot() : void $route = $this->collector->get('/some-path', $this->middleware, 'some-route'); $route->setOptions(['defaults' => [$this->params->type() => 'a']]); $matcher = $this->matcher(); - $this->assertNull($matcher->getUidRoute('a', 'bar')); + self::assertNull($matcher->getUidRoute('a', 'bar')); } public function testThatUidRouteMatches() : void @@ -165,7 +165,7 @@ public function testThatUidRouteMatches() : void $route = $this->collector->get('/some-path', $this->middleware, 'some-route'); $route->setOptions(['defaults' => [$this->params->type() => 'a', $this->params->uid() => 'bar']]); $matcher = $this->matcher(); - $this->assertSame($route, $matcher->getUidRoute('a', 'bar')); + self::assertSame($route, $matcher->getUidRoute('a', 'bar')); } /** @return mixed[] */ @@ -214,8 +214,8 @@ public function testBestMatch() : void private function assertBastMatch(string $name, ?Route $match) : void { - $this->assertNotNull($match, 'A match was not found'); - $this->assertSame($name, $match->getName()); + self::assertNotNull($match, 'A match was not found'); + self::assertSame($name, $match->getName()); } public function testRouteDefinitionWithInvalidTagParameterWillCauseException() : void diff --git a/test/Unit/Router/RouteParamsTest.php b/test/Unit/Router/RouteParamsTest.php index 899ccce..a7e63a1 100644 --- a/test/Unit/Router/RouteParamsTest.php +++ b/test/Unit/Router/RouteParamsTest.php @@ -29,37 +29,37 @@ public function testOptionsArray() : RouteParams /** @depends testOptionsArray */ public function testId(RouteParams $params) : void { - $this->assertSame('id', $params->id()); + self::assertSame('id', $params->id()); } /** @depends testOptionsArray */ public function testUid(RouteParams $params) : void { - $this->assertSame('uid', $params->uid()); + self::assertSame('uid', $params->uid()); } /** @depends testOptionsArray */ public function testType(RouteParams $params) : void { - $this->assertSame('type', $params->type()); + self::assertSame('type', $params->type()); } /** @depends testOptionsArray */ public function testBookmark(RouteParams $params) : void { - $this->assertSame('bookmark', $params->bookmark()); + self::assertSame('bookmark', $params->bookmark()); } /** @depends testOptionsArray */ public function testLang(RouteParams $params) : void { - $this->assertSame('lang', $params->lang()); + self::assertSame('lang', $params->lang()); } /** @depends testOptionsArray */ public function testReuseParams(RouteParams $params) : void { - $this->assertSame('reuse', $params->reuseResultParams()); + self::assertSame('reuse', $params->reuseResultParams()); } /** @return mixed[] */ From ab4415a25124a0596a91fbe8088a3e3fd33e3bed Mon Sep 17 00:00:00 2001 From: George Steel Date: Wed, 3 Mar 2021 11:39:32 +0000 Subject: [PATCH 2/4] Remove PHPCS customisations so that CS aligns with the adopted Doctrine standard --- phpcs.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index ea44a6b..ebb421e 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -15,12 +15,6 @@ - - - - - - From 729e97c8cf326a9197249dbf6945ecddf4ad332e Mon Sep 17 00:00:00 2001 From: George Steel Date: Wed, 3 Mar 2021 11:42:33 +0000 Subject: [PATCH 3/4] qa: updates whitespace according to changes to CS rules --- src/Cache/PrismicApiCache.php | 1 + src/ConfigProvider.php | 7 ++-- src/Container/ApiFactory.php | 3 +- src/Container/LinkResolverFactory.php | 3 +- .../StandardResultSetFactoryFactory.php | 3 +- src/Content/Document.php | 5 ++- src/Event/WebhookEvent.php | 11 ++--- src/Exception/ConfigurationError.php | 1 + src/Exception/InvalidArgument.php | 1 + src/Exception/PrimoError.php | 1 + src/Exception/RequestError.php | 9 ++-- src/Exception/RoutingError.php | 9 ++-- src/Exception/RuntimeError.php | 1 + src/Http/PrismicHttpClient.php | 1 + src/Http/PrismicHttpClientFactory.php | 3 +- src/LinkResolver.php | 11 ++--- .../Container/DocumentResolverFactory.php | 3 +- .../ExpiredPreviewHandlerFactory.php | 3 +- .../Container/InjectRequestCookiesFactory.php | 3 +- .../Container/PreviewCacheHeadersFactory.php | 3 +- .../Container/PreviewHandlerFactory.php | 3 +- .../Container/PrismicTemplateFactory.php | 3 +- .../Container/WebhookHandlerFactory.php | 5 ++- src/Middleware/DocumentResolver.php | 3 +- src/Middleware/ExpiredPreviewHandler.php | 3 +- src/Middleware/InjectRequestCookies.php | 3 +- src/Middleware/PreviewCacheHeaders.php | 3 +- src/Middleware/PreviewHandler.php | 3 +- src/Middleware/PrismicTemplate.php | 3 +- src/Middleware/WebhookHandler.php | 5 ++- .../HydratingResultSetFactoryFactory.php | 3 +- src/ResultSet/Container/TypeMapFactory.php | 3 +- src/ResultSet/HydratingResultSet.php | 3 +- src/ResultSet/HydratingResultSetFactory.php | 5 ++- src/ResultSet/TypeMap.php | 9 ++-- src/RouteProvider.php | 7 ++-- .../Container/DocumentResolverFactory.php | 3 +- src/Router/Container/RouteMatcherFactory.php | 3 +- src/Router/Container/RouteParamsFactory.php | 3 +- src/Router/DocumentResolver.php | 9 ++-- src/Router/RouteMatcher.php | 27 ++++++------ src/Router/RouteParams.php | 19 +++++---- src/Router/ScoredRoute.php | 5 ++- test/Unit/Asset/BadHierarchy.php | 1 + test/Unit/Asset/SimpleDocument.php | 1 + test/Unit/Container/ApiFactoryTest.php | 5 ++- .../Container/LinkResolverFactoryTest.php | 5 ++- .../StandardResultSetFactoryFactoryTest.php | 3 +- test/Unit/Event/WebhookEventTest.php | 3 +- .../Http/PrismicHttpClientFactoryTest.php | 9 ++-- .../Container/DocumentResolverFactoryTest.php | 3 +- .../ExpiredPreviewHandlerFactoryTest.php | 3 +- .../InjectRequestCookiesFactoryTest.php | 3 +- .../PreviewCacheHeadersFactoryTest.php | 3 +- .../Container/PreviewHandlerFactoryTest.php | 3 +- .../Container/PrismicTemplateFactoryTest.php | 3 +- .../Container/WebhookHandlerFactoryTest.php | 5 ++- test/Unit/Middleware/DocumentResolverTest.php | 11 ++--- .../Middleware/ExpiredPreviewHandlerTest.php | 9 ++-- .../Middleware/InjectRequestCookiesTest.php | 7 ++-- .../Middleware/PreviewCacheHeadersTest.php | 9 ++-- test/Unit/Middleware/PreviewHandlerTest.php | 15 +++---- test/Unit/Middleware/PrismicTemplateTest.php | 15 +++---- test/Unit/Middleware/WebhookHandlerTest.php | 15 +++---- .../HydratingResultSetFactoryFactoryTest.php | 3 +- .../Container/TypeMapFactoryTest.php | 5 ++- test/Unit/ResultSet/TypeMapTest.php | 11 ++--- .../Container/DocumentResolverFactoryTest.php | 3 +- .../Container/RouteMatcherFactoryTest.php | 3 +- .../Container/RouteParamsFactoryTest.php | 7 ++-- test/Unit/Router/DocumentResolverTest.php | 25 +++++------ test/Unit/Router/RouteMatcherTest.php | 41 ++++++++++--------- test/Unit/Router/RouteParamsTest.php | 21 +++++----- test/Unit/TestCase.php | 1 + 74 files changed, 270 insertions(+), 196 deletions(-) diff --git a/src/Cache/PrismicApiCache.php b/src/Cache/PrismicApiCache.php index 4b6fa12..7c3fc3c 100644 --- a/src/Cache/PrismicApiCache.php +++ b/src/Cache/PrismicApiCache.php @@ -1,4 +1,5 @@ [ @@ -48,7 +49,7 @@ public function __invoke() : array } /** @return mixed[] */ - private function dependencies() : array + private function dependencies(): array { return [ 'factories' => [ @@ -78,7 +79,7 @@ private function dependencies() : array } /** @return mixed[] */ - private function routing() : array + private function routing(): array { return [ 'params' => [ diff --git a/src/Container/ApiFactory.php b/src/Container/ApiFactory.php index 2bfd5cb..a9357de 100644 --- a/src/Container/ApiFactory.php +++ b/src/Container/ApiFactory.php @@ -1,4 +1,5 @@ has('config') ? $container->get('config') : []; $apiUrl = $config['prismic']['api'] ?? null; diff --git a/src/Container/LinkResolverFactory.php b/src/Container/LinkResolverFactory.php index a4b533f..b43a25f 100644 --- a/src/Container/LinkResolverFactory.php +++ b/src/Container/LinkResolverFactory.php @@ -1,4 +1,5 @@ get(RouteParams::class), diff --git a/src/Container/StandardResultSetFactoryFactory.php b/src/Container/StandardResultSetFactoryFactory.php index 5a0c389..3c417ab 100644 --- a/src/Container/StandardResultSetFactoryFactory.php +++ b/src/Container/StandardResultSetFactoryFactory.php @@ -1,4 +1,5 @@ data->content()->get($name); } /** @param string|int $name */ - public function has($name) : bool + public function has($name): bool { return $this->data->content()->has($name); } diff --git a/src/Event/WebhookEvent.php b/src/Event/WebhookEvent.php index 6b86837..864b084 100644 --- a/src/Event/WebhookEvent.php +++ b/src/Event/WebhookEvent.php @@ -1,4 +1,5 @@ received = time(); } - public static function new(object $payload) : self + public static function new(object $payload): self { return new static($payload); } - public function received() : DateTimeImmutable + public function received(): DateTimeImmutable { return DateTimeImmutable::createFromFormat('U', (string) $this->received, new DateTimeZone('UTC')); } - public function payload() : object + public function payload(): object { return $this->payload; } - public function serialize() : string + public function serialize(): string { return Json::encode([ 'received' => $this->received, @@ -47,7 +48,7 @@ public function serialize() : string } /** @param mixed $serialized */ - public function unserialize($serialized) : void + public function unserialize($serialized): void { $object = Json::decodeObject($serialized); $this->payload = $object->payload; diff --git a/src/Exception/ConfigurationError.php b/src/Exception/ConfigurationError.php index 9d81c8a..805c5e5 100644 --- a/src/Exception/ConfigurationError.php +++ b/src/Exception/ConfigurationError.php @@ -1,4 +1,5 @@ request = $request; @@ -21,7 +22,7 @@ public static function withRequest(RequestInterface $request, string $message, i return $error; } - public static function withMissingRouteResult(RequestInterface $request) : self + public static function withMissingRouteResult(RequestInterface $request): self { $message = sprintf( 'The request for %s failed because the route result was not available. This means that routing has ' . @@ -32,7 +33,7 @@ public static function withMissingRouteResult(RequestInterface $request) : self return self::withRequest($request, $message, 500); } - public static function withMissingTemplateAttribute(RequestInterface $request, string $expectedTemplateAttribute) : self + public static function withMissingTemplateAttribute(RequestInterface $request, string $expectedTemplateAttribute): self { $message = sprintf( 'The request for "%s" failed because there was no template attribute found in the request. I was ' . @@ -44,7 +45,7 @@ public static function withMissingTemplateAttribute(RequestInterface $request, s return self::withRequest($request, $message, 500); } - public function getRequest() :? RequestInterface + public function getRequest(): ?RequestInterface { return $this->request; } diff --git a/src/Exception/RoutingError.php b/src/Exception/RoutingError.php index 005e715..b463610 100644 --- a/src/Exception/RoutingError.php +++ b/src/Exception/RoutingError.php @@ -1,4 +1,5 @@ getMatchedRouteName(); return $routeName ?: '[Unnamed Route]'; } - protected static function matchedParams(RouteResult $routeResult) : string + protected static function matchedParams(RouteResult $routeResult): string { return json_encode($routeResult->getMatchedParams(), JSON_THROW_ON_ERROR); } diff --git a/src/Exception/RuntimeError.php b/src/Exception/RuntimeError.php index ff723a4..318a7c8 100644 --- a/src/Exception/RuntimeError.php +++ b/src/Exception/RuntimeError.php @@ -1,4 +1,5 @@ has(ClientInterface::class)) { return $container->get(ClientInterface::class); diff --git a/src/LinkResolver.php b/src/LinkResolver.php index 556c940..6a68dfe 100644 --- a/src/LinkResolver.php +++ b/src/LinkResolver.php @@ -1,4 +1,5 @@ urlHelper = $urlHelper; } - public function resolve(Link $link) :? string + public function resolve(Link $link): ?string { if ($link instanceof UrlLink) { return $link->url(); @@ -46,7 +47,7 @@ public function resolve(Link $link) :? string return null; } - private function resolveDocumentLink(DocumentLink $link) :? string + private function resolveDocumentLink(DocumentLink $link): ?string { if ($link->isBroken()) { return null; @@ -67,7 +68,7 @@ private function resolveDocumentLink(DocumentLink $link) :? string } /** @return string[] */ - private function routeParams(DocumentLink $link) : array + private function routeParams(DocumentLink $link): array { /** * You cannot use tags to construct a url from scratch because there is no way of knowing which @@ -82,7 +83,7 @@ private function routeParams(DocumentLink $link) : array ]; } - private function bookmarkNameByDocumentId(string $id) :? string + private function bookmarkNameByDocumentId(string $id): ?string { foreach ($this->bookmarks as $bookmark) { if ($bookmark->documentId() === $id) { @@ -93,7 +94,7 @@ private function bookmarkNameByDocumentId(string $id) :? string return null; } - private function url(DocumentLink $link, Route $route) : string + private function url(DocumentLink $link, Route $route): string { $options = $route->getOptions(); $reuseResultParams = $options['defaults'][$this->routeParams->reuseResultParams()] ?? true; diff --git a/src/Middleware/Container/DocumentResolverFactory.php b/src/Middleware/Container/DocumentResolverFactory.php index aeecdd8..8278c48 100644 --- a/src/Middleware/Container/DocumentResolverFactory.php +++ b/src/Middleware/Container/DocumentResolverFactory.php @@ -1,4 +1,5 @@ get(Resolver::class) diff --git a/src/Middleware/Container/ExpiredPreviewHandlerFactory.php b/src/Middleware/Container/ExpiredPreviewHandlerFactory.php index 2ef2d3d..ab979f4 100644 --- a/src/Middleware/Container/ExpiredPreviewHandlerFactory.php +++ b/src/Middleware/Container/ExpiredPreviewHandlerFactory.php @@ -1,4 +1,5 @@ has('config') ? $container->get('config') : []; diff --git a/src/Middleware/Container/InjectRequestCookiesFactory.php b/src/Middleware/Container/InjectRequestCookiesFactory.php index 81dbd12..8a766b0 100644 --- a/src/Middleware/Container/InjectRequestCookiesFactory.php +++ b/src/Middleware/Container/InjectRequestCookiesFactory.php @@ -1,4 +1,5 @@ get(ApiClient::class)); } diff --git a/src/Middleware/Container/PreviewCacheHeadersFactory.php b/src/Middleware/Container/PreviewCacheHeadersFactory.php index fd627b3..3369b76 100644 --- a/src/Middleware/Container/PreviewCacheHeadersFactory.php +++ b/src/Middleware/Container/PreviewCacheHeadersFactory.php @@ -1,4 +1,5 @@ get(ApiClient::class)); } diff --git a/src/Middleware/Container/PreviewHandlerFactory.php b/src/Middleware/Container/PreviewHandlerFactory.php index bdc88f1..de593c1 100644 --- a/src/Middleware/Container/PreviewHandlerFactory.php +++ b/src/Middleware/Container/PreviewHandlerFactory.php @@ -1,4 +1,5 @@ has('config') ? $container->get('config') : []; $defaultUrl = $config['primo']['previews']['defaultUrl'] ?? '/'; diff --git a/src/Middleware/Container/PrismicTemplateFactory.php b/src/Middleware/Container/PrismicTemplateFactory.php index 8cef337..524b99f 100644 --- a/src/Middleware/Container/PrismicTemplateFactory.php +++ b/src/Middleware/Container/PrismicTemplateFactory.php @@ -1,4 +1,5 @@ has('config') ? $container->get('config') : []; $templateAttribute = $config['primo']['templates']['templateAttribute'] diff --git a/src/Middleware/Container/WebhookHandlerFactory.php b/src/Middleware/Container/WebhookHandlerFactory.php index 0ea925f..9c7b39f 100644 --- a/src/Middleware/Container/WebhookHandlerFactory.php +++ b/src/Middleware/Container/WebhookHandlerFactory.php @@ -1,4 +1,5 @@ has('config') ? $container->get('config') : []; @@ -22,7 +23,7 @@ public function __invoke(ContainerInterface $container) : WebhookHandler ); } - private function assertEventDispatcher(ContainerInterface $container) : EventDispatcherInterface + private function assertEventDispatcher(ContainerInterface $container): EventDispatcherInterface { if ($container->has(EventDispatcherInterface::class)) { return $container->get(EventDispatcherInterface::class); diff --git a/src/Middleware/DocumentResolver.php b/src/Middleware/DocumentResolver.php index d913c4e..953acea 100644 --- a/src/Middleware/DocumentResolver.php +++ b/src/Middleware/DocumentResolver.php @@ -1,4 +1,5 @@ resolver = $resolver; } - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { // Get hold of the matched route (RouteResult) so we can inspect and resolve a document $routeResult = $request->getAttribute(RouteResult::class); diff --git a/src/Middleware/ExpiredPreviewHandler.php b/src/Middleware/ExpiredPreviewHandler.php index 1d1e09d..70717c2 100644 --- a/src/Middleware/ExpiredPreviewHandler.php +++ b/src/Middleware/ExpiredPreviewHandler.php @@ -1,4 +1,5 @@ redirectUrl = $redirectUrl; } - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { if (! $request->getAttribute(PreviewTokenExpired::class)) { return $handler->handle($request); diff --git a/src/Middleware/InjectRequestCookies.php b/src/Middleware/InjectRequestCookies.php index c1cc54c..d462eb7 100644 --- a/src/Middleware/InjectRequestCookies.php +++ b/src/Middleware/InjectRequestCookies.php @@ -1,4 +1,5 @@ api = $api; } - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $this->api->setRequestCookies($request->getCookieParams()); diff --git a/src/Middleware/PreviewCacheHeaders.php b/src/Middleware/PreviewCacheHeaders.php index 0694865..a0b2bd0 100644 --- a/src/Middleware/PreviewCacheHeaders.php +++ b/src/Middleware/PreviewCacheHeaders.php @@ -1,4 +1,5 @@ apiClient = $apiClient; } - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $response = $handler->handle($request); if ($response->getStatusCode() === 200 && $this->apiClient->inPreview()) { diff --git a/src/Middleware/PreviewHandler.php b/src/Middleware/PreviewHandler.php index b826290..a5d4271 100644 --- a/src/Middleware/PreviewHandler.php +++ b/src/Middleware/PreviewHandler.php @@ -1,4 +1,5 @@ defaultUrl = $defaultUrl; } - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $query = $request->getQueryParams(); if (! isset($query['token']) || empty($query['token'])) { diff --git a/src/Middleware/PrismicTemplate.php b/src/Middleware/PrismicTemplate.php index b268565..57bb0d3 100644 --- a/src/Middleware/PrismicTemplate.php +++ b/src/Middleware/PrismicTemplate.php @@ -1,4 +1,5 @@ templateAttribute = $templateAttribute; } - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $template = $request->getAttribute($this->templateAttribute); if (! $template) { diff --git a/src/Middleware/WebhookHandler.php b/src/Middleware/WebhookHandler.php index b5794de..8703043 100644 --- a/src/Middleware/WebhookHandler.php +++ b/src/Middleware/WebhookHandler.php @@ -1,4 +1,5 @@ expectedSecret = $expectedSecret; } - public function handle(ServerRequestInterface $request) : ResponseInterface + public function handle(ServerRequestInterface $request): ResponseInterface { $body = (string) $request->getBody(); @@ -48,7 +49,7 @@ public function handle(ServerRequestInterface $request) : ResponseInterface return new JsonResponse(['message' => 'Received'], 200); } - private function jsonError(string $errorMessage, int $statusCode) : ResponseInterface + private function jsonError(string $errorMessage, int $statusCode): ResponseInterface { return new JsonResponse(['error' => $errorMessage], $statusCode); } diff --git a/src/ResultSet/Container/HydratingResultSetFactoryFactory.php b/src/ResultSet/Container/HydratingResultSetFactoryFactory.php index 1140852..25a0b9f 100644 --- a/src/ResultSet/Container/HydratingResultSetFactoryFactory.php +++ b/src/ResultSet/Container/HydratingResultSetFactoryFactory.php @@ -1,4 +1,5 @@ get(TypeMap::class)); } diff --git a/src/ResultSet/Container/TypeMapFactory.php b/src/ResultSet/Container/TypeMapFactory.php index 4612135..1c5b2ea 100644 --- a/src/ResultSet/Container/TypeMapFactory.php +++ b/src/ResultSet/Container/TypeMapFactory.php @@ -1,4 +1,5 @@ has('config') ? $container->get('config') : []; $options = $config['primo']['typeMap'] ?? []; diff --git a/src/ResultSet/HydratingResultSet.php b/src/ResultSet/HydratingResultSet.php index 3aa8242..718ca2d 100644 --- a/src/ResultSet/HydratingResultSet.php +++ b/src/ResultSet/HydratingResultSet.php @@ -1,4 +1,5 @@ results = $results; } - public function merge(ResultSet $with) : ResultSet + public function merge(ResultSet $with): ResultSet { $results = array_merge($this->results, $with->results()); diff --git a/src/ResultSet/HydratingResultSetFactory.php b/src/ResultSet/HydratingResultSetFactory.php index 05b87f4..387dc0b 100644 --- a/src/ResultSet/HydratingResultSetFactory.php +++ b/src/ResultSet/HydratingResultSetFactory.php @@ -1,4 +1,5 @@ map = $map; } - public function withHttpResponse(ResponseInterface $response) : ResultSet + public function withHttpResponse(ResponseInterface $response): ResultSet { return $this->withJsonObject( Json::decodeObject((string) $response->getBody()) ); } - public function withJsonObject(object $data) : ResultSet + public function withJsonObject(object $data): ResultSet { $results = []; foreach ($data->results as $documentData) { diff --git a/src/ResultSet/TypeMap.php b/src/ResultSet/TypeMap.php index 4a5601a..0c0a24c 100644 --- a/src/ResultSet/TypeMap.php +++ b/src/ResultSet/TypeMap.php @@ -1,4 +1,5 @@ map[$type] ?? $this->default; } /** @param string[] $types */ - private function addTypes(string $className, array $types) : void + private function addTypes(string $className, array $types): void { foreach ($types as $type) { $this->addType($type, $className); } } - private function addType(string $type, string $class) : void + private function addType(string $type, string $class): void { $this->classHierarchyCheck($class); $this->map[$type] = $class; } - private function classHierarchyCheck(string $className) : void + private function classHierarchyCheck(string $className): void { if (! class_exists($className)) { throw new InvalidArgument(sprintf( diff --git a/src/RouteProvider.php b/src/RouteProvider.php index 75c8651..60b247a 100644 --- a/src/RouteProvider.php +++ b/src/RouteProvider.php @@ -1,4 +1,5 @@ configurePreviews($container, $application); $this->configureWebhooks($container, $application); } - private function configurePreviews(ContainerInterface $container, Application $app) : void + private function configurePreviews(ContainerInterface $container, Application $app): void { $config = $container->has('config') ? $container->get('config') : []; $previewUrl = $config['primo']['previews']['previewUrl'] ?? ConfigProvider::DEFAULT_PREVIEW_URL; @@ -27,7 +28,7 @@ private function configurePreviews(ContainerInterface $container, Application $a ]); } - private function configureWebhooks(ContainerInterface $container, Application $app) : void + private function configureWebhooks(ContainerInterface $container, Application $app): void { $config = $container->has('config') ? $container->get('config') : []; $options = $config['primo']['webhook']; diff --git a/src/Router/Container/DocumentResolverFactory.php b/src/Router/Container/DocumentResolverFactory.php index fb0365d..7eaf28a 100644 --- a/src/Router/Container/DocumentResolverFactory.php +++ b/src/Router/Container/DocumentResolverFactory.php @@ -1,4 +1,5 @@ get(ApiClient::class), diff --git a/src/Router/Container/RouteMatcherFactory.php b/src/Router/Container/RouteMatcherFactory.php index 258111f..e8f7b98 100644 --- a/src/Router/Container/RouteMatcherFactory.php +++ b/src/Router/Container/RouteMatcherFactory.php @@ -1,4 +1,5 @@ get(RouteParams::class), diff --git a/src/Router/Container/RouteParamsFactory.php b/src/Router/Container/RouteParamsFactory.php index cb3c4e1..feb07a9 100644 --- a/src/Router/Container/RouteParamsFactory.php +++ b/src/Router/Container/RouteParamsFactory.php @@ -1,4 +1,5 @@ has('config') ? $container->get('config') diff --git a/src/Router/DocumentResolver.php b/src/Router/DocumentResolver.php index 30626d9..3149236 100644 --- a/src/Router/DocumentResolver.php +++ b/src/Router/DocumentResolver.php @@ -1,4 +1,5 @@ resolveWithBookmark($routeResult); @@ -45,7 +46,7 @@ public function resolve(RouteResult $routeResult) :? Document return $document; } - private function resolveWithBookmark(RouteResult $routeResult) :? Document + private function resolveWithBookmark(RouteResult $routeResult): ?Document { $params = $routeResult->getMatchedParams(); $bookmark = $params[$this->routeParams->bookmark()] ?? null; @@ -57,7 +58,7 @@ private function resolveWithBookmark(RouteResult $routeResult) :? Document } /** @throws RoutingError */ - private function resolveWithParams(RouteResult $routeResult) :? Document + private function resolveWithParams(RouteResult $routeResult): ?Document { $params = $routeResult->getMatchedParams(); $type = $params[$this->routeParams->type()] ?? null; @@ -102,7 +103,7 @@ private function resolveWithParams(RouteResult $routeResult) :? Document return $resultSet->first(); } - private function resolveWithId(RouteResult $routeResult) :? Document + private function resolveWithId(RouteResult $routeResult): ?Document { $params = $routeResult->getMatchedParams(); $id = $params[$this->routeParams->id()] ?? null; diff --git a/src/Router/RouteMatcher.php b/src/Router/RouteMatcher.php index dfdcfef..0029d41 100644 --- a/src/Router/RouteMatcher.php +++ b/src/Router/RouteMatcher.php @@ -1,4 +1,5 @@ compare($b); }); @@ -80,7 +81,7 @@ public function bestMatch(string $id, string $type, ?string $uid, ?string $bookm return $this->routeMatchingId($id); } - public function getBookmarkedRoute(string $bookmark) :? Route + public function getBookmarkedRoute(string $bookmark): ?Route { foreach ($this->routes() as $route) { $options = $route->getOptions(); @@ -95,7 +96,7 @@ public function getBookmarkedRoute(string $bookmark) :? Route } /** @return Route[] */ - public function routesMatchingType(string $type) : iterable + public function routesMatchingType(string $type): iterable { $routes = []; foreach ($this->routes() as $route) { @@ -110,7 +111,7 @@ public function routesMatchingType(string $type) : iterable } /** @return Route[] */ - public function routesMatchingTag(string $tag) : iterable + public function routesMatchingTag(string $tag): iterable { $routes = []; foreach ($this->routes() as $route) { @@ -124,7 +125,7 @@ public function routesMatchingTag(string $tag) : iterable return $routes; } - public function getTypedRoute(string $type) :? Route + public function getTypedRoute(string $type): ?Route { foreach ($this->routes() as $route) { if ($this->matchesType($route, $type)) { @@ -135,7 +136,7 @@ public function getTypedRoute(string $type) :? Route return null; } - public function getUidRoute(string $type, string $uid) :? Route + public function getUidRoute(string $type, string $uid): ?Route { foreach ($this->routesMatchingType($type) as $route) { if ($this->matchesUid($route, $uid)) { @@ -146,7 +147,7 @@ public function getUidRoute(string $type, string $uid) :? Route return null; } - private function matchesType(Route $route, string $type) : bool + private function matchesType(Route $route, string $type): bool { $options = $route->getOptions(); $option = $options['defaults'][$this->params->type()] ?? []; @@ -157,13 +158,13 @@ private function matchesType(Route $route, string $type) : bool return is_string($option) && $option === $type; } - public function matchesTag(Route $route, string $tag) : bool + public function matchesTag(Route $route, string $tag): bool { return in_array($tag, $this->wantsTag($route), true); } /** @return string[] */ - private function wantsTag(Route $route) : array + private function wantsTag(Route $route): array { $options = $route->getOptions(); $tags = $options['defaults'][$this->params->tag()] ?? null; @@ -184,7 +185,7 @@ private function wantsTag(Route $route) : array return $tags; } - private function matchesUid(Route $route, string $uid) : bool + private function matchesUid(Route $route, string $uid): bool { $options = $route->getOptions(); $option = $options['defaults'][$this->params->uid()] ?? null; @@ -192,7 +193,7 @@ private function matchesUid(Route $route, string $uid) : bool return $option === $uid; } - private function routeMatchingId(string $id) :? Route + private function routeMatchingId(string $id): ?Route { foreach ($this->routes() as $route) { $options = $route->getOptions(); @@ -206,7 +207,7 @@ private function routeMatchingId(string $id) :? Route } /** @return Route[] */ - private function routes() : iterable + private function routes(): iterable { return $this->collector->getRoutes(); } diff --git a/src/Router/RouteParams.php b/src/Router/RouteParams.php index 62e063a..75f2da4 100644 --- a/src/Router/RouteParams.php +++ b/src/Router/RouteParams.php @@ -1,4 +1,5 @@ $value) { @@ -43,7 +44,7 @@ public static function fromArray(array $options) : self return $params; } - private function setParameter(string $name, string $value) : void + private function setParameter(string $name, string $value): void { if (! in_array($name, self::$acceptable, true)) { throw new InvalidArgument(sprintf( @@ -56,37 +57,37 @@ private function setParameter(string $name, string $value) : void $this->{$name} = $value; } - public function id() : string + public function id(): string { return $this->id; } - public function uid() : string + public function uid(): string { return $this->uid; } - public function type() : string + public function type(): string { return $this->type; } - public function bookmark() : string + public function bookmark(): string { return $this->bookmark; } - public function lang() : string + public function lang(): string { return $this->lang; } - public function reuseResultParams() : string + public function reuseResultParams(): string { return $this->reuseResultParams; } - public function tag() : string + public function tag(): string { return $this->tag; } diff --git a/src/Router/ScoredRoute.php b/src/Router/ScoredRoute.php index a3117dd..6a0d9cb 100644 --- a/src/Router/ScoredRoute.php +++ b/src/Router/ScoredRoute.php @@ -1,4 +1,5 @@ score = $score; } - public function route() : Route + public function route(): Route { return $this->route; } - public function compare(self $other) : int + public function compare(self $other): int { return $this->score <=> $other->score; } diff --git a/test/Unit/Asset/BadHierarchy.php b/test/Unit/Asset/BadHierarchy.php index 73dafe1..276cd91 100644 --- a/test/Unit/Asset/BadHierarchy.php +++ b/test/Unit/Asset/BadHierarchy.php @@ -1,4 +1,5 @@ createMock(ContainerInterface::class); $container->expects(self::once()) @@ -30,7 +31,7 @@ public function testAnExceptionIsThrownWhenAnApiUrlHasNotBeenConfigured() : void $factory->__invoke($container); } - public function testFactoryWithNoDependenciesSatisfied() : void + public function testFactoryWithNoDependenciesSatisfied(): void { $container = $this->createMock(ContainerInterface::class); $container->expects(self::exactly(6)) diff --git a/test/Unit/Container/LinkResolverFactoryTest.php b/test/Unit/Container/LinkResolverFactoryTest.php index 6895b41..f4f5a07 100644 --- a/test/Unit/Container/LinkResolverFactoryTest.php +++ b/test/Unit/Container/LinkResolverFactoryTest.php @@ -1,4 +1,5 @@ __invoke($this->createMock(ContainerInterface::class)); diff --git a/test/Unit/Event/WebhookEventTest.php b/test/Unit/Event/WebhookEventTest.php index d5ef317..5866a6b 100644 --- a/test/Unit/Event/WebhookEventTest.php +++ b/test/Unit/Event/WebhookEventTest.php @@ -1,4 +1,5 @@ foo = 'baz'; diff --git a/test/Unit/Http/PrismicHttpClientFactoryTest.php b/test/Unit/Http/PrismicHttpClientFactoryTest.php index 82823d2..3602046 100644 --- a/test/Unit/Http/PrismicHttpClientFactoryTest.php +++ b/test/Unit/Http/PrismicHttpClientFactoryTest.php @@ -1,4 +1,5 @@ container = $this->createMock(ContainerInterface::class); } - private function clientInContainer(bool $value) : void + private function clientInContainer(bool $value): void { $this->container->expects(self::once()) ->method('has') @@ -28,7 +29,7 @@ private function clientInContainer(bool $value) : void ->willReturn($value); } - public function testThatClientInContainerWillBeReturnedWhenAvailable() : void + public function testThatClientInContainerWillBeReturnedWhenAvailable(): void { $client = $this->createMock(ClientInterface::class); $this->clientInContainer(true); @@ -42,7 +43,7 @@ public function testThatClientInContainerWillBeReturnedWhenAvailable() : void self::assertSame($client, $factory($this->container)); } - public function testThatClientDiscoveryWillBeUsedWhenNoClientIsInTheContainer() : void + public function testThatClientDiscoveryWillBeUsedWhenNoClientIsInTheContainer(): void { $this->clientInContainer(false); $this->container->expects(self::never())->method('get'); diff --git a/test/Unit/Middleware/Container/DocumentResolverFactoryTest.php b/test/Unit/Middleware/Container/DocumentResolverFactoryTest.php index 264c724..d318c0c 100644 --- a/test/Unit/Middleware/Container/DocumentResolverFactoryTest.php +++ b/test/Unit/Middleware/Container/DocumentResolverFactoryTest.php @@ -1,4 +1,5 @@ createMock(DocumentResolver::class); $container = $this->createMock(ContainerInterface::class); diff --git a/test/Unit/Middleware/Container/ExpiredPreviewHandlerFactoryTest.php b/test/Unit/Middleware/Container/ExpiredPreviewHandlerFactoryTest.php index c2be2bf..5407b65 100644 --- a/test/Unit/Middleware/Container/ExpiredPreviewHandlerFactoryTest.php +++ b/test/Unit/Middleware/Container/ExpiredPreviewHandlerFactoryTest.php @@ -1,4 +1,5 @@ createMock(ContainerInterface::class); $container->expects(self::once()) diff --git a/test/Unit/Middleware/Container/InjectRequestCookiesFactoryTest.php b/test/Unit/Middleware/Container/InjectRequestCookiesFactoryTest.php index 742ff4a..367e47d 100644 --- a/test/Unit/Middleware/Container/InjectRequestCookiesFactoryTest.php +++ b/test/Unit/Middleware/Container/InjectRequestCookiesFactoryTest.php @@ -1,4 +1,5 @@ createMock(ApiClient::class); $container = $this->createMock(ContainerInterface::class); diff --git a/test/Unit/Middleware/Container/PreviewCacheHeadersFactoryTest.php b/test/Unit/Middleware/Container/PreviewCacheHeadersFactoryTest.php index 9a036de..2222f1d 100644 --- a/test/Unit/Middleware/Container/PreviewCacheHeadersFactoryTest.php +++ b/test/Unit/Middleware/Container/PreviewCacheHeadersFactoryTest.php @@ -1,4 +1,5 @@ createMock(ContainerInterface::class); $container->expects(self::once()) diff --git a/test/Unit/Middleware/Container/PreviewHandlerFactoryTest.php b/test/Unit/Middleware/Container/PreviewHandlerFactoryTest.php index 0f1a2e2..b907f3c 100644 --- a/test/Unit/Middleware/Container/PreviewHandlerFactoryTest.php +++ b/test/Unit/Middleware/Container/PreviewHandlerFactoryTest.php @@ -1,4 +1,5 @@ createMock(ContainerInterface::class); $container->expects(self::once()) diff --git a/test/Unit/Middleware/Container/PrismicTemplateFactoryTest.php b/test/Unit/Middleware/Container/PrismicTemplateFactoryTest.php index d945a7c..91ab383 100644 --- a/test/Unit/Middleware/Container/PrismicTemplateFactoryTest.php +++ b/test/Unit/Middleware/Container/PrismicTemplateFactoryTest.php @@ -1,4 +1,5 @@ createMock(ContainerInterface::class); $container->expects(self::once()) diff --git a/test/Unit/Middleware/Container/WebhookHandlerFactoryTest.php b/test/Unit/Middleware/Container/WebhookHandlerFactoryTest.php index 5e0028f..159fb35 100644 --- a/test/Unit/Middleware/Container/WebhookHandlerFactoryTest.php +++ b/test/Unit/Middleware/Container/WebhookHandlerFactoryTest.php @@ -1,4 +1,5 @@ createMock(ContainerInterface::class); $container->expects(self::exactly(2)) @@ -28,7 +29,7 @@ public function testThatAnExceptionIsThrownWhenNoEventDispatcherIsAvailable() : $factory->__invoke($container); } - public function testFactoryWhenDispatcherCanBeFound() : void + public function testFactoryWhenDispatcherCanBeFound(): void { $container = $this->createMock(ContainerInterface::class); $container->expects(self::exactly(2)) diff --git a/test/Unit/Middleware/DocumentResolverTest.php b/test/Unit/Middleware/DocumentResolverTest.php index 9c96f4b..02cbf8a 100644 --- a/test/Unit/Middleware/DocumentResolverTest.php +++ b/test/Unit/Middleware/DocumentResolverTest.php @@ -1,4 +1,5 @@ request = Psr17FactoryDiscovery::findServerRequestFactory()->createServerRequest('GET', '/foo'); @@ -41,7 +42,7 @@ protected function setUp() : void /** @var ServerRequestInterface */ public $lastRequest; - public function handle(ServerRequestInterface $request) : ResponseInterface + public function handle(ServerRequestInterface $request): ResponseInterface { $this->lastRequest = $request; @@ -54,7 +55,7 @@ public function handle(ServerRequestInterface $request) : ResponseInterface ->willReturn(DateTimeImmutable::createFromFormat('!Y-m-d', '2020-01-01', new DateTimeZone('UTC'))); } - public function testAnExceptionIsThrownWhenThereIsNoRouteResultAvailable() : void + public function testAnExceptionIsThrownWhenThereIsNoRouteResultAvailable(): void { $subject = new DocumentResolver($this->resolver); $this->expectException(RequestError::class); @@ -62,7 +63,7 @@ public function testAnExceptionIsThrownWhenThereIsNoRouteResultAvailable() : voi $subject->process($this->request, $this->handler); } - public function testThatGivenADocumentCanBeResolvedTheDocumentIsInjectedToRequestAttributes() : ResponseInterface + public function testThatGivenADocumentCanBeResolvedTheDocumentIsInjectedToRequestAttributes(): ResponseInterface { $this->resolver->method('resolve')->with($this->routeResult)->willReturn( $this->document @@ -77,7 +78,7 @@ public function testThatGivenADocumentCanBeResolvedTheDocumentIsInjectedToReques return $response; } - public function testThatRequestAttributeIsNotPresentWhenADocumentCannotBeResolved() : void + public function testThatRequestAttributeIsNotPresentWhenADocumentCannotBeResolved(): void { $this->resolver->method('resolve')->with($this->routeResult)->willReturn(null); diff --git a/test/Unit/Middleware/ExpiredPreviewHandlerTest.php b/test/Unit/Middleware/ExpiredPreviewHandlerTest.php index 21e051f..444c620 100644 --- a/test/Unit/Middleware/ExpiredPreviewHandlerTest.php +++ b/test/Unit/Middleware/ExpiredPreviewHandlerTest.php @@ -1,4 +1,5 @@ request = Psr17FactoryDiscovery::findServerRequestFactory()->createServerRequest('GET', '/foo'); @@ -30,7 +31,7 @@ protected function setUp() : void /** @var ServerRequestInterface */ public $lastRequest; - public function handle(ServerRequestInterface $request) : ResponseInterface + public function handle(ServerRequestInterface $request): ResponseInterface { $this->lastRequest = $request; @@ -40,13 +41,13 @@ public function handle(ServerRequestInterface $request) : ResponseInterface $this->subject = new ExpiredPreviewHandler('/go-here'); } - public function testThatMiddlewareIsNoOpByDefault() : void + public function testThatMiddlewareIsNoOpByDefault(): void { $response = $this->subject->process($this->request, $this->handler); self::assertSame('Boom', (string) $response->getBody()); } - public function testThatResponseIsRedirectWithCookieWhenExpiryErrorIsPresent() : void + public function testThatResponseIsRedirectWithCookieWhenExpiryErrorIsPresent(): void { $error = new PreviewTokenExpired('Bad News'); $request = $this->request->withAttribute(PreviewTokenExpired::class, $error); diff --git a/test/Unit/Middleware/InjectRequestCookiesTest.php b/test/Unit/Middleware/InjectRequestCookiesTest.php index 3542dba..e24ae5a 100644 --- a/test/Unit/Middleware/InjectRequestCookiesTest.php +++ b/test/Unit/Middleware/InjectRequestCookiesTest.php @@ -1,4 +1,5 @@ api = Api::get('https://www.example.com', null, new Client()); $this->subject = new InjectRequestCookies($this->api); $this->handler = new class () implements RequestHandlerInterface { - public function handle(ServerRequestInterface $request) : ResponseInterface + public function handle(ServerRequestInterface $request): ResponseInterface { return new TextResponse('Hey!'); } }; } - public function testThatRequestCookiesAreProvidedToTheApi() : void + public function testThatRequestCookiesAreProvidedToTheApi(): void { self::assertFalse($this->api->inPreview()); $request = Psr17FactoryDiscovery::findServerRequestFactory()->createServerRequest('GET', '/foo'); diff --git a/test/Unit/Middleware/PreviewCacheHeadersTest.php b/test/Unit/Middleware/PreviewCacheHeadersTest.php index ba0ce6e..b63e407 100644 --- a/test/Unit/Middleware/PreviewCacheHeadersTest.php +++ b/test/Unit/Middleware/PreviewCacheHeadersTest.php @@ -1,4 +1,5 @@ request = Psr17FactoryDiscovery::findServerRequestFactory()->createServerRequest('GET', '/foo'); $this->handler = new class () implements RequestHandlerInterface { - public function handle(ServerRequestInterface $request) : ResponseInterface + public function handle(ServerRequestInterface $request): ResponseInterface { return new TextResponse('Boom'); } @@ -38,7 +39,7 @@ public function handle(ServerRequestInterface $request) : ResponseInterface $this->subject = new PreviewCacheHeaders($this->api); } - public function testThatNoCacheControlHeaderIsSetWhenPreviewIsNotActive() : void + public function testThatNoCacheControlHeaderIsSetWhenPreviewIsNotActive(): void { $this->api->method('inPreview')->willReturn(false); $response = $this->subject->process($this->request, $this->handler); @@ -46,7 +47,7 @@ public function testThatNoCacheControlHeaderIsSetWhenPreviewIsNotActive() : void self::assertEmpty($response->getHeader('Cache-Control')); } - public function testThatCacheControlHeaderIsSetWhenPreviewIsActive() : void + public function testThatCacheControlHeaderIsSetWhenPreviewIsActive(): void { $this->api->method('inPreview')->willReturn(true); $response = $this->subject->process($this->request, $this->handler); diff --git a/test/Unit/Middleware/PreviewHandlerTest.php b/test/Unit/Middleware/PreviewHandlerTest.php index 7a45d6a..afad9c5 100644 --- a/test/Unit/Middleware/PreviewHandlerTest.php +++ b/test/Unit/Middleware/PreviewHandlerTest.php @@ -1,4 +1,5 @@ request = Psr17FactoryDiscovery::findServerRequestFactory()->createServerRequest('GET', '/foo'); @@ -38,7 +39,7 @@ protected function setUp() : void /** @var ServerRequestInterface */ public $lastRequest; - public function handle(ServerRequestInterface $request) : ResponseInterface + public function handle(ServerRequestInterface $request): ResponseInterface { $this->lastRequest = $request; @@ -50,14 +51,14 @@ public function handle(ServerRequestInterface $request) : ResponseInterface $this->subject = new PreviewHandler($this->api, $this->linkResolver, '/go-here'); } - public function testThatWhenTheTokenIsEmptyNoRedirectWillOccur() : void + public function testThatWhenTheTokenIsEmptyNoRedirectWillOccur(): void { self::assertEmpty($this->request->getQueryParams()); $response = $this->subject->process($this->request, $this->handler); self::assertSame('Boom', (string) $response->getBody()); } - public function testThatWhenTheTokenIsInvalidNoRedirectWillOccur() : void + public function testThatWhenTheTokenIsInvalidNoRedirectWillOccur(): void { $token = 'expected-token'; $request = $this->request->withQueryParams(['token' => $token]); @@ -70,7 +71,7 @@ public function testThatWhenTheTokenIsInvalidNoRedirectWillOccur() : void self::assertSame('Boom', (string) $response->getBody()); } - public function testThatWhenTheTokenHasExpiredNoRedirectOccursAndRequestAttributeIsGiven() : void + public function testThatWhenTheTokenHasExpiredNoRedirectOccursAndRequestAttributeIsGiven(): void { $token = 'expected-token'; $request = $this->request->withQueryParams(['token' => $token]); @@ -87,7 +88,7 @@ public function testThatWhenTheTokenHasExpiredNoRedirectOccursAndRequestAttribut self::assertSame($error, $this->handler->lastRequest->getAttribute(PreviewTokenExpired::class)); } - public function testThatTheRedirectWillBeTheDefaultUrlWhenTheApiDoesNotReturnALink() : void + public function testThatTheRedirectWillBeTheDefaultUrlWhenTheApiDoesNotReturnALink(): void { $token = 'expected-token'; $request = $this->request->withQueryParams(['token' => $token]); @@ -98,7 +99,7 @@ public function testThatTheRedirectWillBeTheDefaultUrlWhenTheApiDoesNotReturnALi self::assertMessageHasHeader($response, 'location', '/go-here'); } - public function testThatTheRedirectWillBeDeterminedByLinkResolver() : void + public function testThatTheRedirectWillBeDeterminedByLinkResolver(): void { $token = 'expected-token'; $request = $this->request->withQueryParams(['token' => $token]); diff --git a/test/Unit/Middleware/PrismicTemplateTest.php b/test/Unit/Middleware/PrismicTemplateTest.php index f4d1862..3609009 100644 --- a/test/Unit/Middleware/PrismicTemplateTest.php +++ b/test/Unit/Middleware/PrismicTemplateTest.php @@ -1,4 +1,5 @@ templates = $this->createMock(TemplateRendererInterface::class); @@ -39,7 +40,7 @@ protected function setUp() : void /** @var ServerRequestInterface */ public $lastRequest; - public function handle(ServerRequestInterface $request) : ResponseInterface + public function handle(ServerRequestInterface $request): ResponseInterface { $this->lastRequest = $request; @@ -48,19 +49,19 @@ public function handle(ServerRequestInterface $request) : ResponseInterface }; } - public function testThatTheTemplateMustBeKnownInAdvance() : void + public function testThatTheTemplateMustBeKnownInAdvance(): void { $this->expectException(RequestError::class); $this->expectExceptionMessage('The request for "/foo" failed because there was no template attribute found in the request'); $this->subject->process($this->request, $this->handler); } - private function requestHasTemplate() : ServerRequestInterface + private function requestHasTemplate(): ServerRequestInterface { return $this->request->withAttribute('template', 'template::foo'); } - public function testThatRequestIsDelegatedWhenADocumentIsNotFound() : void + public function testThatRequestIsDelegatedWhenADocumentIsNotFound(): void { $request = $this->requestHasTemplate(); self::assertNull($this->handler->lastRequest); @@ -70,14 +71,14 @@ public function testThatRequestIsDelegatedWhenADocumentIsNotFound() : void self::assertSame($request, $this->handler->lastRequest); } - private function requestHasDocument() : ServerRequestInterface + private function requestHasDocument(): ServerRequestInterface { $request = $this->requestHasTemplate(); return $request->withAttribute(Document::class, $this->document); } - public function testThatTheTemplateWillBeRenderedWhenRequestCriteriaAreMet() : void + public function testThatTheTemplateWillBeRenderedWhenRequestCriteriaAreMet(): void { $this->templates->expects(self::once()) ->method('addDefaultParam') diff --git a/test/Unit/Middleware/WebhookHandlerTest.php b/test/Unit/Middleware/WebhookHandlerTest.php index 1fa137e..fe6ba2b 100644 --- a/test/Unit/Middleware/WebhookHandlerTest.php +++ b/test/Unit/Middleware/WebhookHandlerTest.php @@ -1,4 +1,5 @@ events = $this->createMock(EventDispatcherInterface::class); @@ -27,13 +28,13 @@ protected function setUp() : void $this->subject = new WebhookHandler($this->events, 'secret'); } - public function testAnEmptyRequestBodyIsABadRequest() : void + public function testAnEmptyRequestBodyIsABadRequest(): void { $response = $this->subject->handle($this->request); self::assertResponseHasStatus($response, 400); } - public function testAnInvalidPayloadIsABadRequest() : void + public function testAnInvalidPayloadIsABadRequest(): void { $stream = Psr17FactoryDiscovery::findStreamFactory()->createStream('Not JSON'); $request = $this->request->withBody($stream); @@ -42,7 +43,7 @@ public function testAnInvalidPayloadIsABadRequest() : void } /** @return mixed[] */ - public function theWrongSecret() : iterable + public function theWrongSecret(): iterable { return [ 'Missing Secret' => ['{"not-defined":"foo"}'], @@ -51,7 +52,7 @@ public function theWrongSecret() : iterable } /** @dataProvider theWrongSecret */ - public function testUnsuccessfulSecrets(string $body) : void + public function testUnsuccessfulSecrets(string $body): void { $stream = Psr17FactoryDiscovery::findStreamFactory()->createStream($body); $request = $this->request->withBody($stream); @@ -59,7 +60,7 @@ public function testUnsuccessfulSecrets(string $body) : void self::assertResponseHasStatus($response, 400); } - public function testPayloadWithTheCorrectSecretIsSuccessful() : void + public function testPayloadWithTheCorrectSecretIsSuccessful(): void { $body = '{"secret":"secret"}'; $stream = Psr17FactoryDiscovery::findStreamFactory()->createStream($body); @@ -69,7 +70,7 @@ public function testPayloadWithTheCorrectSecretIsSuccessful() : void } /** @dataProvider theWrongSecret */ - public function testPayloadIsSuccessfulWhenSecretIsNotRequired(string $body) : void + public function testPayloadIsSuccessfulWhenSecretIsNotRequired(string $body): void { $subject = new WebhookHandler($this->events, null); $stream = Psr17FactoryDiscovery::findStreamFactory()->createStream($body); diff --git a/test/Unit/ResultSet/Container/HydratingResultSetFactoryFactoryTest.php b/test/Unit/ResultSet/Container/HydratingResultSetFactoryFactoryTest.php index b91848f..804cf95 100644 --- a/test/Unit/ResultSet/Container/HydratingResultSetFactoryFactoryTest.php +++ b/test/Unit/ResultSet/Container/HydratingResultSetFactoryFactoryTest.php @@ -1,4 +1,5 @@ createMock(ContainerInterface::class); diff --git a/test/Unit/ResultSet/Container/TypeMapFactoryTest.php b/test/Unit/ResultSet/Container/TypeMapFactoryTest.php index a54f625..3dc0ac3 100644 --- a/test/Unit/ResultSet/Container/TypeMapFactoryTest.php +++ b/test/Unit/ResultSet/Container/TypeMapFactoryTest.php @@ -1,4 +1,5 @@ createMock(ContainerInterface::class); $container->expects(self::once()) @@ -43,7 +44,7 @@ public function testFactoryWithConfig() : void self::assertSame(SimpleDocument::class, $map->className('d')); } - public function testFactoryWithoutConfig() : void + public function testFactoryWithoutConfig(): void { $container = $this->createMock(ContainerInterface::class); $container->expects(self::once()) diff --git a/test/Unit/ResultSet/TypeMapTest.php b/test/Unit/ResultSet/TypeMapTest.php index 5535a8a..326a579 100644 --- a/test/Unit/ResultSet/TypeMapTest.php +++ b/test/Unit/ResultSet/TypeMapTest.php @@ -1,4 +1,5 @@ className('whatever')); } - public function testGivenSpecificTypeTheCorrectClassWillBeReturned() : void + public function testGivenSpecificTypeTheCorrectClassWillBeReturned(): void { $map = new TypeMap([ SimpleDocument::class => ['a', 'b'], @@ -29,13 +30,13 @@ public function testGivenSpecificTypeTheCorrectClassWillBeReturned() : void self::assertSame(SimpleDocument::class, $map->className('b')); } - public function testThatMappingCanBeString() : void + public function testThatMappingCanBeString(): void { $map = new TypeMap([SimpleDocument::class => 'c']); self::assertSame(SimpleDocument::class, $map->className('c')); } - public function testThatAnExceptionIsThrownWhenAClassDoesNotExist() : void + public function testThatAnExceptionIsThrownWhenAClassDoesNotExist(): void { $this->expectException(InvalidArgument::class); $this->expectExceptionMessage('The target class "Primo\UnknownClass" does not exist. Please create it or check your document type mapping configuration.'); @@ -45,7 +46,7 @@ public function testThatAnExceptionIsThrownWhenAClassDoesNotExist() : void ]); } - public function testThatAnExceptionIsThrownWithClassNamesNotImplementingHierarchy() : void + public function testThatAnExceptionIsThrownWithClassNamesNotImplementingHierarchy(): void { $this->expectException(InvalidArgument::class); $this->expectExceptionMessage('All target classes to hydrate to must descend from ' . Document::class); diff --git a/test/Unit/Router/Container/DocumentResolverFactoryTest.php b/test/Unit/Router/Container/DocumentResolverFactoryTest.php index 0b039bf..16d6adf 100644 --- a/test/Unit/Router/Container/DocumentResolverFactoryTest.php +++ b/test/Unit/Router/Container/DocumentResolverFactoryTest.php @@ -1,4 +1,5 @@ createMock(ContainerInterface::class); $api = $this->createMock(ApiClient::class); diff --git a/test/Unit/Router/Container/RouteMatcherFactoryTest.php b/test/Unit/Router/Container/RouteMatcherFactoryTest.php index 7f797fd..252ad0a 100644 --- a/test/Unit/Router/Container/RouteMatcherFactoryTest.php +++ b/test/Unit/Router/Container/RouteMatcherFactoryTest.php @@ -1,4 +1,5 @@ createMock(ContainerInterface::class); $container->expects(self::exactly(2)) diff --git a/test/Unit/Router/Container/RouteParamsFactoryTest.php b/test/Unit/Router/Container/RouteParamsFactoryTest.php index 90bccfa..14cd46f 100644 --- a/test/Unit/Router/Container/RouteParamsFactoryTest.php +++ b/test/Unit/Router/Container/RouteParamsFactoryTest.php @@ -1,4 +1,5 @@ container = $this->createMock(ContainerInterface::class); $this->factory = new RouteParamsFactory(); } - public function testContainerWithoutConfigWillYieldParamsWithDefaultValues() : void + public function testContainerWithoutConfigWillYieldParamsWithDefaultValues(): void { $this->container->expects(self::once()) ->method('has') @@ -37,7 +38,7 @@ public function testContainerWithoutConfigWillYieldParamsWithDefaultValues() : v self::assertSame('document-id', $params->id()); } - public function testContainerWithConfiguredParamsWillYieldParamsWithConfiguredValues() : void + public function testContainerWithConfiguredParamsWillYieldParamsWithConfiguredValues(): void { $this->container->expects(self::once()) ->method('has') diff --git a/test/Unit/Router/DocumentResolverTest.php b/test/Unit/Router/DocumentResolverTest.php index 8ea611e..53e67f9 100644 --- a/test/Unit/Router/DocumentResolverTest.php +++ b/test/Unit/Router/DocumentResolverTest.php @@ -1,4 +1,5 @@ api = $this->createMock(ApiClient::class); $this->params = RouteParams::fromArray([]); $this->resolver = new DocumentResolver($this->api, $this->params); $this->middleware = new class implements MiddlewareInterface { - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { return new TextResponse('Hey'); } }; } - public function testRouteResultWithoutMatchingParamsWillReturnNull() : void + public function testRouteResultWithoutMatchingParamsWillReturnNull(): void { $result = RouteResult::fromRoute(new Route('/foo', $this->middleware, ['GET']), []); self::assertNull($this->resolver->resolve($result)); } - public function testThatResultFromApiWillBeReturnedWhenBookmarkMatches() : void + public function testThatResultFromApiWillBeReturnedWhenBookmarkMatches(): void { $document = $this->createMock(Document::class); $this->api->expects(self::once()) @@ -67,7 +68,7 @@ public function testThatResultFromApiWillBeReturnedWhenBookmarkMatches() : void self::assertSame($document, $this->resolver->resolve($result)); } - public function testThatResultFromApiWillBeReturnedWhenRouteMatchesDocumentId() : void + public function testThatResultFromApiWillBeReturnedWhenRouteMatchesDocumentId(): void { $document = $this->createMock(Document::class); $this->api->expects(self::once()) @@ -83,7 +84,7 @@ public function testThatResultFromApiWillBeReturnedWhenRouteMatchesDocumentId() self::assertSame($document, $this->resolver->resolve($result)); } - private function apiWillReturnSingleDocumentInLanguage(string $lang) : Document + private function apiWillReturnSingleDocumentInLanguage(string $lang): Document { $document = $this->createMock(Document::class); $query = $this->createMock(Query::class); @@ -117,7 +118,7 @@ private function apiWillReturnSingleDocumentInLanguage(string $lang) : Document return $document; } - public function testThatResultFromApiIsReturnedWhenRouteMatchesTypeAndUid() : void + public function testThatResultFromApiIsReturnedWhenRouteMatchesTypeAndUid(): void { $document = $this->apiWillReturnSingleDocumentInLanguage('*'); @@ -132,7 +133,7 @@ public function testThatResultFromApiIsReturnedWhenRouteMatchesTypeAndUid() : vo self::assertSame($document, $this->resolver->resolve($result)); } - public function testThatLanguageIsProvidedToApiMethodWhenFoundInTheRouteParams() : void + public function testThatLanguageIsProvidedToApiMethodWhenFoundInTheRouteParams(): void { $document = $this->apiWillReturnSingleDocumentInLanguage('en-gb'); @@ -148,7 +149,7 @@ public function testThatLanguageIsProvidedToApiMethodWhenFoundInTheRouteParams() self::assertSame($document, $this->resolver->resolve($result)); } - public function testThatTypeMustBeKnownInOrderToResolveByUid() : void + public function testThatTypeMustBeKnownInOrderToResolveByUid(): void { $result = RouteResult::fromRoute( new Route('/foo', $this->middleware, ['GET'], 'myRoute'), @@ -160,7 +161,7 @@ public function testThatTypeMustBeKnownInOrderToResolveByUid() : void $this->resolver->resolve($result); } - public function testThatItIsPossibleToQueryOnASingleType() : void + public function testThatItIsPossibleToQueryOnASingleType(): void { $document = $this->apiWillReturnSingleDocumentInLanguage('*'); @@ -172,7 +173,7 @@ public function testThatItIsPossibleToQueryOnASingleType() : void self::assertSame($document, $this->resolver->resolve($result)); } - public function testThatItIsPossibleToQueryByTag() : void + public function testThatItIsPossibleToQueryByTag(): void { $document = $this->apiWillReturnSingleDocumentInLanguage('*'); @@ -184,7 +185,7 @@ public function testThatItIsPossibleToQueryByTag() : void self::assertSame($document, $this->resolver->resolve($result)); } - public function testAnExceptionIsThrownWhenAResultSetContainsMultipleResults() : void + public function testAnExceptionIsThrownWhenAResultSetContainsMultipleResults(): void { $query = $this->createMock(Query::class); $resultSet = $this->createMock(ResultSet::class); diff --git a/test/Unit/Router/RouteMatcherTest.php b/test/Unit/Router/RouteMatcherTest.php index 8b618ad..cc3e89b 100644 --- a/test/Unit/Router/RouteMatcherTest.php +++ b/test/Unit/Router/RouteMatcherTest.php @@ -1,4 +1,5 @@ params = RouteParams::fromArray([]); @@ -33,31 +34,31 @@ protected function setUp() : void $this->collector = new RouteCollector($router); $this->middleware = new class implements MiddlewareInterface { - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { return new TextResponse('Hey'); } }; } - private function matcher() : RouteMatcher + private function matcher(): RouteMatcher { return new RouteMatcher($this->params, $this->collector); } - public function testThatBookmarkedRouteIsNullWhenThereAreNoMatchingRoutes() : void + public function testThatBookmarkedRouteIsNullWhenThereAreNoMatchingRoutes(): void { $matcher = $this->matcher(); self::assertNull($matcher->getBookmarkedRoute('anything')); } - public function testThatTypedRouteIsNullWhenThereAreNoMatchingRoutes() : void + public function testThatTypedRouteIsNullWhenThereAreNoMatchingRoutes(): void { $matcher = $this->matcher(); self::assertNull($matcher->getTypedRoute('any-type')); } - public function testThatTheRouteMatcherCanFindABookmarkedRoute() : void + public function testThatTheRouteMatcherCanFindABookmarkedRoute(): void { $bookmarkedRoute = $this->collector->get('/some-path', $this->middleware, 'bookmark-route'); $bookmarkedRoute->setOptions(['defaults' => [$this->params->bookmark() => 'bookmark-name']]); @@ -66,7 +67,7 @@ public function testThatTheRouteMatcherCanFindABookmarkedRoute() : void self::assertSame($bookmarkedRoute, $route); } - public function testThatATypedRouteIsMatchedWhenTypeIsDefinedAsAString() : void + public function testThatATypedRouteIsMatchedWhenTypeIsDefinedAsAString(): void { $typedRoute = $this->collector->get('/some-path', $this->middleware, 'typed-route'); $typedRoute->setOptions(['defaults' => [$this->params->type() => 'some-type']]); @@ -75,7 +76,7 @@ public function testThatATypedRouteIsMatchedWhenTypeIsDefinedAsAString() : void self::assertSame($typedRoute, $route); } - public function testThatATypedRouteIsMatchedWhenTheTypeIsDefinedAsAnArray() : void + public function testThatATypedRouteIsMatchedWhenTheTypeIsDefinedAsAnArray(): void { $typedRoute = $this->collector->get('/some-path', $this->middleware, 'typed-route'); $typedRoute->setOptions([ @@ -92,7 +93,7 @@ public function testThatATypedRouteIsMatchedWhenTheTypeIsDefinedAsAnArray() : vo self::assertNull($matcher->getTypedRoute('wrong-type')); } - public function testThatMatchingIsFifoByDefault() : void + public function testThatMatchingIsFifoByDefault(): void { $first = $this->collector->get('/some-path', $this->middleware, 'route-one'); $first->setOptions(['defaults' => [$this->params->type() => 'type']]); @@ -102,7 +103,7 @@ public function testThatMatchingIsFifoByDefault() : void self::assertSame($first, $matcher->getTypedRoute('type')); } - public function testThatMultipleRoutesMatchingATypeCanBeFound() : void + public function testThatMultipleRoutesMatchingATypeCanBeFound(): void { $first = $this->collector->get('/some-path', $this->middleware, 'some-route'); $first->setOptions(['defaults' => [$this->params->type() => 'type']]); @@ -116,7 +117,7 @@ public function testThatMultipleRoutesMatchingATypeCanBeFound() : void self::assertNotContains($third, $results); } - public function testThatMultipleRoutesMatchingATagCanBeFound() : void + public function testThatMultipleRoutesMatchingATagCanBeFound(): void { $first = $this->collector->get('/some-path', $this->middleware, 'some-route'); $first->setOptions(['defaults' => [$this->params->tag() => 'a']]); @@ -130,7 +131,7 @@ public function testThatMultipleRoutesMatchingATagCanBeFound() : void self::assertNotContains($third, $results); } - public function testThatMatchingTagsIsCaseSensitive() : void + public function testThatMatchingTagsIsCaseSensitive(): void { $first = $this->collector->get('/some-path', $this->middleware, 'some-route'); $first->setOptions(['defaults' => [$this->params->tag() => 'a']]); @@ -146,13 +147,13 @@ public function testThatMatchingTagsIsCaseSensitive() : void self::assertContains($second, $results); } - public function testThatUidRouteIsNullWhenThereAreNoMatchingRoutes() : void + public function testThatUidRouteIsNullWhenThereAreNoMatchingRoutes(): void { $matcher = $this->matcher(); self::assertNull($matcher->getUidRoute('foo', 'bar')); } - public function testThatUidRouteIsNullWhenTypeMatchesButUidDoesNot() : void + public function testThatUidRouteIsNullWhenTypeMatchesButUidDoesNot(): void { $route = $this->collector->get('/some-path', $this->middleware, 'some-route'); $route->setOptions(['defaults' => [$this->params->type() => 'a']]); @@ -160,7 +161,7 @@ public function testThatUidRouteIsNullWhenTypeMatchesButUidDoesNot() : void self::assertNull($matcher->getUidRoute('a', 'bar')); } - public function testThatUidRouteMatches() : void + public function testThatUidRouteMatches(): void { $route = $this->collector->get('/some-path', $this->middleware, 'some-route'); $route->setOptions(['defaults' => [$this->params->type() => 'a', $this->params->uid() => 'bar']]); @@ -169,7 +170,7 @@ public function testThatUidRouteMatches() : void } /** @return mixed[] */ - public function routeMatchingProvider() : array + public function routeMatchingProvider(): array { return [ 'bookmark' => [$this->params->bookmark() => 'mark'], @@ -190,7 +191,7 @@ public function routeMatchingProvider() : array ]; } - private function loadRoutes() : void + private function loadRoutes(): void { foreach ($this->routeMatchingProvider() as $name => $defaults) { $route = $this->collector->get('/' . $name, $this->middleware, $name); @@ -198,7 +199,7 @@ private function loadRoutes() : void } } - public function testBestMatch() : void + public function testBestMatch(): void { $this->loadRoutes(); $matcher = $this->matcher(); @@ -212,13 +213,13 @@ public function testBestMatch() : void $this->assertBastMatch('two-tags', $matcher->bestMatch('id', 'type', 'no-match', null, ['a', 'b'])); } - private function assertBastMatch(string $name, ?Route $match) : void + private function assertBastMatch(string $name, ?Route $match): void { self::assertNotNull($match, 'A match was not found'); self::assertSame($name, $match->getName()); } - public function testRouteDefinitionWithInvalidTagParameterWillCauseException() : void + public function testRouteDefinitionWithInvalidTagParameterWillCauseException(): void { $route = $this->collector->get('/some-path', $this->middleware, 'some-route'); $route->setOptions(['defaults' => [$this->params->tag() => true]]); diff --git a/test/Unit/Router/RouteParamsTest.php b/test/Unit/Router/RouteParamsTest.php index a7e63a1..1973839 100644 --- a/test/Unit/Router/RouteParamsTest.php +++ b/test/Unit/Router/RouteParamsTest.php @@ -1,4 +1,5 @@ 'id', @@ -27,43 +28,43 @@ public function testOptionsArray() : RouteParams } /** @depends testOptionsArray */ - public function testId(RouteParams $params) : void + public function testId(RouteParams $params): void { self::assertSame('id', $params->id()); } /** @depends testOptionsArray */ - public function testUid(RouteParams $params) : void + public function testUid(RouteParams $params): void { self::assertSame('uid', $params->uid()); } /** @depends testOptionsArray */ - public function testType(RouteParams $params) : void + public function testType(RouteParams $params): void { self::assertSame('type', $params->type()); } /** @depends testOptionsArray */ - public function testBookmark(RouteParams $params) : void + public function testBookmark(RouteParams $params): void { self::assertSame('bookmark', $params->bookmark()); } /** @depends testOptionsArray */ - public function testLang(RouteParams $params) : void + public function testLang(RouteParams $params): void { self::assertSame('lang', $params->lang()); } /** @depends testOptionsArray */ - public function testReuseParams(RouteParams $params) : void + public function testReuseParams(RouteParams $params): void { self::assertSame('reuse', $params->reuseResultParams()); } /** @return mixed[] */ - public function typeErrorProvider() : iterable + public function typeErrorProvider(): iterable { return [ 'Non string option key' => [[0 => 'value']], @@ -76,13 +77,13 @@ public function typeErrorProvider() : iterable * * @dataProvider typeErrorProvider */ - public function testOptionTypeError(array $options) : void + public function testOptionTypeError(array $options): void { $this->expectException(TypeError::class); RouteParams::fromArray($options); } - public function testExceptionThrownForInvalidOptionKeys() : void + public function testExceptionThrownForInvalidOptionKeys(): void { $this->expectException(InvalidArgument::class); $this->expectExceptionMessage('"nuts" is not a valid option key. Valid options are:'); diff --git a/test/Unit/TestCase.php b/test/Unit/TestCase.php index 20e0fdf..b6b74b0 100644 --- a/test/Unit/TestCase.php +++ b/test/Unit/TestCase.php @@ -1,4 +1,5 @@ Date: Wed, 3 Mar 2021 11:45:02 +0000 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ee7b68..118e76c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file, in reverse - [#8](https://github.com/netglue/primo/pull/8) Improves CI by using [the matrix action from the Laminas project](https://github.com/laminas/laminas-ci-matrix-action). - [#8](https://github.com/netglue/primo/pull/8) Also updates dependencies, fixing test failures on 8 _(Out of date PHPUnit)_ and fixing a test failure due to copy/paste of a duplicate route name. +- [#9](https://github.com/netglue/primo/pull/9) Cleans up CS so it's the same as the adopted coding standard. ### Deprecated