Skip to content

Commit

Permalink
tests: Use PHPUnit’s mocking facilities instead of anonymous classes
Browse files Browse the repository at this point in the history
This will allow the tests to work on PHP 5.6 as well.
  • Loading branch information
jtojnar committed May 1, 2021
1 parent aad0ac7 commit d6ab1c9
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions tests/Spouts/YouTubeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use helpers\Configuration;
use helpers\WebClient;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;
use spouts\youtube\youtube;

Expand Down Expand Up @@ -38,23 +36,11 @@ public function testBasic($url, $feedTitle, $firstItemTitle) {
$dice->addRule('*', [
'substitutions' => [
WebClient::class => [
'instance' => function() use ($dice, $httpClient) {
$wc = new class($dice->create(Logger::class), $httpClient) extends WebClient {
/** @var Client */
private $httpClient;
'instance' => function() use ($httpClient) {
$stub = $this->createMock(WebClient::class);
$stub->method('getHttpClient')->willReturn($httpClient);

public function __construct($logger, $httpClient) {
parent::__construct(new Configuration, $logger);

$this->httpClient = $httpClient;
}

public function getHttpClient() {
return $this->httpClient;
}
};

return $wc;
return $stub;
}
],
],
Expand Down

0 comments on commit d6ab1c9

Please sign in to comment.