<?php

namespace Fobia\Database\SphinxConnection\Test\Eloquent;

use Fobia\Database\SphinxConnection\Test\ModelRt;
use Fobia\Database\SphinxConnection\Test\TestCase;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;

/**
 * Generated by PHPUnit_SkeletonGenerator on 2016-10-08 at 13:15:13.
 */
class BuilderTest extends TestCase
{
    public function setUp()
    {
        parent::setUp();
        parent::setUpDatabase();

        $this->db->table('rt')->replace([
            ['id' => 1],
            ['id' => 2],
            ['id' => 3],
            ['id' => 4],
            ['id' => 5],
        ]);
    }
    //
    //public function tearDown()
    //{
    //    $this->db->statement("TRUNCATE RTINDEX rt");
    //    parent::tearDown();
    //}


    /**
     * @covers \Fobia\Database\SphinxConnection\Eloquent\Builder::paginate
     */
    public function testPaginate()
    {
        $r = ModelRt::where('id', '>', 0)->paginate(2);
        /** @var LengthAwarePaginator $r */
        $this->assertCount(2, $r->items());
        $this->assertTrue($r->total() > 2);
    }

    /**
     * @covers \Fobia\Database\SphinxConnection\Eloquent\Builder::getCountForPagination
     */
    public function testGetCountForPagination()
    {
        $rt = ModelRt::where('id', '>', 0)->limit(1);
        $rt->get();

        $count = $rt->getCountForPagination();
        $this->assertTrue($count > 1);
    }
}
