<commit_before><?php
/**
 * Test class for Crunchmail\Collections\GenericCollection
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2015 (c) Oasiswork
 * @license   https://opensource.org/licenses/MIT MIT
 */

namespace Crunchmail\Tests;

use Crunchmail;

/**
 * Test class
 *
 * @covers \Crunchmail\Collections\GenericCollection
 * @coversDefaultClass \Crunchmail\Collections\GenericCollection
 */
class GenericCollectionTest extends TestCase
{

    /* ---------------------------------------------------------------------
     * Providers
     * --------------------------------------------------------------------- */
    public function directionProvider()
    {
        return [
            ['next', 'messages', 'messages_page_2'],
            ['previous', 'messages_page_2', 'messages']
        ];
    }

    /* ---------------------------------------------------------------------
     * Tests
     * --------------------------------------------------------------------- */

    /**
     * @covers ::current
     * @covers ::count
     * @covers ::pageCount
     *
     * @todo test generic collection
     */
    public function testCollectionCanBeRetrieveAsAnArray()
    {
        $client = $this->quickMock(['messages', 200]);

        $collection = $client->messages->get();

        var_dump($collection);

        $arr = $collection->current();

        $this->assertInternalType('array', $arr);

        $body = $this->getSentBody(0);
        $this->assertSame($body->count, $collection->count());
        $this->assertSame($body->page_count, $collection->pageCount());
    }

    /**
     * @covers ::previous
     * @covers ::next
     * @covers ::getAdjacent
     * @covers ::getResponse
     *
     * @dataProvider directionProvider
     */
    public function testRetrievingNextPage($direction, $msg1, $msg2)
    {
        $client = $this->quickMock(
            [$msg1, 200],
            [$msg2, 200]
        );
        $collection = $client->messages->get();

        $nextUrl = $collection->getResponse()->$direction;

        $collection->$direction();

        $request = $this->getHistoryRequest(1);

        $this->assertEquals($nextUrl, (string) $request->getUri());
    }

    /**
     * @covers ::previous
     * @covers ::next
     * @covers ::getAdjacent
     *
     * @dataProvider directionProvider
     */
    public function testRetrievingEmptyPageReturnsNull($direction)
    {
        $client = $this->quickMock(
            ['messages_one_page', 200],
            ['messages_one_page', 200]
        );
        $collection = $client->messages->get();
        $res = $collection->$direction();

        $this->assertNull($res);
    }

    /**
     * @covers ::refresh
     */
    public function testRefreshActuallyCallTheApi()
    {
        $client = $this->quickMock(
            ['messages', 200],
            ['messages_page_2', 200]
        );
        $collection = $client->messages->get();

        $res = $collection->refresh();

        $history = $this->getHistory();
<commit_msg>test: Enhance tests for travis debuggingc<commit_after><?php
/**
 * Test class for Crunchmail\Collections\GenericCollection
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2015 (c) Oasiswork
 * @license   https://opensource.org/licenses/MIT MIT
 */

namespace Crunchmail\Tests;

use Crunchmail;

/**
 * Test class
 *
 * @covers \Crunchmail\Collections\GenericCollection
 * @coversDefaultClass \Crunchmail\Collections\GenericCollection
 */
class GenericCollectionTest extends TestCase
{

    /* ---------------------------------------------------------------------
     * Providers
     * --------------------------------------------------------------------- */
    public function directionProvider()
    {
        return [
            ['next', 'messages', 'messages_page_2'],
            ['previous', 'messages_page_2', 'messages']
        ];
    }

    /* ---------------------------------------------------------------------
     * Tests
     * --------------------------------------------------------------------- */

    /**
     * @covers ::__construct
     */
    public function testResponseWithResultsFieldReturnACollection()
    {
        $client = $this->quickMock(['messages', 200]);
        $collection = $client->messages->get();
        $this->assertCollection($collection);
    }

    /**
     * @depends testResponseWithResultsFieldReturnACollection
     *
     * @covers ::current
     * @covers ::count
     * @covers ::pageCount
     */
    public function testCollectionCanBeRetrieveAsAnArray()
    {
        $client = $this->quickMock(['messages', 200]);
        $collection = $client->messages->get();
        $this->assertCollection($collection);

        $arr = $collection->current();

        $this->assertInternalType('array', $arr);

        $body = $this->getSentBody(0);
        $this->assertSame($body->count, $collection->count());
        $this->assertSame($body->page_count, $collection->pageCount());
    }

    /**
     * @depends testResponseWithResultsFieldReturnACollection
     * @dataProvider directionProvider
     *
     * @covers ::previous
     * @covers ::next
     * @covers ::getAdjacent
     * @covers ::getResponse
     */
    public function testRetrievingNextPage($direction, $msg1, $msg2)
    {
        $client = $this->quickMock(
            [$msg1, 200],
            [$msg2, 200]
        );
        $collection = $client->messages->get();

        $nextUrl = $collection->getResponse()->$direction;

        $collection->$direction();

        $request = $this->getHistoryRequest(1);

        $this->assertEquals($nextUrl, (string) $request->getUri());
    }

    /**
     * @depends testResponseWithResultsFieldReturnACollection
     * @dataProvider directionProvider
     *
     * @covers ::previous
     * @covers ::next
     * @covers ::getAdjacent
     */
    public function testRetrievingEmptyPageReturnsNull($direction)
    {
        $client = $this->quickMock(
            ['messages_one_page', 200],
            ['messages_one_page', 200]
        );
        $collection = $client->messages->get();
        $res = $collection->$direction();

        $this->assertNull($res);
    }

    /**
     * @depends testResponseWithResultsFieldReturnACollection
     *
     * @covers ::refresh
     */
    public function testRefreshActuallyCallTheApi()
    {
        $client = $this->quickMock(
            ['messages', 200],
            ['messages_page_2', 200]
        );
        $collection = $client->messages->get();

        $res = $collection->refresh();

        $history = $this->getHistory();

{'fraction_non_alphanumeric': 0.22266099635479952, 'fraction_numerical': 0.010783718104495747, 'mean_word_length': 1.8261802575107295, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 76, 'https://': 2, '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': '1359110', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1719, 'n_words': 300}