Skip to content

Commit 49cd2ca

Browse files
pascalwoerdedbu
authored andcommitted
Support PSR-18 interface as candidate by inheritance (#145)
* Support PSR-18 interface as candidate by inheritance
1 parent e822f86 commit 49cd2ca

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

spec/Strategy/MockClientStrategySpec.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Http\Discovery\Strategy\DiscoveryStrategy;
99
use Http\Discovery\Strategy;
1010
use PhpSpec\ObjectBehavior;
11+
use Psr\Http\Client\ClientInterface;
1112
use spec\Http\Discovery\Helper\DiscoveryHelper;
1213

1314
class MockClientStrategySpec extends ObjectBehavior
@@ -24,6 +25,15 @@ function it_should_return_the_mock_client(DiscoveryStrategy $strategy)
2425
$candidates->shouldHaveCount(1);
2526
}
2627

28+
function it_should_return_the_mock_client_for_implementations(DiscoveryStrategy $strategy)
29+
{
30+
foreach (class_implements(HttpClient::class) as $type) {
31+
$candidates = $this->getCandidates($type);
32+
$candidates->shouldBeArray();
33+
$candidates->shouldHaveCount(1);
34+
}
35+
}
36+
2737
function it_should_return_the_mock_client_as_async(DiscoveryStrategy $strategy)
2838
{
2939
$candidates = $this->getCandidates(HttpAsyncClient::class);

src/Strategy/MockClientStrategy.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ final class MockClientStrategy implements DiscoveryStrategy
1818
*/
1919
public static function getCandidates($type)
2020
{
21-
switch ($type) {
22-
case HttpClient::class:
23-
case HttpAsyncClient::class:
24-
return [['class' => Mock::class, 'condition' => Mock::class]];
25-
default:
26-
return [];
27-
}
21+
if (is_a(HttpClient::class, $type, true) || is_a(HttpAsyncClient::class, $type, true)) {
22+
return [['class' => Mock::class, 'condition' => Mock::class]];
23+
}
24+
25+
return [];
2826
}
2927
}

0 commit comments

Comments
 (0)