Skip to content

Commit 1c9a952

Browse files
authored
[Refactor] PHP 8.1 support (#1)
* PHP 8.1 support * Update Eloquent dependency
1 parent ee03927 commit 1c9a952

File tree

6 files changed

+31
-19
lines changed

6 files changed

+31
-19
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ name: Tests
22

33
on:
44
push:
5-
branches: [ main, develop ]
5+
branches: [ main, develop, 2.x ]
66
pull_request:
7-
branches: [ main, develop ]
7+
branches: [ main, develop, 2.x ]
88

99
jobs:
1010
build:
1111

1212
runs-on: ubuntu-latest
13-
13+
1414
strategy:
1515
fail-fast: true
1616
matrix:
17-
php: ['7.4', '8.0']
17+
php: ['7.4', '8.0', '8.1']
1818
laravel: ['^8.0']
1919

2020
steps:
@@ -28,6 +28,7 @@ jobs:
2828
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd
2929
tools: composer:v2
3030
coverage: none
31+
ini-values: error_reporting=E_ALL
3132

3233
- name: Set Laravel Version
3334
run: composer require "laravel/framework:${{ matrix.laravel }}" --no-update -n
@@ -38,6 +39,6 @@ jobs:
3839
timeout_minutes: 5
3940
max_attempts: 5
4041
command: composer install --no-suggest --prefer-dist -n -o
41-
42+
4243
- name: Execute tests
4344
run: vendor/bin/phpunit

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
"illuminate/database": "^8.0",
2929
"illuminate/pagination": "^8.0",
3030
"illuminate/support": "^8.0",
31-
"laravel-json-api/eloquent": "^1.0.0"
31+
"laravel-json-api/eloquent": "^2.0"
3232
},
3333
"require-dev": {
34-
"orchestra/testbench": "^6.9",
35-
"phpunit/phpunit": "^9.5"
34+
"orchestra/testbench": "^6.23",
35+
"phpunit/phpunit": "^9.5.10"
3636
},
3737
"autoload": {
3838
"psr-4": {
@@ -48,10 +48,11 @@
4848
},
4949
"extra": {
5050
"branch-alias": {
51-
"dev-develop": "1.x-dev"
51+
"dev-develop": "1.x-dev",
52+
"dev-2.x": "2.x-dev"
5253
}
5354
},
54-
"minimum-stability": "stable",
55+
"minimum-stability": "dev",
5556
"prefer-stable": true,
5657
"config": {
5758
"sort-packages": true

phpunit.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
convertErrorsToExceptions="true"
99
convertNoticesToExceptions="true"
1010
convertWarningsToExceptions="true"
11+
convertDeprecationsToExceptions="true"
1112
processIsolation="false"
1213
stopOnError="false"
1314
stopOnFailure="false"
@@ -31,6 +32,7 @@
3132
</testsuite>
3233
</testsuites>
3334
<php>
35+
<ini name="error_reporting" value="E_ALL"/>
3436
<env name="DB_CONNECTION" value="testing"/>
3537
</php>
3638
</phpunit>

src/Cursor/CursorPaginator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Illuminate\Pagination\Paginator;
2525
use IteratorAggregate;
2626
use LogicException;
27+
use Traversable;
2728

2829
class CursorPaginator implements IteratorAggregate, Countable
2930
{
@@ -154,15 +155,15 @@ public function getTo(): ?string
154155
/**
155156
* @inheritDoc
156157
*/
157-
public function getIterator()
158+
public function getIterator(): Traversable
158159
{
159160
yield from $this->items;
160161
}
161162

162163
/**
163164
* @inheritDoc
164165
*/
165-
public function count()
166+
public function count(): int
166167
{
167168
return $this->items->count();
168169
}

src/CursorPage.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use LaravelJsonApi\Core\Document\Link;
2424
use LaravelJsonApi\Core\Pagination\AbstractPage;
2525
use LaravelJsonApi\CursorPagination\Cursor\CursorPaginator;
26+
use Traversable;
2627

2728
class CursorPage extends AbstractPage
2829
{
@@ -179,15 +180,15 @@ public function url(array $page): string
179180
/**
180181
* @inheritDoc
181182
*/
182-
public function getIterator()
183+
public function getIterator(): Traversable
183184
{
184185
yield from $this->paginator;
185186
}
186187

187188
/**
188189
* @inheritDoc
189190
*/
190-
public function count()
191+
public function count(): int
191192
{
192193
return $this->paginator->count();
193194
}

tests/lib/Acceptance/TestCase.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,34 @@
1919

2020
namespace LaravelJsonApi\CursorPagination\Tests\Acceptance;
2121

22+
use Illuminate\Foundation\Testing\Concerns\InteractsWithDeprecationHandling;
2223
use LaravelJsonApi\Contracts\Schema\Container as SchemaContainerContract;
2324
use LaravelJsonApi\Contracts\Server\Server;
2425
use LaravelJsonApi\Core\Schema\Container as SchemaContainer;
26+
use LaravelJsonApi\Core\Support\ContainerResolver;
2527
use Orchestra\Testbench\TestCase as BaseTestCase;
2628

2729
class TestCase extends BaseTestCase
2830
{
31+
use InteractsWithDeprecationHandling;
32+
2933
/**
3034
* @inheritDoc
3135
*/
3236
protected function setUp(): void
3337
{
3438
parent::setUp();
3539

40+
$this->withoutDeprecationHandling();
41+
3642
$this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');
3743

38-
$this->app->singleton(
39-
SchemaContainerContract::class,
40-
fn($container) => new SchemaContainer($container, $container->make(Server::class), [
44+
$this->app->singleton(SchemaContainerContract::class, static function ($container) {
45+
$resolver = new ContainerResolver(static fn () => $container);
46+
return new SchemaContainer($resolver, $container->make(Server::class), [
4147
\App\VideoSchema::class,
42-
])
43-
);
48+
]);
49+
});
4450

4551
$this->app->singleton(Server::class, function () {
4652
$server = $this->createMock(Server::class);

0 commit comments

Comments
 (0)