Skip to content

Commit a9db08b

Browse files
committed
Fix deprecated errors in tests
1 parent 8b9d39b commit a9db08b

File tree

8 files changed

+163
-17
lines changed

8 files changed

+163
-17
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
fail-fast: true
1010
matrix:
1111
os: [ubuntu-20.04]
12-
php: [7.4, 8.0, 8.1]
12+
php: [7.4, 8.0, 8.1, 8.2, 8.3, 8.4]
1313

1414
name: League - PHP ${{ matrix.php }} on ${{ matrix.os }}
1515

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
composer.lock
22
build
33
vendor
4-
.phpunit.result.cache
4+
.phpunit.result.cache
5+
.idea

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@
2626
"require-dev": {
2727
"doctrine/orm": "^2.5",
2828
"illuminate/contracts": "~5.0",
29+
"laminas/laminas-paginator": "~2.12",
2930
"mockery/mockery": "^1.3",
30-
"pagerfanta/pagerfanta": "~1.0.0",
31+
"pagerfanta/pagerfanta": "~1.0.0|~4.0.0",
3132
"phpstan/phpstan": "^1.4",
3233
"phpunit/phpunit": "^9.5",
3334
"squizlabs/php_codesniffer": "~3.4",
34-
"vimeo/psalm": "^4.22",
35-
"zendframework/zend-paginator": "~2.3"
35+
"vimeo/psalm": "^4.22"
3636
},
3737
"suggest": {
3838
"illuminate/pagination": "The Illuminate Pagination component.",
3939
"pagerfanta/pagerfanta": "Pagerfanta Paginator",
40-
"zendframework/zend-paginator": "Zend Framework Paginator"
40+
"laminas/laminas-paginator": "Laminas Framework Paginator"
4141
},
4242
"autoload": {
4343
"psr-4": {

src/Manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Manager
6161
*/
6262
private ScopeFactoryInterface $scopeFactory;
6363

64-
public function __construct(ScopeFactoryInterface $scopeFactory = null)
64+
public function __construct(?ScopeFactoryInterface $scopeFactory = null)
6565
{
6666
$this->scopeFactory = $scopeFactory ?: new ScopeFactory();
6767
}
@@ -72,7 +72,7 @@ public function __construct(ScopeFactoryInterface $scopeFactory = null)
7272
public function createData(
7373
ResourceInterface $resource,
7474
?string $scopeIdentifier = null,
75-
Scope $parentScopeInstance = null
75+
?Scope $parentScopeInstance = null
7676
): Scope {
7777
if ($parentScopeInstance !== null) {
7878
return $this->scopeFactory->createChildScopeFor($this, $parentScopeInstance, $resource, $scopeIdentifier);
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the League\Fractal package.
5+
*
6+
* (c) Phil Sturgeon <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace League\Fractal\Pagination;
13+
14+
use Laminas\Paginator\Paginator;
15+
16+
/**
17+
* A paginator adapter for laminas/laminas-paginator.
18+
*
19+
* @author Abdul Malik Ikhsan <[email protected]>
20+
*/
21+
class LaminasPaginatorAdapter implements PaginatorInterface
22+
{
23+
protected Paginator $paginator;
24+
25+
/**
26+
* The route generator.
27+
*
28+
* @var callable
29+
*/
30+
protected $routeGenerator;
31+
32+
public function __construct(Paginator $paginator, callable $routeGenerator)
33+
{
34+
$this->paginator = $paginator;
35+
$this->routeGenerator = $routeGenerator;
36+
}
37+
38+
/**
39+
* {@inheritDoc}
40+
*/
41+
public function getCurrentPage(): int
42+
{
43+
return $this->paginator->getCurrentPageNumber();
44+
}
45+
46+
/**
47+
* {@inheritDoc}
48+
*/
49+
public function getLastPage(): int
50+
{
51+
return $this->paginator->count();
52+
}
53+
54+
/**
55+
* {@inheritDoc}
56+
*/
57+
public function getTotal(): int
58+
{
59+
return $this->paginator->getTotalItemCount();
60+
}
61+
62+
/**
63+
* {@inheritDoc}
64+
*/
65+
public function getCount(): int
66+
{
67+
return $this->paginator->getCurrentItemCount();
68+
}
69+
70+
/**
71+
* {@inheritDoc}
72+
*/
73+
public function getPerPage(): int
74+
{
75+
return $this->paginator->getItemCountPerPage();
76+
}
77+
78+
/**
79+
* {@inheritDoc}
80+
*/
81+
public function getUrl(int $page): string
82+
{
83+
return call_user_func($this->routeGenerator, $page);
84+
}
85+
86+
public function getPaginator(): Paginator
87+
{
88+
return $this->paginator;
89+
}
90+
91+
public function getRouteGenerator(): callable
92+
{
93+
return $this->routeGenerator;
94+
}
95+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
namespace League\Fractal\Test\Pagination;
3+
4+
use League\Fractal\Pagination\LaminasPaginatorAdapter;
5+
use Mockery;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class LaminasFrameworkPaginatorAdapterTest extends TestCase
9+
{
10+
public function testPaginationAdapter()
11+
{
12+
$items = [
13+
'Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7', 'Item 8', 'Item 9', 'Item 10',
14+
'Item 11', 'Item 12', 'Item 13', 'Item 14', 'Item 15', 'Item 16', 'Item 17', 'Item 18', 'Item 19', 'Item 20',
15+
'Item 21', 'Item 22', 'Item 23', 'Item 24', 'Item 25', 'Item 26', 'Item 27', 'Item 28', 'Item 29', 'Item 30',
16+
'Item 31', 'Item 32', 'Item 33', 'Item 34', 'Item 35', 'Item 36', 'Item 37', 'Item 38', 'Item 39', 'Item 40',
17+
'Item 41', 'Item 42', 'Item 43', 'Item 44', 'Item 45', 'Item 46', 'Item 47', 'Item 48', 'Item 49', 'Item 50',
18+
];
19+
20+
$adapter = Mockery::mock('Laminas\Paginator\Adapter\ArrayAdapter', [$items])->makePartial();
21+
22+
$total = 50;
23+
$count = 10;
24+
$perPage = 10;
25+
$currentPage = 2;
26+
$lastPage = 5;
27+
28+
$paginator = Mockery::mock('Laminas\Paginator\Paginator', [$adapter])->makePartial();
29+
30+
$paginator->shouldReceive('getCurrentPageNumber')->andReturn($currentPage);
31+
$paginator->shouldReceive('count')->andReturn($lastPage);
32+
$paginator->shouldReceive('getItemCountPerPage')->andReturn($perPage);
33+
34+
$adapter = new LaminasPaginatorAdapter($paginator, function ($page) {
35+
return 'http://example.com/foo?page='.$page;
36+
});
37+
38+
$this->assertInstanceOf('League\Fractal\Pagination\PaginatorInterface', $adapter);
39+
40+
$this->assertSame($currentPage, $adapter->getCurrentPage());
41+
$this->assertSame($lastPage, $adapter->getLastPage());
42+
$this->assertSame($count, $adapter->getCount());
43+
$this->assertSame($total, $adapter->getTotal());
44+
$this->assertSame($perPage, $adapter->getPerPage());
45+
$this->assertSame('http://example.com/foo?page=1', $adapter->getUrl(1));
46+
$this->assertSame('http://example.com/foo?page=3', $adapter->getUrl(3));
47+
}
48+
49+
public function tearDown(): void
50+
{
51+
Mockery::close();
52+
}
53+
}

test/Pagination/ZendFrameworkPaginatorAdapterTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
class ZendFrameworkPaginatorAdapterTest extends TestCase
99
{
10+
public static function setUpBeforeClass(): void
11+
{
12+
class_alias(\Laminas\Paginator\Adapter\ArrayAdapter::class, \Zend\Paginator\Adapter\ArrayAdapter::class);
13+
class_alias(\Laminas\Paginator\Paginator::class, \Zend\Paginator\Paginator::class);
14+
}
15+
1016
public function testPaginationAdapter()
1117
{
1218
$items = [

test/Serializer/DataArraySerializerTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,6 @@ public function testSerializingNullResource()
357357
$this->assertSame($expected, $scope->toArray());
358358
}
359359

360-
public function testCanPassNullValueToSerializer()
361-
{
362-
$testClass = new \stdClass();
363-
$testClass->name = 'test';
364-
$testClass->email = '[email protected]';
365-
366-
367-
}
368-
369360
public function tearDown(): void
370361
{
371362
Mockery::close();

0 commit comments

Comments
 (0)