diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 54df15a..06e8742 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -13,7 +13,7 @@ */ class CommandTest extends TestCase { - public function testHasData() + public function testHasData(): void { $c = new Command('foo', ['baz' => 'bar']); $this->assertSame('bar', $c['baz']); @@ -25,20 +25,20 @@ public function testHasData() $this->assertInstanceOf('Traversable', $c->getIterator()); } - public function testHasParamNormalizesNullToEmptyString() + public function testHasParamNormalizesNullToEmptyString(): void { $c = new Command('foo', ['' => 'bar']); $this->assertTrue($c->hasParam(null)); } - public function testCanInjectHandlerStack() + public function testCanInjectHandlerStack(): void { $handlerStack = new HandlerStack(); $c = new Command('foo', [], $handlerStack); $this->assertSame($handlerStack, $c->getHandlerStack()); } - public function testCloneUsesDifferentHandlerStack() + public function testCloneUsesDifferentHandlerStack(): void { $originalStack = new HandlerStack(); $command = new Command('foo', [], $originalStack); diff --git a/tests/Exception/CommandExceptionTest.php b/tests/Exception/CommandExceptionTest.php index 989bfe5..d3f374c 100644 --- a/tests/Exception/CommandExceptionTest.php +++ b/tests/Exception/CommandExceptionTest.php @@ -18,7 +18,7 @@ */ class CommandExceptionTest extends TestCase { - public function testCanGetDataFromException() + public function testCanGetDataFromException(): void { $command = $this->createMock(CommandInterface::class); $request = $this->createMock(RequestInterface::class); @@ -30,7 +30,7 @@ public function testCanGetDataFromException() $this->assertSame($response, $exception->getResponse()); } - public function testFactoryReturnsExceptionIfAlreadyCommandException() + public function testFactoryReturnsExceptionIfAlreadyCommandException(): void { $command = $this->createMock(CommandInterface::class); $previous = CommandException::fromPrevious($command, new \Exception()); @@ -39,7 +39,7 @@ public function testFactoryReturnsExceptionIfAlreadyCommandException() $this->assertSame($previous, $exception); } - public function testFactoryReturnsClientExceptionFor400LevelStatusCode() + public function testFactoryReturnsClientExceptionFor400LevelStatusCode(): void { $command = $this->createMock(CommandInterface::class); $request = $this->createMock(RequestInterface::class); @@ -51,7 +51,7 @@ public function testFactoryReturnsClientExceptionFor400LevelStatusCode() $this->assertInstanceOf(CommandClientException::class, $exception); } - public function testFactoryReturnsServerExceptionFor500LevelStatusCode() + public function testFactoryReturnsServerExceptionFor500LevelStatusCode(): void { $command = $this->createMock(CommandInterface::class); $request = $this->createMock(RequestInterface::class); diff --git a/tests/ResultTest.php b/tests/ResultTest.php index 4fdc9b5..1d4a1c0 100644 --- a/tests/ResultTest.php +++ b/tests/ResultTest.php @@ -13,7 +13,7 @@ */ class ResultTest extends TestCase { - public function testHasData() + public function testHasData(): void { $c = new Result(['baz' => 'bar']); $this->assertSame('bar', $c['baz']); @@ -27,7 +27,7 @@ public function testHasData() $this->assertStringContainsString('bar', (string) $c); } - public function testNullOffsetUsesEmptyStringKey() + public function testNullOffsetUsesEmptyStringKey(): void { $c = new Result(['' => 'bar']); $this->assertTrue(isset($c[null])); @@ -40,7 +40,7 @@ public function testNullOffsetUsesEmptyStringKey() $this->assertSame([], $c->toArray()); } - public function testAppendSyntaxUsesEmptyStringKey() + public function testAppendSyntaxUsesEmptyStringKey(): void { $c = new Result(); $c[] = 'bar'; diff --git a/tests/ServiceClientTest.php b/tests/ServiceClientTest.php index cbcbba6..209a885 100644 --- a/tests/ServiceClientTest.php +++ b/tests/ServiceClientTest.php @@ -24,19 +24,19 @@ */ class ServiceClientTest extends TestCase { - private function getServiceClient(array $responses) + private function getServiceClient(array $responses): ServiceClient { return new ServiceClient( new HttpClient([ 'handler' => new MockHandler($responses), ]), - function (CommandInterface $command) { + function (CommandInterface $command): Request { $data = $command->toArray(); $data['action'] = $command->getName(); return new Request('POST', '/', [], http_build_query($data)); }, - function (ResponseInterface $response, RequestInterface $request) { + function (ResponseInterface $response, RequestInterface $request): Result { $data = json_decode((string) $response->getBody(), true); parse_str((string) $request->getBody(), $data['_request']); @@ -45,17 +45,17 @@ function (ResponseInterface $response, RequestInterface $request) { ); } - public function testCanGetHttpClientAndHandlers() + public function testCanGetHttpClientAndHandlers(): void { $httpClient = new HttpClient(); $handlers = new HandlerStack(); - $fn = function () {}; + $fn = function (): void {}; $serviceClient = new ServiceClient($httpClient, $fn, $fn, $handlers); $this->assertSame($httpClient, $serviceClient->getHttpClient()); $this->assertSame($handlers, $serviceClient->getHandlerStack()); } - public function testExecuteCommandViaMagicMethod() + public function testExecuteCommandViaMagicMethod(): void { $client = $this->getServiceClient([ new Response(200, [], '{"foo":"bar"}'), @@ -74,7 +74,7 @@ public function testExecuteCommandViaMagicMethod() $this->assertEquals('doThatThingOtherYouDo', $result2['_request']['action']); } - public function testCommandExceptionIsThrownWhenAnErrorOccurs() + public function testCommandExceptionIsThrownWhenAnErrorOccurs(): void { $client = $this->getServiceClient([ new BadResponseException( @@ -88,10 +88,10 @@ public function testCommandExceptionIsThrownWhenAnErrorOccurs() $client->execute($client->getCommand('foo')); } - public function testExecuteMultipleCommands() + public function testExecuteMultipleCommands(): void { // Set up commands to execute concurrently. - $generateCommands = function () { + $generateCommands = function (): \Generator { yield new Command('capitalize', ['letter' => 'a']); yield new Command('capitalize', ['letter' => '2']); yield new Command('capitalize', ['letter' => 'z']); @@ -113,10 +113,10 @@ public function testExecuteMultipleCommands() $fulfilledFnCalled = false; $rejectedFnCalled = false; $options = [ - 'fulfilled' => function () use (&$fulfilledFnCalled) { + 'fulfilled' => function () use (&$fulfilledFnCalled): void { $fulfilledFnCalled = true; }, - 'rejected' => function () use (&$rejectedFnCalled) { + 'rejected' => function () use (&$rejectedFnCalled): void { $rejectedFnCalled = true; }, ]; @@ -141,9 +141,9 @@ public function testExecuteMultipleCommands() $this->assertEquals('Z', $results[2]['letter']); } - public function testExecuteAllNormalizesNullResultKeys() + public function testExecuteAllNormalizesNullResultKeys(): void { - $generateCommands = function () { + $generateCommands = function (): \Generator { yield null => new Command('capitalize', ['letter' => 'a']); }; @@ -153,7 +153,7 @@ public function testExecuteAllNormalizesNullResultKeys() $fulfilledKey = 'not-called'; $results = $client->executeAll($generateCommands(), [ - 'fulfilled' => function ($result, $key) use (&$fulfilledKey) { + 'fulfilled' => function (Result $result, ?string $key) use (&$fulfilledKey): void { $fulfilledKey = $key; }, ]); @@ -164,9 +164,9 @@ public function testExecuteAllNormalizesNullResultKeys() $this->assertSame('A', $results['']['letter']); } - public function testExecuteAllNormalizesNullResultKeysForRejectedCommands() + public function testExecuteAllNormalizesNullResultKeysForRejectedCommands(): void { - $generateCommands = function () { + $generateCommands = function (): \Generator { yield null => new Command('capitalize', ['letter' => '2']); }; @@ -180,7 +180,7 @@ public function testExecuteAllNormalizesNullResultKeysForRejectedCommands() $rejectedKey = 'not-called'; $results = $client->executeAll($generateCommands(), [ - 'rejected' => function ($reason, $key) use (&$rejectedKey) { + 'rejected' => function (CommandException $reason, ?string $key) use (&$rejectedKey): void { $rejectedKey = $key; }, ]); @@ -190,9 +190,9 @@ public function testExecuteAllNormalizesNullResultKeysForRejectedCommands() $this->assertInstanceOf(CommandException::class, $results['']); } - public function testMultipleCommandsFailsForNonCommands() + public function testMultipleCommandsFailsForNonCommands(): void { - $generateCommands = function () { + $generateCommands = function (): \Generator { yield 'foo'; };