<commit_before><?php

use Mathiasd88\MercadoPublico\MercadoPublico;

class MercadoPublicoTest extends PHPUnit_Framework_TestCase
{
    protected $defaultTicket = 'F8537A18-6766-4DEF-9E59-426B4FEE2844';

    protected $defaultDate = '02022014';

    /**
     * Creates a MercadoPublico instans for testing purposes.
     * 
     * @return MercadoPublico
     */
    private function createMercadoPublicoInstance()
    {
        $mercadoPublico = new MercadoPublico($this->defaultTicket);

        return $mercadoPublico;
    }

    /**
     * Valid response for requests (Quizás la cantidad máxima de peticiones diarias se supere).
     * 
     * @param  Mathiasd88\MercadoPublico\MercadoPublico $response
     * @return boolean
     */
    private function validResponse($response)
    {
        return ($response->status == 200 || $response->message = 'Ticket superó la cuota diaria asignada.');
    }

    /** @test */
    public function it_can_be_instanciated()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();

        $this->assertTrue($mercadoPublico instanceof MercadoPublico);
    }

    /** @test */
    public function it_can_search_provider()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();

        $response = $mercadoPublico->buscarProveedor('70.017.820-k'); // Rut real de ejempl->get()o

        $this->assertTrue($this->validResponse($response));
    }

    /** @test */
    public function it_can_search_buyers()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();

        $response = $mercadoPublico->buscarComprador()->get();

        $this->assertTrue($this->validResponse($response));
    }

    /** @test */
    public function it_can_search_licitaciones()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();

        $response = $mercadoPublico->licitaciones()->get();

        $this->assertTrue($this->validResponse($response));
    }

    /** @test */
    public function it_can_search_licitaciones_by_date()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();

        $response = $mercadoPublico->licitaciones()->fecha('02022014')->get();

        $this->assertTrue($this->validResponse($response));
    }

    /** @test */
    public function it_can_search_licitaciones_by_code()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();

        $response = $mercadoPublico->licitaciones()->codigo('1509-5-L114')->get();

        $this->assertTrue($this->validResponse($response));
    }

    /** @test */
    public function it_can_search_licitaciones_by_status()
    {
        $estados = [
            'publicada',
            'activas',
            'cerrada',
            'desierta',
            'adjudicada',
            'revocada',
            'suspendida',
            'todos'
        ];

        $mercadoPublico = $this->createMercadoPublicoInstance();

        $response = $mercadoPublico->licitaciones()->estado(array_rand($estados))->get();

        $this->assertTrue($this->validResponse($response));
    }

    /** @test */
    public function it_can_search_licitaciones_by_codigo_de_organismo()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();<commit_msg>Fix prueba, ahora toma valores (y no keys) aleatorios para prueba de estados<commit_after><?php

use Mathiasd88\MercadoPublico\MercadoPublico;

class MercadoPublicoTest extends PHPUnit_Framework_TestCase
{
    protected $defaultTicket = 'F8537A18-6766-4DEF-9E59-426B4FEE2844';

    protected $defaultDate = '02022014';

    /**
     * Creates a MercadoPublico instans for testing purposes.
     * 
     * @return MercadoPublico
     */
    private function createMercadoPublicoInstance()
    {
        $mercadoPublico = new MercadoPublico($this->defaultTicket);

        return $mercadoPublico;
    }

    /**
     * Valid response for requests (Quizás la cantidad máxima de peticiones diarias se supere).
     * 
     * @param  Mathiasd88\MercadoPublico\MercadoPublico $response
     * @return boolean
     */
    private function validResponse($response)
    {
        return ($response->status == 200 || $response->message = 'Ticket superó la cuota diaria asignada.');
    }

    /** @test */
    public function it_can_be_instanciated()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();

        $this->assertTrue($mercadoPublico instanceof MercadoPublico);
    }

    /** @test */
    public function it_can_search_provider()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();

        $response = $mercadoPublico->buscarProveedor('70.017.820-k'); // Rut real de ejempl->get()o

        $this->assertTrue($this->validResponse($response));
    }

    /** @test */
    public function it_can_search_buyers()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();

        $response = $mercadoPublico->buscarComprador()->get();

        $this->assertTrue($this->validResponse($response));
    }

    /** @test */
    public function it_can_search_licitaciones()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();

        $response = $mercadoPublico->licitaciones()->get();

        $this->assertTrue($this->validResponse($response));
    }

    /** @test */
    public function it_can_search_licitaciones_by_date()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();

        $response = $mercadoPublico->licitaciones()->fecha('02022014')->get();

        $this->assertTrue($this->validResponse($response));
    }

    /** @test */
    public function it_can_search_licitaciones_by_code()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();

        $response = $mercadoPublico->licitaciones()->codigo('1509-5-L114')->get();

        $this->assertTrue($this->validResponse($response));
    }

    /** @test */
    public function it_can_search_licitaciones_by_status()
    {
        $estados = [
            'publicada',
            'activas',
            'cerrada',
            'desierta',
            'adjudicada',
            'revocada',
            'suspendida',
            'todos'
        ];

        $randomValue = array_rand($estados);

        $mercadoPublico = $this->createMercadoPublicoInstance();

        $response = $mercadoPublico->licitaciones()->estado($estados[$randomValue])->get();

        $this->assertTrue($this->validResponse($response));
    }

    /** @test */
    public function it_can_search_licitaciones_by_codigo_de_organismo()
    {
        $mercadoPublico = $this->createMercadoPublicoInstance();
{'fraction_non_alphanumeric': 0.13394077448747152, 'fraction_numerical': 0.018526955201214883, 'mean_word_length': 2.8901358535144714, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, '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': '1050375', 'n_tokens_mistral': 2147, 'n_tokens_neox': 2036, 'n_words': 299}