Skip to content

Commit b65d1e5

Browse files
author
Martynas Kasparavicius
committed
Bump react/promise requirement to 3.0;
DataloaderInterface returns PromiseInterfaces instead of ExtendedPromiseInterfaces as the latter has been removed in react/promise 3.0; PHP 8.4+ compatability: resolve "implicitly nullable parameters are deprecated";
1 parent 4701a3d commit b65d1e5

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Port of Facebook's dataloader to PHP",
55
"keywords": ["batch loading", "dataloader", "graphql"],
66
"require": {
7-
"react/promise": "^2.7.1",
7+
"react/promise": "^3.0",
88
"react/event-loop": "^1.1.1",
99
"php": "^7.4.0|^8.0"
1010
},

src/DataLoader.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
namespace leinonen\DataLoader;
66

77
use React\EventLoop\LoopInterface;
8-
use function React\Promise\all;
9-
use React\Promise\ExtendedPromiseInterface;
108
use React\Promise\Promise;
9+
use React\Promise\PromiseInterface;
10+
11+
use function React\Promise\all;
1112
use function React\Promise\reject;
1213
use function React\Promise\resolve;
1314

@@ -39,7 +40,7 @@ public function __construct(
3940
callable $batchLoadFunction,
4041
LoopInterface $loop,
4142
CacheMapInterface $cacheMap,
42-
DataLoaderOptions $options = null
43+
?DataLoaderOptions $options = null
4344
) {
4445
$this->batchLoadFunction = $batchLoadFunction;
4546
$this->eventLoop = $loop;
@@ -50,7 +51,7 @@ public function __construct(
5051
/**
5152
* {@inheritdoc}
5253
*/
53-
public function load($key): ExtendedPromiseInterface
54+
public function load($key): PromiseInterface
5455
{
5556
if ($key === null) {
5657
throw new \InvalidArgumentException(self::class . '::load must be called with a value, but got null');
@@ -84,7 +85,7 @@ function (callable $resolve, callable $reject) use ($key) {
8485
/**
8586
* {@inheritdoc}
8687
*/
87-
public function loadMany(array $keys): ExtendedPromiseInterface
88+
public function loadMany(array $keys): PromiseInterface
8889
{
8990
return all(
9091
\array_map(

src/DataLoaderInterface.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@
44

55
namespace leinonen\DataLoader;
66

7-
use React\Promise\ExtendedPromiseInterface;
8-
use React\Promise\Promise;
7+
use React\Promise\PromiseInterface;
98

109
interface DataLoaderInterface
1110
{
1211
/**
1312
* Returns a Promise for the value represented by the given key.
1413
*
1514
* @param mixed $key
16-
* @return ExtendedPromiseInterface
15+
* @return PromiseInterface
1716
*
1817
* @throws \InvalidArgumentException
1918
*/
20-
public function load($key): ExtendedPromiseInterface;
19+
public function load($key): PromiseInterface;
2120

2221
/**
2322
* Loads multiple keys, promising an array of values.
@@ -30,11 +29,11 @@ public function load($key): ExtendedPromiseInterface;
3029
* });
3130
*
3231
* @param array $keys
33-
* @return ExtendedPromiseInterface
32+
* @return PromiseInterface
3433
*
3534
* @throws \InvalidArgumentException
3635
*/
37-
public function loadMany(array $keys): ExtendedPromiseInterface;
36+
public function loadMany(array $keys): PromiseInterface;
3837

3938
/**
4039
* Clears the value for the given key from the cache if it exists.

tests/Unit/DataLoaderAbuseTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use leinonen\DataLoader\DataLoader;
77
use leinonen\DataLoader\DataLoaderException;
88
use PHPUnit\Framework\TestCase;
9-
use React\EventLoop\Factory;
9+
use React\EventLoop\Loop;
1010
use React\EventLoop\LoopInterface;
1111
use React\Promise\Promise;
1212
use function React\Promise\resolve;
@@ -20,7 +20,7 @@ class DataLoaderAbuseTest extends TestCase
2020

2121
public function setUp(): void
2222
{
23-
$this->eventLoop = Factory::create();
23+
$this->eventLoop = Loop::get();
2424
}
2525

2626
/**
@@ -162,7 +162,7 @@ function ($keys) {
162162
public function batch_function_must_return_a_promise_of_an_array_not_null()
163163
{
164164
$badLoader = $this->createDataLoader(function ($keys) {
165-
return resolve();
165+
return resolve(null);
166166
});
167167

168168
$exception = null;
@@ -210,7 +210,7 @@ public function batch_function_must_promise_an_array_of_correct_length()
210210
* Creates a simple DataLoader.
211211
*
212212
* @param $batchLoadFunction
213-
* @param array $options
213+
* @param ?\leinonen\DataLoader\DataLoaderOptions $options
214214
* @return DataLoader
215215
*/
216216
private function createDataLoader($batchLoadFunction, $options = null)

tests/Unit/DataLoaderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,12 +777,12 @@ public function it_batches_loads_occurring_within_promises()
777777

778778
all([
779779
$identityLoader->load('A'),
780-
resolve()->then(function () use ($identityLoader) {
781-
resolve()->then(function () use ($identityLoader) {
780+
resolve(null)->then(function () use ($identityLoader) {
781+
resolve(null)->then(function () use ($identityLoader) {
782782
$identityLoader->load('B');
783-
resolve()->then(function () use ($identityLoader) {
783+
resolve(null)->then(function () use ($identityLoader) {
784784
$identityLoader->load('C');
785-
resolve()->then(function () use ($identityLoader) {
785+
resolve(null)->then(function () use ($identityLoader) {
786786
$identityLoader->load('D');
787787
});
788788
});

0 commit comments

Comments
 (0)