<commit_before><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 * @package   Zend_Paginator
 */

namespace ZendTest\Paginator\Adapter;

use Zend\Paginator\Adapter\DbSelect;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Expression;

/**
 * @category   Zend
 * @package    Zend_Paginator
 * @subpackage UnitTests
 * @group      Zend_Paginator
 */
class DbSelectTest extends \PHPUnit_Framework_TestCase
{
    /** @var \PHPUnit_Framework_MockObject_MockObject */
    protected $mockSelect;

    /** @var \PHPUnit_Framework_MockObject_MockObject */
    protected $mockStatement;

    /** @var \PHPUnit_Framework_MockObject_MockObject */
    protected $mockResult;

    /** @var \PHPUnit_Framework_MockObject_MockObject */
    protected $mockSql;

    /** @var DbSelect */
    protected $dbSelect;

    public function setup()
    {
        $mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
        $this->mockStatement = $mockStatement;

        $mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');

        $mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
        $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
        $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult));
        $mockPlatform = $this->getMock('Zend\Db\Adapter\Platform\PlatformInterface');
        $mockPlatform->expects($this->any())->method('getName')->will($this->returnValue('platform'));
        $mockAdapter = $this->getMockForAbstractClass(
            'Zend\Db\Adapter\Adapter',
            array($mockDriver, $mockPlatform)
        );

        $mockSql = $this->getMock(
            'Zend\Db\Sql\Sql',
            array('prepareStatementForSqlObject', 'execute'),
            array($mockAdapter)
        );

        $this->mockSql = $mockSql;
        $this->mockSelect = $this->getMock('Zend\Db\Sql\Select');
        $this->mockResult = $mockResult;
        $this->dbSelect = new DbSelect($this->mockSelect, $mockSql);
    }

    public function testGetItems()
    {
        $this->mockSelect->expects($this->once())->method('limit')->with($this->equalTo(10));
        $this->mockSelect->expects($this->once())->method('offset')->with($this->equalTo(2));
        $items = $this->dbSelect->getItems(2, 10);
        $this->assertInstanceOf('Zend\Db\ResultSet\ResultSet', $items);
    }

    public function testCount()
    {
        $this->mockSql->expects($this->once())
            ->method('prepareStatementForSqlObject')
            ->with($this->isInstanceOf('Zend\Db\Sql\Select'))
            ->will($this->returnValue($this->mockStatement));
        $this->mockSql->expects($this->any())->method('execute')->will($this->returnValue($this->mockResult));
        $this->mockResult->expects($this->once())->method('current')->will($this->returnValue(array('c' => 5)));

        $this->mockSelect->expects($this->exactly(3))->method('reset'); // called for columns, limit, offset, order

        $count = $this->dbSelect->count();
        $this->assertEquals(5, $count);
    }
}<commit_msg>Zend\Paginator - reorganized the Mock setup for getItems and count tests to work<commit_after><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 * @package   Zend_Paginator
 */

namespace ZendTest\Paginator\Adapter;

use Zend\Paginator\Adapter\DbSelect;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Expression;

/**
 * @category   Zend
 * @package    Zend_Paginator
 * @subpackage UnitTests
 * @group      Zend_Paginator
 */
class DbSelectTest extends \PHPUnit_Framework_TestCase
{
    /** @var \PHPUnit_Framework_MockObject_MockObject */
    protected $mockSelect;

    /** @var \PHPUnit_Framework_MockObject_MockObject */
    protected $mockStatement;

    /** @var \PHPUnit_Framework_MockObject_MockObject */
    protected $mockResult;

    /** @var \PHPUnit_Framework_MockObject_MockObject */
    protected $mockSql;

    /** @var DbSelect */
    protected $dbSelect;

    public function setup()
    {
        $mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
        $this->mockResult = $mockResult;

        $mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
        $this->mockStatement = $mockStatement;

        $this->mockStatement->expects($this->any())->method('execute')->will($this->returnValue($this->mockResult));

        $mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
        $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));

        $mockPlatform = $this->getMock('Zend\Db\Adapter\Platform\PlatformInterface');
        $mockPlatform->expects($this->any())->method('getName')->will($this->returnValue('platform'));
        $mockAdapter = $this->getMockForAbstractClass(
            'Zend\Db\Adapter\Adapter',
            array($mockDriver, $mockPlatform)
        );

        $mockSql = $this->getMock(
            'Zend\Db\Sql\Sql',
            array('prepareStatementForSqlObject', 'execute'),
            array($mockAdapter)
        );
        $this->mockSql = $mockSql;
        $this->mockSql->expects($this->once())
            ->method('prepareStatementForSqlObject')
            ->with($this->isInstanceOf('Zend\Db\Sql\Select'))
            ->will($this->returnValue($this->mockStatement));


        $this->mockSelect = $this->getMock('Zend\Db\Sql\Select');

        $this->dbSelect = new DbSelect($this->mockSelect, $mockSql);
    }

    public function testGetItems()
    {
        $this->mockSelect->expects($this->once())->method('limit')->with($this->equalTo(10));
        $this->mockSelect->expects($this->once())->method('offset')->with($this->equalTo(2));
        $items = $this->dbSelect->getItems(2, 10);
        $this->assertInstanceOf('Zend\Db\ResultSet\ResultSet', $items);
    }

    public function testCount()
    {
        $this->mockResult->expects($this->once())->method('current')->will($this->returnValue(array('c' => 5)));

        $this->mockSelect->expects($this->exactly(3))->method('reset'); // called for columns, limit, offset, order

        $count = $this->dbSelect->count();
        $this->assertEquals(5, $count);
    }
}
{'fraction_non_alphanumeric': 0.17388081826267418, 'fraction_numerical': 0.005336495701156241, 'mean_word_length': 3.3783257624918885, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 144, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3307842', 'n_tokens_mistral': 2052, 'n_tokens_neox': 1986, 'n_words': 280}