Skip to content

Commit a7eb570

Browse files
Merge pull request #26 from PlumTreeSystems/master
Bump react/promise requirement to 3.0 for PHP 8.4 compatibility
2 parents 4701a3d + a95eedd commit a7eb570

File tree

5 files changed

+25
-23
lines changed

5 files changed

+25
-23
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: 7 additions & 6 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(
@@ -272,7 +273,7 @@ private function validateBatchPromiseOutput($values, $keys): void
272273
/**
273274
* Validates the batch promise returned from the batch load function.
274275
*
275-
* @param $batchPromise
276+
* @param $batchPromise
276277
*
277278
* @throws DataLoaderException
278279
*/

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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
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;
12+
1213
use function React\Promise\resolve;
1314

1415
class DataLoaderAbuseTest extends TestCase
@@ -20,7 +21,7 @@ class DataLoaderAbuseTest extends TestCase
2021

2122
public function setUp(): void
2223
{
23-
$this->eventLoop = Factory::create();
24+
$this->eventLoop = Loop::get();
2425
}
2526

2627
/**
@@ -162,7 +163,7 @@ function ($keys) {
162163
public function batch_function_must_return_a_promise_of_an_array_not_null()
163164
{
164165
$badLoader = $this->createDataLoader(function ($keys) {
165-
return resolve();
166+
return resolve(null);
166167
});
167168

168169
$exception = null;
@@ -209,8 +210,8 @@ public function batch_function_must_promise_an_array_of_correct_length()
209210
/**
210211
* Creates a simple DataLoader.
211212
*
212-
* @param $batchLoadFunction
213-
* @param array $options
213+
* @param $batchLoadFunction
214+
* @param ?\leinonen\DataLoader\DataLoaderOptions $options
214215
* @return DataLoader
215216
*/
216217
private function createDataLoader($batchLoadFunction, $options = null)

tests/Unit/DataLoaderTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
use PHPUnit\Framework\TestCase;
99
use React\EventLoop\Factory;
1010
use React\EventLoop\LoopInterface;
11-
use function React\Promise\all;
1211
use React\Promise\Promise;
12+
13+
use function React\Promise\all;
1314
use function React\Promise\resolve;
1415

1516
class DataLoaderTest extends TestCase
@@ -777,12 +778,12 @@ public function it_batches_loads_occurring_within_promises()
777778

778779
all([
779780
$identityLoader->load('A'),
780-
resolve()->then(function () use ($identityLoader) {
781-
resolve()->then(function () use ($identityLoader) {
781+
resolve(null)->then(function () use ($identityLoader) {
782+
resolve(null)->then(function () use ($identityLoader) {
782783
$identityLoader->load('B');
783-
resolve()->then(function () use ($identityLoader) {
784+
resolve(null)->then(function () use ($identityLoader) {
784785
$identityLoader->load('C');
785-
resolve()->then(function () use ($identityLoader) {
786+
resolve(null)->then(function () use ($identityLoader) {
786787
$identityLoader->load('D');
787788
});
788789
});

0 commit comments

Comments
 (0)