<commit_before><?php

namespace KG\Pager\Tests\Adapter;

use KG\Pager\Adapter\MongoAdapter;

class MongoAdapterTest extends \PHPUnit_Framework_TestCase
{
    protected function setUp()
    {
        if (!class_exists('\MongoCursor')) {
            $this->markTestSkipped('ext/mongodb must be installed to run this test');
        }
    }

    public function testGetItemCountDelegatesToCount()
    {
        $cursor = $this->getMockCursor();

        $cursor
            ->expects($this->once())
            ->method('count')
            ->willReturn(5)
        ;

        $adapter = new MongoAdapter($cursor);
        $this->assertEquals(5, $adapter->getItemCount());
    }

    public function testGetItemsDelegatesToCursor()
    {
        $cursor = $this->getMockCursor();

        $cursor
            ->expects($this->once())
            ->method('skip')
            ->with($this->equalTo(10))
        ;

        $cursor
            ->expects($this->once())
            ->method('limit')
            ->with($this->equalTo(2))
        ;

        $this->mockIterator($cursor, $expected = array('foo', 'bar'));

        $adapter = new MongoAdapter($cursor);
        $this->assertEquals($expected, $adapter->getItems(10, 2));
    }

    private function getMockCursor()
    {
        return $this
            ->getMockBuilder('\MongoCursor')
            ->disableOriginalConstructor()
            ->getMock()
        ;
    }

    private function mockIterator($mock, $values)
    {
        $iterator = new \ArrayIterator($values);

        $methodsToMock = array(
            'current',
            'key',
            'next',
            'rewind',
            'valid',
        );

        foreach ($methodsToMock as $methodToMock) {
            $mock
                ->method($methodToMock)
                ->will($this->returnCallback(function () use ($iterator, $methodToMock) {
                    return call_user_method_array($methodToMock, $iterator, func_get_args());
                }))
            ;
        }
    }
}<commit_msg>Replace deprecated call_user_method_array with call_user_func_array<commit_after><?php

namespace KG\Pager\Tests\Adapter;

use KG\Pager\Adapter\MongoAdapter;

class MongoAdapterTest extends \PHPUnit_Framework_TestCase
{
    protected function setUp()
    {
        if (!class_exists('\MongoCursor')) {
            $this->markTestSkipped('ext/mongodb must be installed to run this test');
        }
    }

    public function testGetItemCountDelegatesToCount()
    {
        $cursor = $this->getMockCursor();

        $cursor
            ->expects($this->once())
            ->method('count')
            ->willReturn(5)
        ;

        $adapter = new MongoAdapter($cursor);
        $this->assertEquals(5, $adapter->getItemCount());
    }

    public function testGetItemsDelegatesToCursor()
    {
        $cursor = $this->getMockCursor();

        $cursor
            ->expects($this->once())
            ->method('skip')
            ->with($this->equalTo(10))
        ;

        $cursor
            ->expects($this->once())
            ->method('limit')
            ->with($this->equalTo(2))
        ;

        $this->mockIterator($cursor, $expected = array('foo', 'bar'));

        $adapter = new MongoAdapter($cursor);
        $this->assertEquals($expected, $adapter->getItems(10, 2));
    }

    private function getMockCursor()
    {
        return $this
            ->getMockBuilder('\MongoCursor')
            ->disableOriginalConstructor()
            ->getMock()
        ;
    }

    private function mockIterator($mock, $values)
    {
        $iterator = new \ArrayIterator($values);

        $methodsToMock = array(
            'current',
            'key',
            'next',
            'rewind',
            'valid',
        );

        foreach ($methodsToMock as $methodToMock) {
            $mock
                ->method($methodToMock)
                ->will($this->returnCallback(function () use ($iterator, $methodToMock) {
                    return call_user_func_array(array($iterator, $methodToMock), func_get_args());
                }))
            ;
        }
    }
}
{'fraction_non_alphanumeric': 0.13881499395405078, 'fraction_numerical': 0.0038694074969770256, 'mean_word_length': 1.8465244322092222, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '5545128', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1115, 'n_words': 194}