<commit_before><?php

namespace CascadeEnergy\Tests\ElasticSearch;

use CascadeEnergy\ElasticSearch\Bulk;

class BulkTest extends \PHPUnit_Framework_TestCase
{
    /** @var Bulk */
    private $bulk;

    /** @var \PHPUnit_Framework_MockObject_MockObject */
    private $client;

    public function setUp()
    {
        $this->client = $this->getMock('Elasticsearch\Client');

        /** @noinspection PhpParamsInspection */
        $this->bulk = new Bulk($this->client, 'index', 'type', 3);
    }

    public function testItShouldAllowItemsToBeAddedToTheBulkOperation()
    {
        $this->bulk->addItem('idFoo', 'foo');
        $this->bulk->addItem('idBar', 'bar', 'update');

        $this->assertAttributeEquals(
            [
                ['index' => ['_id' => 'idFoo']],
                'foo',
                ['update' => ['_id' => 'idBar']],
                'bar'
            ],
            'itemList',
            $this->bulk
        );

        $this->assertEquals(2, $this->bulk->getItemCount());
    }

    public function testItShouldFlushAutomaticallyWhenTooManyItemsHaveBeenAdded()
    {
        $this->client->expects($this->once())->method('bulk');

        $this->bulk->addItem('idFoo', 'foo');
        $this->bulk->addItem('idBar', 'bar');
        $this->bulk->addItem('idBaz', 'baz');

        $this->assertEquals(0, $this->bulk->getItemCount());
    }

    public function testItShouldFlushWhenBeginAndEndAreCalled()
    {
        $this->client->expects($this->exactly(2))->method('bulk');

        $this->bulk->addItem('idFoo', 'foo');
        $this->bulk->begin();

        $this->bulk->addItem('idFoo', 'foo');
        $this->bulk->end();
    }
<commit_msg>Update unit tests for index and type support<commit_after><?php

namespace CascadeEnergy\Tests\ElasticSearch;

use CascadeEnergy\ElasticSearch\Bulk;

class BulkTest extends \PHPUnit_Framework_TestCase
{
    /** @var Bulk */
    private $bulk;

    /** @var \PHPUnit_Framework_MockObject_MockObject */
    private $client;

    public function setUp()
    {
        $this->client = $this->getMock('Elasticsearch\Client');

        /** @noinspection PhpParamsInspection */
        $this->bulk = new Bulk($this->client, 'index', 'type', 5);
    }

    public function testItShouldAllowItemsToBeAddedToTheBulkOperation()
    {
        $this->bulk->addItem('idFoo', 'foo');
        $this->bulk->addItem('idBar', 'bar', 'update');
        $this->bulk->addItem('idQux', 'qux', 'index', 'indexQux');
        $this->bulk->addItem('idQuux', 'quux', 'update', 'indexQuux', 'typeQuux');

        $this->assertAttributeEquals(
            [
                ['index' => ['_id' => 'idFoo']],
                'foo',
                ['update' => ['_id' => 'idBar']],
                'bar',
                ['index' => ['_id' => 'idQux', '_index' => 'indexQux']],
                'qux',
                ['update' => ['_id' => 'idQuux', '_index' => 'indexQuux', '_type' => 'typeQuux']],
                'quux'
            ],
            'itemList',
            $this->bulk
        );

        $this->assertEquals(4, $this->bulk->getItemCount());
    }

    public function testItShouldFlushAutomaticallyWhenTooManyItemsHaveBeenAdded()
    {
        $this->client->expects($this->once())->method('bulk');

        $this->bulk->addItem('idFoo', 'foo');
        $this->bulk->addItem('idBar', 'bar');
        $this->bulk->addItem('idBaz', 'baz');
        $this->bulk->addItem('idQux', 'qux');
        $this->bulk->addItem('idQuux', 'quux');

        $this->assertEquals(0, $this->bulk->getItemCount());
    }

    public function testItShouldFlushWhenBeginAndEndAreCalled()
    {
        $this->client->expects($this->exactly(2))->method('bulk');

        $this->bulk->addItem('idFoo', 'foo');
        $this->bulk->begin();

        $this->bulk->addItem('idFoo', 'foo');
        $this->bulk->end();
    }

{'fraction_non_alphanumeric': 0.19121447028423771, 'fraction_numerical': 0.0020671834625322996, 'mean_word_length': 2.481115107913669, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 102, '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': '7086497', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1239, 'n_words': 180}