Skip to content

Commit

Permalink
Fix broken Guzzle mocks in ClientSpec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Mar 1, 2022
1 parent d8c7df0 commit 8fd1411
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions spec/Packagist/Api/ClientSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace spec\Packagist\Api;

use GuzzleHttp\Psr7\Stream;
use PhpSpec\ObjectBehavior;
use PhpSpec\Exception\Example\MatcherException;

Expand All @@ -23,32 +24,35 @@ function it_is_initializable()
$this->shouldHaveType('Packagist\Api\Client');
}

function it_search_for_packages(HttpClient $client, Factory $factory, Response $response)
function it_search_for_packages(HttpClient $client, Factory $factory, Response $response, Stream $body)
{
$data = file_get_contents('spec/Packagist/Api/Fixture/search.json');
$response->getBody()->shouldBeCalled()->willReturn($data);
$response->getBody()->shouldBeCalled()->willReturn($body);
$body->__toString()->shouldBeCalled()->willReturn($data);

$client->request('GET', 'https://packagist.org/search.json?q=sylius')->shouldBeCalled()->willReturn($response);
$factory->create(json_decode($data, true))->shouldBeCalled()->willReturn(array());

$this->search('sylius');
}

function it_search_for_packages_with_limit(HttpClient $client, Factory $factory, Response $response)
function it_search_for_packages_with_limit(HttpClient $client, Factory $factory, Response $response, Stream $body)
{
$data = file_get_contents('spec/Packagist/Api/Fixture/search.json');
$response->getBody()->shouldBeCalled()->willReturn($data);
$response->getBody()->shouldBeCalled()->willReturn($body);
$body->__toString()->shouldBeCalled()->willReturn($data);

$client->request('GET', 'https://packagist.org/search.json?q=sylius')->shouldBeCalled()->willReturn($response);
$factory->create(json_decode($data, true))->shouldBeCalled()->willReturn(array());

$this->search('sylius', [], 2);
}

function it_searches_for_packages_with_filters(HttpClient $client, Factory $factory, Response $response)
function it_searches_for_packages_with_filters(HttpClient $client, Factory $factory, Response $response, Stream $body)
{
$data = file_get_contents('spec/Packagist/Api/Fixture/search.json');
$response->getBody()->shouldBeCalled()->willReturn($data);
$response->getBody()->shouldBeCalled()->willReturn($body);
$body->__toString()->shouldBeCalled()->willReturn($data);

$client->request('GET', 'https://packagist.org/search.json?tag=storage&q=sylius')->shouldBeCalled()->willReturn($response);

Expand All @@ -57,10 +61,11 @@ function it_searches_for_packages_with_filters(HttpClient $client, Factory $fact
$this->search('sylius', array('tag' => 'storage'));
}

function it_gets_popular_packages(HttpClient $client, Factory $factory, Response $response)
function it_gets_popular_packages(HttpClient $client, Factory $factory, Response $response, Stream $body)
{
$data = file_get_contents('spec/Packagist/Api/Fixture/popular.json');
$response->getBody()->shouldBeCalled()->willReturn($data);
$response->getBody()->shouldBeCalled()->willReturn($body);
$body->__toString()->shouldBeCalled()->willReturn($data);

$client->request('GET', 'https://packagist.org/explore/popular.json?page=1')->shouldBeCalled()->willReturn($response);

Expand All @@ -69,10 +74,11 @@ function it_gets_popular_packages(HttpClient $client, Factory $factory, Response
$this->popular(2)->shouldHaveCount(2);
}

function it_gets_package_details(HttpClient $client, Factory $factory, Response $response)
function it_gets_package_details(HttpClient $client, Factory $factory, Response $response, Stream $body)
{
$data = file_get_contents('spec/Packagist/Api/Fixture/get.json');
$response->getBody()->shouldBeCalled()->willReturn($data);
$response->getBody()->shouldBeCalled()->willReturn($body);
$body->__toString()->shouldBeCalled()->willReturn($data);

$client->request('GET', 'https://packagist.org/packages/sylius/sylius.json')->shouldBeCalled()->willReturn($response);

Expand All @@ -81,10 +87,11 @@ function it_gets_package_details(HttpClient $client, Factory $factory, Response
$this->get('sylius/sylius');
}

function it_lists_all_package_names(HttpClient $client, Factory $factory, Response $response)
function it_lists_all_package_names(HttpClient $client, Factory $factory, Response $response, Stream $body)
{
$data = file_get_contents('spec/Packagist/Api/Fixture/all.json');
$response->getBody()->shouldBeCalled()->willReturn($data);
$response->getBody()->shouldBeCalled()->willReturn($body);
$body->__toString()->shouldBeCalled()->willReturn($data);

$client->request('GET', 'https://packagist.org/packages/list.json')->shouldBeCalled()->willReturn($response);

Expand All @@ -93,10 +100,11 @@ function it_lists_all_package_names(HttpClient $client, Factory $factory, Respon
$this->all();
}

function it_filters_package_names_by_type(HttpClient $client, Factory $factory, Response $response)
function it_filters_package_names_by_type(HttpClient $client, Factory $factory, Response $response, Stream $body)
{
$data = file_get_contents('spec/Packagist/Api/Fixture/all.json');
$response->getBody()->shouldBeCalled()->willReturn($data);
$response->getBody()->shouldBeCalled()->willReturn($body);
$body->__toString()->shouldBeCalled()->willReturn($data);

$client->request('GET', 'https://packagist.org/packages/list.json?type=library')->shouldBeCalled()->willReturn($response);

Expand All @@ -105,10 +113,11 @@ function it_filters_package_names_by_type(HttpClient $client, Factory $factory,
$this->all(array('type' => 'library'));
}

function it_filters_package_names_by_vendor(HttpClient $client, Factory $factory, Response $response)
function it_filters_package_names_by_vendor(HttpClient $client, Factory $factory, Response $response, Stream $body)
{
$data = file_get_contents('spec/Packagist/Api/Fixture/all.json');
$response->getBody()->shouldBeCalled()->willReturn($data);
$response->getBody()->shouldBeCalled()->willReturn($body);
$body->__toString()->shouldBeCalled()->willReturn($data);

$client->request('GET', 'https://packagist.org/packages/list.json?vendor=sylius')->shouldBeCalled()->willReturn($response);

Expand Down

0 comments on commit 8fd1411

Please sign in to comment.