Skip to content

Commit 81d8362

Browse files
authored
Merge pull request #157 from clue-labs/promise-v3
Forward compatibility with upcoming Promise v3
2 parents d3d5b08 + 98690d9 commit 81d8362

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
"php": ">=5.4.0",
88
"evenement/evenement": "^3.0 || ^2.1 || ^1.1",
99
"react/event-loop": "^1.2",
10-
"react/promise": "^2.7",
11-
"react/promise-stream": "^1.1",
12-
"react/promise-timer": "^1.8",
13-
"react/socket": "^1.9"
10+
"react/promise": "^3 || ^2.7",
11+
"react/promise-stream": "^1.4",
12+
"react/promise-timer": "^1.9",
13+
"react/socket": "^1.12"
1414
},
1515
"require-dev": {
16-
"clue/block-react": "^1.2",
16+
"clue/block-react": "^1.5",
1717
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
1818
},
1919
"autoload": {

src/Io/Connection.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function ping()
128128
$reject($reason);
129129
})
130130
->on('success', function () use ($resolve) {
131-
$resolve();
131+
$resolve(null);
132132
});
133133
});
134134
}
@@ -144,7 +144,7 @@ public function quit()
144144
$this->state = self::STATE_CLOSED;
145145
$this->emit('end', [$this]);
146146
$this->emit('close', [$this]);
147-
$resolve();
147+
$resolve(null);
148148
});
149149
$this->state = self::STATE_CLOSEING;
150150
});

src/Io/LazyConnection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function quit()
181181
// not already connecting => no need to connect, simply close virtual connection
182182
if ($this->connecting === null) {
183183
$this->close();
184-
return \React\Promise\resolve();
184+
return \React\Promise\resolve(null);
185185
}
186186

187187
return $this->connecting()->then(function (ConnectionInterface $connection) {

tests/Io/LazyConnectionTest.php

+19-19
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testPingWillNotCloseConnectionWhenPendingConnectionFails()
3131
public function testPingWillNotCloseConnectionWhenUnderlyingConnectionCloses()
3232
{
3333
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping'])->disableOriginalConstructor()->getMock();
34-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
34+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
3535

3636
$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
3737
$factory->expects($this->once())->method('createConnection')->willReturn(\React\Promise\resolve($base));
@@ -48,7 +48,7 @@ public function testPingWillNotCloseConnectionWhenUnderlyingConnectionCloses()
4848
public function testPingWillCancelTimerWithoutClosingConnectionWhenUnderlyingConnectionCloses()
4949
{
5050
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping'])->disableOriginalConstructor()->getMock();
51-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
51+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
5252

5353
$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
5454
$factory->expects($this->once())->method('createConnection')->willReturn(\React\Promise\resolve($base));
@@ -69,7 +69,7 @@ public function testPingWillCancelTimerWithoutClosingConnectionWhenUnderlyingCon
6969
public function testPingWillNotForwardErrorFromUnderlyingConnection()
7070
{
7171
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping'])->disableOriginalConstructor()->getMock();
72-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
72+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
7373

7474
$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
7575
$factory->expects($this->once())->method('createConnection')->willReturn(\React\Promise\resolve($base));
@@ -87,8 +87,8 @@ public function testPingWillNotForwardErrorFromUnderlyingConnection()
8787
public function testPingFollowedByIdleTimerWillQuitUnderlyingConnection()
8888
{
8989
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping', 'quit', 'close'])->disableOriginalConstructor()->getMock();
90-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
91-
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve());
90+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
91+
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve(null));
9292
$base->expects($this->never())->method('close');
9393

9494
$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
@@ -115,8 +115,8 @@ public function testPingFollowedByIdleTimerWillQuitUnderlyingConnection()
115115
public function testPingFollowedByIdleTimerWillCloseUnderlyingConnectionWhenQuitFails()
116116
{
117117
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping', 'quit', 'close'])->disableOriginalConstructor()->getMock();
118-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
119-
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\reject());
118+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
119+
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\reject(new \RuntimeException()));
120120
$base->expects($this->once())->method('close');
121121

122122
$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
@@ -143,7 +143,7 @@ public function testPingFollowedByIdleTimerWillCloseUnderlyingConnectionWhenQuit
143143
public function testPingAfterIdleTimerWillCloseUnderlyingConnectionBeforeCreatingSecondConnection()
144144
{
145145
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping', 'quit', 'close'])->disableOriginalConstructor()->getMock();
146-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
146+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
147147
$base->expects($this->once())->method('quit')->willReturn(new Promise(function () { }));
148148
$base->expects($this->once())->method('close');
149149

@@ -289,7 +289,7 @@ public function testQueryBeforePingWillResolveWithoutStartingTimerWhenQueryFromU
289289
public function testQueryAfterPingWillCancelTimerAgainWhenPingFromUnderlyingConnectionResolved()
290290
{
291291
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
292-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
292+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
293293
$base->expects($this->once())->method('query')->with('SELECT 1')->willReturn(new Promise(function () { }));
294294

295295
$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
@@ -480,7 +480,7 @@ public function testPingWillTryToCreateNewUnderlyingConnectionAfterPreviousPingF
480480
public function testPingWillResolveAndStartTimerWhenPingFromUnderlyingConnectionResolves()
481481
{
482482
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
483-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
483+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
484484

485485
$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
486486
$factory->expects($this->once())->method('createConnection')->willReturn(\React\Promise\resolve($base));
@@ -570,7 +570,7 @@ public function testQuitAfterPingReturnsPendingPromiseWhenConnectionIsPending()
570570
public function testQuitAfterPingWillQuitUnderlyingConnectionWhenResolved()
571571
{
572572
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
573-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
573+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
574574
$base->expects($this->once())->method('quit')->willReturn(new Promise(function () { }));
575575

576576
$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
@@ -585,8 +585,8 @@ public function testQuitAfterPingWillQuitUnderlyingConnectionWhenResolved()
585585
public function testQuitAfterPingResolvesAndEmitsCloseWhenUnderlyingConnectionQuits()
586586
{
587587
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
588-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
589-
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve());
588+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
589+
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve(null));
590590

591591
$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
592592
$factory->expects($this->once())->method('createConnection')->willReturn(\React\Promise\resolve($base));
@@ -606,7 +606,7 @@ public function testQuitAfterPingRejectsAndEmitsCloseWhenUnderlyingConnectionFai
606606
{
607607
$error = new \RuntimeException();
608608
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
609-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
609+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
610610
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\reject($error));
611611

612612
$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
@@ -651,7 +651,7 @@ public function testCloseAfterPingCancelsPendingConnection()
651651
public function testCloseTwiceAfterPingWillCloseUnderlyingConnectionWhenResolved()
652652
{
653653
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
654-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
654+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
655655
$base->expects($this->once())->method('close');
656656

657657
$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
@@ -685,7 +685,7 @@ public function testCloseAfterPingDoesNotEmitConnectionErrorFromAbortedConnectio
685685
public function testCloseAfterPingWillCancelTimerWhenPingFromUnderlyingConnectionResolves()
686686
{
687687
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
688-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
688+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
689689

690690
$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
691691
$factory->expects($this->once())->method('createConnection')->willReturn(\React\Promise\resolve($base));
@@ -704,7 +704,7 @@ public function testCloseAfterPingWillCancelTimerWhenPingFromUnderlyingConnectio
704704
public function testCloseAfterPingHasResolvedWillCloseUnderlyingConnectionWithoutTryingToCancelConnection()
705705
{
706706
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping', 'close'])->disableOriginalConstructor()->getMock();
707-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
707+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
708708
$base->expects($this->once())->method('close')->willReturnCallback(function () use ($base) {
709709
$base->emit('close');
710710
});
@@ -723,7 +723,7 @@ public function testCloseAfterPingHasResolvedWillCloseUnderlyingConnectionWithou
723723
public function testCloseAfterQuitAfterPingWillCloseUnderlyingConnectionWhenQuitIsStillPending()
724724
{
725725
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
726-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
726+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
727727
$base->expects($this->once())->method('quit')->willReturn(new Promise(function () { }));
728728
$base->expects($this->once())->method('close');
729729

@@ -740,7 +740,7 @@ public function testCloseAfterQuitAfterPingWillCloseUnderlyingConnectionWhenQuit
740740
public function testCloseAfterPingAfterIdleTimeoutWillCloseUnderlyingConnectionWhenQuitIsStillPending()
741741
{
742742
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
743-
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
743+
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
744744
$base->expects($this->once())->method('quit')->willReturn(new Promise(function () { }));
745745
$base->expects($this->once())->method('close');
746746

tests/ResultQueryTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ public function testSimpleSelectFromLazyConnectionWithoutDatabaseNameReturnsSame
415415

416416
$connection->query('select * from test.book')->then(function (QueryResult $command) {
417417
$this->assertCount(2, $command->resultRows);
418-
})->done();
418+
});
419419

420420
$connection->quit();
421421
Loop::run();

0 commit comments

Comments
 (0)