<commit_before><?php
namespace Bolt\Tests\Composer\Satis;

use Bolt\Composer\Satis\QueryService;
use Bolt\Tests\BoltUnitTest;

/**
 * Class to test src/Composer/Satis/QueryService.
 *
 * @author <NAME> <<EMAIL>>
 */
class QueryServiceTest extends BoltUnitTest
{
    public function testPackageInfoValid()
    {
        $app = $this->getApp();
        $service = new QueryService($app['guzzle.client'], $app['extend.site'], $app['extend.urls']);

        $response = $service->info('gawain/clippy', '2.0.0');
        $this->assertObjectHasAttribute('package', $response);
        $this->assertObjectHasAttribute('version', $response);
    }

    public function testPackageInfoInvalid()
    {
        $app = $this->getApp();
        $service = new QueryService($app['guzzle.client'], $app['extend.site'], $app['extend.urls']);

        $response = $service->info('rossriley/mytest', '2.0.0');
        $this->assertObjectHasAttribute('package', $response);
        $this->assertObjectHasAttribute('version', $response);
        $this->assertFalse($response->package);
        $this->assertFalse($response->version);
    }

    public function testInfoList()
    {
        $app = $this->getApp();
        $service = new QueryService($app['guzzle.client'], $app['extend.site'], $app['extend.urls']);

        $response = $service->all();
        $this->assertObjectHasAttribute('packages', $response);
        $this->assertNotCount(0, $response->packages);
    }
}<commit_msg>[Tests] Use Guzzle mocks in QueryServiceTest<commit_after><?php
namespace Bolt\Tests\Composer\Satis;

use Bolt\Composer\Satis\QueryService;
use Bolt\Tests\BoltUnitTest;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;

/**
 * Class to test src/Composer/Satis/QueryService.
 *
 * @author <NAME> <<EMAIL>>
 */
class QueryServiceTest extends BoltUnitTest
{
    public function testPackageInfoValid()
    {
        $app = $this->getApp();
        $mock = new MockHandler([
            new Response(200, [], json_encode(['package' => 'gawain/clippy', 'version' => '2.3.4'])),
        ]);
        $handler = HandlerStack::create($mock);
        $client = new Client(['handler' => $handler]);

        $service = new QueryService($client, $app['extend.site'], $app['extend.urls']);

        $response = $service->info('gawain/clippy', '2.0.0');
        $this->assertObjectHasAttribute('package', $response);
        $this->assertObjectHasAttribute('version', $response);
    }

    public function testPackageInfoInvalid()
    {
        $app = $this->getApp();
        $mock = new MockHandler([
            new Response(200, [], json_encode(['package' => false, 'version' => false])),
        ]);
        $handler = HandlerStack::create($mock);
        $client = new Client(['handler' => $handler]);

        $service = new QueryService($client, $app['extend.site'], $app['extend.urls']);

        $response = $service->info('rossriley/mytest', '2.0.0');
        $this->assertObjectHasAttribute('package', $response);
        $this->assertObjectHasAttribute('version', $response);
        $this->assertFalse($response->package);
        $this->assertFalse($response->version);
    }

    public function testInfoList()
    {
        $app = $this->getApp();
        $mock = new MockHandler([
            new Response(200, [], json_encode(['packages' => [
                ['gawain/clippy', 'version' => '2.3.4'],
                ['evil/clippy', 'version' => '0.0.1'],
            ]])),
        ]);
        $handler = HandlerStack::create($mock);
        $client = new Client(['handler' => $handler]);

        $service = new QueryService($client, $app['extend.site'], $app['extend.urls']);

        $response = $service->all();
        $this->assertObjectHasAttribute('packages', $response);
        $this->assertNotCount(0, $response->packages);
    }
}
{'fraction_non_alphanumeric': 0.1811631497683994, 'fraction_numerical': 0.008492022645393721, 'mean_word_length': 3.225, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5136378', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1152, 'n_words': 201}