Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the Mock strategy to work for async clients too #137

Merged
merged 2 commits into from
Feb 23, 2019
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## Unrelesed

- Fix MockClientStrategy for provide the mock as an async client too

## 1.6.0 - 2019-01-23

### Added
Expand Down
8 changes: 8 additions & 0 deletions spec/Strategy/MockClientStrategySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace spec\Http\Discovery\Strategy;

use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Http\Discovery\ClassDiscovery;
use Http\Discovery\Strategy\DiscoveryStrategy;
Expand All @@ -22,4 +23,11 @@ function it_should_return_the_mock_client(DiscoveryStrategy $strategy)
$candidates->shouldBeArray();
$candidates->shouldHaveCount(1);
}

function it_should_return_the_mock_client_as_async(DiscoveryStrategy $strategy)
{
$candidates = $this->getCandidates(HttpAsyncClient::class);
$candidates->shouldBeArray();
$candidates->shouldHaveCount(1);
}
}
11 changes: 8 additions & 3 deletions src/Strategy/MockClientStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Http\Discovery\Strategy;

use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Http\Mock\Client as Mock;

Expand All @@ -17,8 +18,12 @@ final class MockClientStrategy implements DiscoveryStrategy
*/
public static function getCandidates($type)
{
return (HttpClient::class === $type)
? [['class' => Mock::class, 'condition' => Mock::class]]
: [];
switch ($type) {
case HttpClient::class:
case HttpAsyncClient::class:
return [['class' => Mock::class, 'condition' => Mock::class]];
default:
return [];
}
}
}