Skip to content

Commit

Permalink
Support PSR-18 interface as candidate by inheritance (#145)
Browse files Browse the repository at this point in the history
* Support PSR-18 interface as candidate by inheritance
  • Loading branch information
pascalwoerde authored and dbu committed Sep 24, 2019
1 parent e822f86 commit 49cd2ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 10 additions & 0 deletions spec/Strategy/MockClientStrategySpec.php
Expand Up @@ -8,6 +8,7 @@
use Http\Discovery\Strategy\DiscoveryStrategy;
use Http\Discovery\Strategy;
use PhpSpec\ObjectBehavior;
use Psr\Http\Client\ClientInterface;
use spec\Http\Discovery\Helper\DiscoveryHelper;

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

function it_should_return_the_mock_client_for_implementations(DiscoveryStrategy $strategy)
{
foreach (class_implements(HttpClient::class) as $type) {
$candidates = $this->getCandidates($type);
$candidates->shouldBeArray();
$candidates->shouldHaveCount(1);
}
}

function it_should_return_the_mock_client_as_async(DiscoveryStrategy $strategy)
{
$candidates = $this->getCandidates(HttpAsyncClient::class);
Expand Down
12 changes: 5 additions & 7 deletions src/Strategy/MockClientStrategy.php
Expand Up @@ -18,12 +18,10 @@ final class MockClientStrategy implements DiscoveryStrategy
*/
public static function getCandidates($type)
{
switch ($type) {
case HttpClient::class:
case HttpAsyncClient::class:
return [['class' => Mock::class, 'condition' => Mock::class]];
default:
return [];
}
if (is_a(HttpClient::class, $type, true) || is_a(HttpAsyncClient::class, $type, true)) {
return [['class' => Mock::class, 'condition' => Mock::class]];
}

return [];
}
}

0 comments on commit 49cd2ca

Please sign in to comment.