<commit_before><?php

namespace P\IQuery\test;

use ArrayIterator;
use PHPUnit_Framework_TestCase;
use P\IQuery\IQuery;

/**
 * @group iterator
 */
class IQueryTest extends PHPUnit_Framework_TestCase
{
    private $stmt;
    private $iterator;
    private $data = ['john', 'jane', 'foo', 'bar'];

    public function setUp()
    {
        $this->stmt = new Iquery(new ArrayIterator($this->data));
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testSetLimit()
    {
        $this->stmt->setLimit(1);
        $iterator = $this->stmt->queryIterator();
        $res = iterator_to_array($iterator);
        $this->assertCount(1, $res);

        $this->stmt->setLimit(-4);
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testSetOffset()
    {
        $this->stmt->setOffset(1);
        $iterator = $this->stmt->queryIterator();
        $res = iterator_to_array($iterator);
        $this->assertCount(3, $res);

        $this->stmt->setOffset('toto');
    }

    public function testIntervalLimitTooLong()
    {
        $this->stmt->setOffset(3);
        $this->stmt->setLimit(10);
        $iterator = $this->stmt->queryIterator();
        $res = iterator_to_array($iterator);
        $this->assertSame([3 => 'bar'], $res);
        $this->assertCount(1, $res);
    }

    public function testInterval()
    {
        $this->stmt->setOffset(1);
        $this->stmt->setLimit(1);
        $iterator = $this->stmt->queryIterator();
        $res = iterator_to_array($iterator);
        $this->assertCount(1, $res);
    }

    public function testWhere()
    {
        $func = function ($row) {
            return false !== strpos($row, 'o');
        };
        $this->stmt->setWhere($func);

        $iterator =$this->stmt->queryIterator();
        $this->assertCount(2, iterator_to_array($iterator, false));

        $func2 = function ($row) {
            return false !== strpos($row, 'j');
        };
        $this->stmt->addWhere($func2);
        $this->stmt->addWhere($func);

        $iterator = $this->stmt->queryIterator();
        $this->assertCount(1, iterator_to_array($iterator, false));

        $this->stmt->addWhere($func2);
        $this->stmt->addWhere($func);
        $this->assertTrue($this->stmt->hasWhere($func2));
        $this->stmt->removeWhere($func2);
        $this->assertFalse($this->stmt->hasWhere($func2));

        $iterator = $this->stmt->queryIterator();
        $this->assertCount(2, iterator_to_array($iterator, false));
    }

    public function testSortBy()
    {
        $this->stmt->setSortBy('strcmp');
        $iterator = $this->stmt->queryIterator();
        $res = iterator_to_array($iterator, false);
        $this->assertSame(['bar', 'foo', 'jane', 'john'], $res);

        $this->stmt->addSortBy('strcmp');
        $this->stmt->addSortBy('strcmp');
        $this->stmt->removeSortBy('strcmp');
        $this->assertTrue($this->stmt->hasSortBy('strcmp'));
        $iterator = $this->stmt->queryIterator();
        $res = iterator_to_array($iterator, false);
        $this->assertSame(['bar', 'foo', 'jane', 'john'], $res);
    }

    public function testExecuteWithCallback()
    {
        $func = function ($value) {
            return strtoupper($value);
        };
<commit_msg>remove setWhere from testing<commit_after><?php

namespace P\IQuery\test;

use ArrayIterator;
use PHPUnit_Framework_TestCase;
use P\IQuery\IQuery;

/**
 * @group iterator
 */
class IQueryTest extends PHPUnit_Framework_TestCase
{
    private $stmt;
    private $iterator;
    private $data = ['john', 'jane', 'foo', 'bar'];

    public function setUp()
    {
        $this->stmt = new Iquery(new ArrayIterator($this->data));
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testSetLimit()
    {
        $this->stmt->setLimit(1);
        $iterator = $this->stmt->queryIterator();
        $res = iterator_to_array($iterator);
        $this->assertCount(1, $res);

        $this->stmt->setLimit(-4);
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testSetOffset()
    {
        $this->stmt->setOffset(1);
        $iterator = $this->stmt->queryIterator();
        $res = iterator_to_array($iterator);
        $this->assertCount(3, $res);

        $this->stmt->setOffset('toto');
    }

    public function testIntervalLimitTooLong()
    {
        $this->stmt->setOffset(3);
        $this->stmt->setLimit(10);
        $iterator = $this->stmt->queryIterator();
        $res = iterator_to_array($iterator);
        $this->assertSame([3 => 'bar'], $res);
        $this->assertCount(1, $res);
    }

    public function testInterval()
    {
        $this->stmt->setOffset(1);
        $this->stmt->setLimit(1);
        $iterator = $this->stmt->queryIterator();
        $res = iterator_to_array($iterator);
        $this->assertCount(1, $res);
    }

    public function testWhere()
    {
        $func = function ($row) {
            return false !== strpos($row, 'o');
        };
        $this->stmt->addWhere($func);

        $iterator =$this->stmt->queryIterator();
        $this->assertCount(2, iterator_to_array($iterator, false));

        $func2 = function ($row) {
            return false !== strpos($row, 'j');
        };
        $this->stmt->addWhere($func2);
        $this->stmt->addWhere($func);

        $iterator = $this->stmt->queryIterator();
        $this->assertCount(1, iterator_to_array($iterator, false));

        $this->stmt->addWhere($func2);
        $this->stmt->addWhere($func);
        $this->assertTrue($this->stmt->hasWhere($func2));
        $this->stmt->removeWhere($func2);
        $this->assertFalse($this->stmt->hasWhere($func2));

        $iterator = $this->stmt->queryIterator();
        $this->assertCount(2, iterator_to_array($iterator, false));
    }

    public function testSortBy()
    {
        $this->stmt->addSortBy('strcmp');
        $iterator = $this->stmt->queryIterator();
        $res = iterator_to_array($iterator, false);
        $this->assertSame(['bar', 'foo', 'jane', 'john'], $res);

        $this->stmt->addSortBy('strcmp');
        $this->stmt->addSortBy('strcmp');
        $this->stmt->removeSortBy('strcmp');
        $this->assertTrue($this->stmt->hasSortBy('strcmp'));
        $iterator = $this->stmt->queryIterator();
        $res = iterator_to_array($iterator, false);
        $this->assertSame(['bar', 'foo', 'jane', 'john'], $res);
    }

    public function testExecuteWithCallback()
    {
        $func = function ($value) {
            return strtoupper($value);
        };

{'fraction_non_alphanumeric': 0.18121513643901704, 'fraction_numerical': 0.006633499170812604, 'mean_word_length': 2.625136612021858, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 155, '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': '191980', 'n_tokens_mistral': 2015, 'n_tokens_neox': 1986, 'n_words': 321}