Skip to content

Commit 8aab76c

Browse files
committed
Fix the Mock strategy to work for async clients too
1 parent 8340ddc commit 8aab76c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

spec/Strategy/MockClientStrategySpec.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace spec\Http\Discovery\Strategy;
44

5+
use Http\Client\HttpAsyncClient;
56
use Http\Client\HttpClient;
67
use Http\Discovery\ClassDiscovery;
78
use Http\Discovery\Strategy\DiscoveryStrategy;
@@ -22,4 +23,11 @@ function it_should_return_the_mock_client(DiscoveryStrategy $strategy)
2223
$candidates->shouldBeArray();
2324
$candidates->shouldHaveCount(1);
2425
}
26+
27+
function it_should_return_the_mock_client_as_async(DiscoveryStrategy $strategy)
28+
{
29+
$candidates = $this->getCandidates(HttpAsyncClient::class);
30+
$candidates->shouldBeArray();
31+
$candidates->shouldHaveCount(1);
32+
}
2533
}

src/Strategy/MockClientStrategy.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Http\Discovery\Strategy;
44

5+
use Http\Client\HttpAsyncClient;
56
use Http\Client\HttpClient;
67
use Http\Mock\Client as Mock;
78

@@ -17,8 +18,11 @@ final class MockClientStrategy implements DiscoveryStrategy
1718
*/
1819
public static function getCandidates($type)
1920
{
20-
return (HttpClient::class === $type)
21-
? [['class' => Mock::class, 'condition' => Mock::class]]
22-
: [];
21+
switch ($type) {
22+
case HttpClient::class:
23+
case HttpAsyncClient::class:
24+
return [['class' => Mock::class, 'condition' => Mock::class]];
25+
default:
26+
return [];
2327
}
2428
}

0 commit comments

Comments
 (0)