<commit_before><?php

use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\History;
use EvdB\OpenExchangeRates\OpenExchangeRates;
use GuzzleHttp\Subscriber\Mock;
use GuzzleHttp\Message\Response;

class TestOpenExchangeRates extends PHPUnit_Framework_TestCase
{

    /**
     * @var \GuzzleHttp\ClientInterface
     */
    protected $client;

    /**
     * @var \GuzzleHttp\Subscriber\History
     */
    protected $history;


    protected function buildClient($options = [], $enableHistory = true)
    {
        $client = new Client($options);

        if ($enableHistory === true) {
            $this->history = new History();
            $client->getEmitter()->attach($this->history);
        }

        return $client;
    }

    protected function mockResponses(\GuzzleHttp\ClientInterface &$client, array $responses)
    {
        $client->getEmitter()->attach(new Mock($responses));
    }

    protected function buildExchangeRateClient($options = null, $client = null)
    {
        return new OpenExchangeRates(
            $options ?: ['app_id' => 'testappid'],
            $client ?: $this->buildClient()
        );
    }

    public function testCreationOfRequests()
    {
        $exchange = $this->buildExchangeRateClient(null, $client = $this->buildClient());

        //mock 5 responses
        $this->mockResponses($client, array_fill(0, 5, new Response(200)));

        $interfaceMethods = [
            'latest' => [],
            'currencies' => [],
            'historical' => [DateTime::createFromFormat('Y-m-d', '2015-12-31')],
            'timeSeries' => [DateTime::createFromFormat('Y-m-d', '2015-12-30'), DateTime::createFromFormat('Y-m-d', '2015-12-31')],
            'convert' => [rand(0, 100), 'USD', 'EUR']
        ];

        foreach ($interfaceMethods as $method => $args) {
            call_user_func_array([$exchange, $method], $args);
        }

        $this->assertCount(5, $this->history, '5 requests should be made');
    }

    /**
     * @expectedException \EvdB\OpenExchangeRates\Exception\ResourceNotFound
     */
    public function testJsonpCallbackPresence()
    {
        $exchange = $this->buildExchangeRateClient(null, $client = $this->buildClient());

        $this->mockResponses($client, [new Response(200)]);

        $exchange->jsonp('latest', [], 'testMyCallback');

        $this->assertEquals('testMyCallback', $this->history->getLastRequest()->getQuery()->get('callback'));

        //will throw expected exception
        $exchange->jsonp('invalid', [], 'myInvalidCallback');<commit_msg>php 54 datetimefromformat not working as expected<commit_after><?php

use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\History;
use EvdB\OpenExchangeRates\OpenExchangeRates;
use GuzzleHttp\Subscriber\Mock;
use GuzzleHttp\Message\Response;

class TestOpenExchangeRates extends PHPUnit_Framework_TestCase
{

    /**
     * @var \GuzzleHttp\ClientInterface
     */
    protected $client;

    /**
     * @var \GuzzleHttp\Subscriber\History
     */
    protected $history;


    protected function buildClient($options = [], $enableHistory = true)
    {
        $client = new Client($options);

        if ($enableHistory === true) {
            $this->history = new History();
            $client->getEmitter()->attach($this->history);
        }

        return $client;
    }

    protected function mockResponses(\GuzzleHttp\ClientInterface &$client, array $responses)
    {
        $client->getEmitter()->attach(new Mock($responses));
    }

    protected function buildExchangeRateClient($options = null, $client = null)
    {
        return new OpenExchangeRates(
            $options ?: ['app_id' => 'testappid'],
            $client ?: $this->buildClient()
        );
    }

    public function testCreationOfRequests()
    {
        $exchange = $this->buildExchangeRateClient(null, $client = $this->buildClient());

        //mock 5 responses
        $this->mockResponses($client, array_fill(0, 5, new Response(200)));

        $interfaceMethods = [
            'latest' => [],
            'currencies' => [],
            'historical' => [DateTime::createFromFormat('Y-m-d', '2015-12-29')],
            'timeSeries' => [DateTime::createFromFormat('Y-m-d', '2015-12-30'), DateTime::createFromFormat('Y-m-d', '2015-12-31')],
            'convert' => [rand(0, 100), 'USD', 'EUR']
        ];

        foreach ($interfaceMethods as $method => $args) {
            call_user_func_array([$exchange, $method], $args);
        }

        $this->assertCount(5, $this->history, '5 requests should be made');
    }

    /**
     * @expectedException \EvdB\OpenExchangeRates\Exception\ResourceNotFound
     */
    public function testJsonpCallbackPresence()
    {
        $exchange = $this->buildExchangeRateClient(null, $client = $this->buildClient());

        $this->mockResponses($client, [new Response(200)]);

        $exchange->jsonp('latest', [], 'testMyCallback');

        $this->assertEquals('testMyCallback', $this->history->getLastRequest()->getQuery()->get('callback'));

        //will throw expected exception
        $exchange->jsonp('invalid', [], 'myInvalidCallback');
{'fraction_non_alphanumeric': 0.15579851620460758, 'fraction_numerical': 0.015618898867629832, 'mean_word_length': 2.8664150943396227, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '7636725', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1442, 'n_words': 265}