Skip to content

Commit

Permalink
Fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Nayjest committed Jun 23, 2016
1 parent 1ae71a2 commit 7ee79f2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Processor/PaginateProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

namespace ViewComponents\Eloquent\Processor;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use ViewComponents\ViewComponents\Data\Operation\OperationInterface;
use ViewComponents\ViewComponents\Data\Operation\PaginateOperation;
use ViewComponents\ViewComponents\Data\Processor\AbstractPaginateProcessor;

class PaginateProcessor extends AbstractPaginateProcessor
{
/**
* @param Builder $src
* @param Builder|EloquentBuilder $src
* @param OperationInterface|PaginateOperation $operation
* @return mixed
*/
public function process($src, OperationInterface $operation)
{

$src->getQuery()
->limit($operation->getPageSize())
$src->limit($operation->getPageSize())
->offset($this->getOffset($operation));
return $src;
}
Expand Down
32 changes: 32 additions & 0 deletions tests/phpunit/Processor/PaginateProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace ViewComponents\Eloquent\Test\Processor;

use ViewComponents\Eloquent\EloquentDataProvider;
use ViewComponents\Eloquent\Test\Mock\TestUser;
use ViewComponents\ViewComponents\Data\Operation\PaginateOperation;
use Illuminate\Database\Capsule\Manager as DB;

class PaginateProcessorTest extends \PHPUnit_Framework_TestCase
{
public function test()
{
$recordsQty = TestUser::all()->count();
if ($recordsQty <= 5) {
throw new \Exception("Can't test PaginateProcessor: not enough fixture data");
}
$provider = new EloquentDataProvider(TestUser::class);
$provider->operations()->add(new PaginateOperation(1,3));
$data = iterator_to_array($provider);
$id1 = array_first($data)->id;
self::assertEquals(3, count($data));

$provider = new EloquentDataProvider(DB::table((new TestUser)->getTable()));
$provider->operations()->add(new PaginateOperation(2,2));
$data = iterator_to_array($provider);
self::assertEquals(2, count($data));

$id2 = array_first($data)->id;
self::assertTrue($id2 > 0 && $id2 > 0 && $id1 !== $id2);
}
}

0 comments on commit 7ee79f2

Please sign in to comment.