Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions tests/Exception/CommandExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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]));
Expand All @@ -40,7 +40,7 @@ public function testNullOffsetUsesEmptyStringKey()
$this->assertSame([], $c->toArray());
}

public function testAppendSyntaxUsesEmptyStringKey()
public function testAppendSyntaxUsesEmptyStringKey(): void
{
$c = new Result();
$c[] = 'bar';
Expand Down
38 changes: 19 additions & 19 deletions tests/ServiceClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand All @@ -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"}'),
Expand All @@ -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(
Expand All @@ -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']);
Expand All @@ -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;
},
];
Expand All @@ -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']);
};

Expand All @@ -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;
},
]);
Expand All @@ -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']);
};

Expand All @@ -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;
},
]);
Expand All @@ -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';
};

Expand Down