Skip to content

Commit

Permalink
Merge 943e5f5 into 4ba74ff
Browse files Browse the repository at this point in the history
  • Loading branch information
KorvinSzanto committed Aug 22, 2020
2 parents 4ba74ff + 943e5f5 commit 0bb8ebc
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 66 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- v1-dependencies-

- run: composer install -n --prefer-dist
- run: composer require --dev phpstan/phpstan

- save_cache:
key: v1-dependencies-{{ checksum "composer.json" }}
Expand Down
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ sudo: false

matrix:
include:
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.2
env: COLLECT_COVERAGE=true
- php: 7.3
- php: hhvm
dist: trusty
- php: 7.4
- php: nightly

allow_failures:
- php: hhvm
- php: nightly

install:
- travis_retry composer install --no-interaction --prefer-source
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ $ composer require league/fractal-paginator-doctrine

The following versions of PHP are supported by this version.

* PHP 5.6
* PHP 7.0
* PHP 7.1
* PHP 7.2
* PHP 7.3
* PHP 7.4
* HHVM

## Documentation

Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
"homepage": "http://fractal.thephpleague.com/",
"license": "MIT",
"require": {
"php": ">=7.2"
"php": ">=5.6"
},
"require-dev": {
"mockery/mockery": "~1.0",
"phpstan/phpstan": "^0.11.8",
"phpunit/phpunit": "~8.0",
"phpunit/phpunit": "~9.0|~8.0|~5.5",
"squizlabs/php_codesniffer": "~3.4",
"league/fractal": "~1.0|1.0.x-dev",
"league/fractal": "~1.0|1.0.x-dev|>0.20",
"doctrine/orm": "^2.5"
},
"suggest": {
Expand All @@ -38,10 +37,10 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "0.20.x-dev"
}
},
"conflict": {
"league/fractal": "<1.0"
"league/fractal": "<1.0 <0.20"
}
}
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
</filter>
<logging>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
Expand Down
15 changes: 12 additions & 3 deletions src/DoctrinePaginatorAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace League\Fractal\Pagination;

use Doctrine\ORM\Tools\Pagination\Paginator;
use Exception;
use RuntimeException;

/**
* A paginator adapter for doctrine pagination.
Expand All @@ -22,7 +24,7 @@ class DoctrinePaginatorAdapter implements PaginatorInterface
{
/**
* The paginator instance.
* @var Paginator
* @var Paginator<mixed>
*/
private $paginator;

Expand All @@ -35,7 +37,7 @@ class DoctrinePaginatorAdapter implements PaginatorInterface

/**
* Create a new DoctrinePaginatorAdapter.
* @param Paginator $paginator
* @param Paginator<mixed> $paginator
* @param callable $routeGenerator
*
*/
Expand Down Expand Up @@ -79,10 +81,17 @@ public function getTotal()
* Get the count.
*
* @return int
*
* @throws Exception If the iterator cannot be resolved
* @throws RuntimeException If the returned iterator can't be counted
*/
public function getCount()
{
return $this->paginator->getIterator()->count();
$iterator = $this->paginator->getIterator();
if (!is_callable([$iterator, 'count'])) {
throw new RuntimeException('Invalid iterator returned by paginator. Must have a callable "count" method.');
}
return $iterator->count();
}

/**
Expand Down
22 changes: 14 additions & 8 deletions test/Pagination/DoctrinePaginatorAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,39 @@

use League\Fractal\Pagination\DoctrinePaginatorAdapter;
use League\Fractal\Test\TestCase;
use Mockery;
use Mockery as M;

class DoctrinePaginatorAdapterTest extends TestCase
class DoctrinePaginatorAdapterTest extends \PHPUnit\Framework\TestCase
{
use M\Adapter\Phpunit\MockeryPHPUnitIntegration;

public function testPaginationAdapter()
{
$total = 50;
$count = 5;
$perPage = 5;
$currentPage = 2;
$lastPage = 10;
//Mock the doctrine paginator
$paginator = Mockery::mock('Doctrine\ORM\Tools\Pagination\Paginator')->makePartial();

// Mock the doctrine paginator
$paginator = M::mock('Doctrine\ORM\Tools\Pagination\Paginator')->makePartial();
$paginator->shouldReceive('count')->andReturn($total);
//Mock the query that the paginator is acting on
$query = Mockery::mock('Doctrine\ORM\AbstractQuery');

// Mock the query that the paginator is acting on
$query = M::mock('Doctrine\ORM\AbstractQuery');
$query->shouldReceive('getFirstResult')->andReturn(($currentPage - 1) * $perPage);
$query->shouldReceive('getMaxResults')->andReturn($perPage);
$paginator->shouldReceive('getQuery')->andReturn($query);
//Mock the iterator of the paginator
$iterator = Mockery::mock('IteratorAggregate');

// Mock the iterator of the paginator
$iterator = M::mock('IteratorAggregate');
$iterator->shouldReceive('count')->andReturn($count);
$paginator->shouldReceive('getIterator')->andReturn($iterator);
$adapter = new DoctrinePaginatorAdapter($paginator, function ($page) {

return 'http://example.com/foo?page=' . $page;
});

$this->assertInstanceOf('League\Fractal\Pagination\PaginatorInterface', $adapter);
$this->assertSame($currentPage, $adapter->getCurrentPage());
$this->assertSame($lastPage, $adapter->getLastPage());
Expand Down
44 changes: 0 additions & 44 deletions test/TestCase.php

This file was deleted.

0 comments on commit 0bb8ebc

Please sign in to comment.