Skip to content

Commit

Permalink
Fix the Mock strategy to work for async clients too
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean85 committed Feb 22, 2019
1 parent 8340ddc commit f6973e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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 [];
}
}
}

0 comments on commit f6973e5

Please sign in to comment.