Skip to content

Commit 9551d26

Browse files
Jean85dbu
authored andcommitted
Fix the Mock strategy to work for async clients too (#137)
1 parent 8340ddc commit 9551d26

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## Unrelesed
4+
5+
- Fix MockClientStrategy for provide the mock as an async client too
6+
37
## 1.6.0 - 2019-01-23
48

59
### Added

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: 8 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,12 @@ 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 [];
27+
}
2328
}
2429
}

0 commit comments

Comments
 (0)