Skip to content

Commit d2a0860

Browse files
committed
Update to reactphp/http v1.0.0
1 parent a23a930 commit d2a0860

4 files changed

Lines changed: 45 additions & 44 deletions

File tree

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ from any Server-Sent Events (SSE) server endpoint:
2121

2222
```php
2323
$loop = Factory::create();
24-
$es = new EventSource('https://example.com/stream.php', $loop);
24+
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
2525

26-
$es->on('message', function (MessageEvent $message) {
26+
$es->on('message', function (Clue\React\EventSource\MessageEvent $message) {
2727
//$data = json_decode($message->data);
2828
var_dump($message);
2929
});
@@ -48,19 +48,19 @@ registers everything with the main [`EventLoop`](https://github.com/reactphp/eve
4848
in order to handle async HTTP requests.
4949

5050
```php
51-
$loop = \React\EventLoop\Factory::create();
51+
$loop = React\EventLoop\Factory::create();
5252

53-
$es = new \Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
53+
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
5454
```
5555

5656
If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
5757
proxy servers etc.), you can explicitly pass a custom instance of the
5858
[`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface)
59-
to the [`Browser`](https://github.com/clue/reactphp-buzz#browser) instance
59+
to the [`Browser`](https://github.com/reactphp/http#browser) instance
6060
and pass it as an additional argument to the `EventSource` like this:
6161

6262
```php
63-
$connector = new \React\Socket\Connector($loop, array(
63+
$connector = new React\Socket\Connector($loop, array(
6464
'dns' => '127.0.0.1',
6565
'tcp' => array(
6666
'bindto' => '192.168.10.1:0'
@@ -70,9 +70,9 @@ $connector = new \React\Socket\Connector($loop, array(
7070
'verify_peer_name' => false
7171
)
7272
));
73-
$browser = new \Clue\React\Buzz\Browser($loop, $connector);
73+
$browser = new React\Http\Browser($loop, $connector);
7474

75-
$es = new \Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop, $browser);
75+
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop, $browser);
7676
```
7777

7878
## Install

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
},
1919
"require": {
2020
"php": ">=5.4",
21-
"clue/buzz-react": "^2.9",
22-
"evenement/evenement": "^3.0 || ^2.0"
21+
"evenement/evenement": "^3.0 || ^2.0",
22+
"react/event-loop": "^1.0",
23+
"react/http": "^1.0"
2324
},
2425
"require-dev": {
2526
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35"

src/EventSource.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Clue\React\EventSource;
44

5-
use Clue\React\Buzz\Browser;
65
use Evenement\EventEmitter;
76
use Psr\Http\Message\ResponseInterface;
87
use React\EventLoop\LoopInterface;
8+
use React\Http\Browser;
99
use React\Stream\ReadableStreamInterface;
1010

1111
/**
@@ -20,19 +20,19 @@
2020
* in order to handle async HTTP requests.
2121
*
2222
* ```php
23-
* $loop = \React\EventLoop\Factory::create();
23+
* $loop = React\EventLoop\Factory::create();
2424
*
25-
* $es = new \Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
25+
* $es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
2626
* ```
2727
*
2828
* If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
2929
* proxy servers etc.), you can explicitly pass a custom instance of the
3030
* [`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface)
31-
* to the [`Browser`](https://github.com/clue/reactphp-buzz#browser) instance
31+
* to the [`Browser`](https://github.com/reactphp/http#browser) instance
3232
* and pass it as an additional argument to the `EventSource` like this:
3333
*
3434
* ```php
35-
* $connector = new \React\Socket\Connector($loop, array(
35+
* $connector = new React\Socket\Connector($loop, array(
3636
* 'dns' => '127.0.0.1',
3737
* 'tcp' => array(
3838
* 'bindto' => '192.168.10.1:0'
@@ -42,9 +42,9 @@
4242
* 'verify_peer_name' => false
4343
* )
4444
* ));
45-
* $browser = new \Clue\React\Buzz\Browser($loop, $connector);
45+
* $browser = new React\Http\Browser($loop, $connector);
4646
*
47-
* $es = new \Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop, $browser);
47+
* $es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop, $browser);
4848
* ```
4949
*/
5050
class EventSource extends EventEmitter

tests/EventSourceTest.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace Clue\Tests\React\EventSource;
44

5-
use PHPUnit\Framework\TestCase;
65
use Clue\React\EventSource\EventSource;
6+
use PHPUnit\Framework\TestCase;
77
use React\Promise\Promise;
88
use React\Promise\Deferred;
9-
use RingCentral\Psr7\Response;
9+
use React\Http\Browser;
10+
use React\Http\Io\ReadableBodyStream;
1011
use React\Stream\ThroughStream;
11-
use Clue\React\Buzz\Message\ReadableBodyStream;
12-
use Clue\React\Buzz\Browser;
12+
use RingCentral\Psr7\Response;
1313

1414
class EventSourceTest extends TestCase
1515
{
@@ -50,15 +50,15 @@ public function testConstructorCanBeCalledWithoutBrowser()
5050
$ref->setAccessible(true);
5151
$browser = $ref->getValue($es);
5252

53-
$this->assertInstanceOf('Clue\React\Buzz\Browser', $browser);
53+
$this->assertInstanceOf('React\Http\Browser', $browser);
5454
}
5555

5656
public function testConstructorWillSendGetRequestThroughGivenBrowser()
5757
{
5858
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
5959

6060
$pending = new Promise(function () { });
61-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
61+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
6262
$browser->expects($this->once())->method('withRejectErrorResponse')->with(false)->willReturnSelf();
6363
$browser->expects($this->once())->method('requestStreaming')->with('GET', 'http://example.com')->willReturn($pending);
6464

@@ -70,7 +70,7 @@ public function testConstructorWillSendGetRequestThroughGivenBrowserWithHttpsSch
7070
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
7171

7272
$pending = new Promise(function () { });
73-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
73+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
7474
$browser->expects($this->once())->method('withRejectErrorResponse')->with(false)->willReturnSelf();
7575
$browser->expects($this->once())->method('requestStreaming')->with('GET', 'https://example.com')->willReturn($pending);
7676

@@ -85,7 +85,7 @@ public function testCloseWillCancelPendingGetRequest()
8585
$pending = new Promise(function () { }, function () use (&$cancelled) {
8686
++$cancelled;
8787
});
88-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
88+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
8989
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
9090
$browser->expects($this->once())->method('requestStreaming')->willReturn($pending);
9191

@@ -102,7 +102,7 @@ public function testCloseWillNotEmitErrorEventWhenGetRequestCancellationHandlerR
102102
$pending = new Promise(function () { }, function () {
103103
throw new \RuntimeException();
104104
});
105-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
105+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
106106
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
107107
$browser->expects($this->once())->method('requestStreaming')->willReturn($pending);
108108

@@ -127,7 +127,7 @@ public function testConstructorWillStartGetRequestThatWillStartRetryTimerWhenGet
127127
);
128128

129129
$deferred = new Deferred();
130-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
130+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
131131
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
132132
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
133133

@@ -149,7 +149,7 @@ public function testConstructorWillStartGetRequestThatWillStartRetryTimerThatWil
149149
);
150150

151151
$deferred = new Deferred();
152-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
152+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
153153
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
154154
$browser->expects($this->exactly(2))->method('requestStreaming')->willReturnOnConsecutiveCalls(
155155
$deferred->promise(),
@@ -173,7 +173,7 @@ public function testConstructorWillStartGetRequestThatWillEmitErrorWhenGetReques
173173
);
174174

175175
$deferred = new Deferred();
176-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
176+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
177177
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
178178
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
179179

@@ -193,7 +193,7 @@ public function testConstructorWillStartGetRequestThatWillNotStartRetryTimerWhen
193193
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
194194

195195
$deferred = new Deferred();
196-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
196+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
197197
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
198198
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
199199

@@ -216,7 +216,7 @@ public function testCloseAfterGetRequestFromConstructorFailsWillCancelPendingRet
216216
$loop->expects($this->once())->method('cancelTimer')->with($timer);
217217

218218
$deferred = new Deferred();
219-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
219+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
220220
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
221221
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
222222

@@ -232,7 +232,7 @@ public function testConstructorWillReportFatalErrorWhenGetResponseResolvesWithIn
232232
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
233233

234234
$deferred = new Deferred();
235-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
235+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
236236
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
237237
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
238238

@@ -257,7 +257,7 @@ public function testConstructorWillReportFatalErrorWhenGetResponseResolvesWithIn
257257
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
258258

259259
$deferred = new Deferred();
260-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
260+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
261261
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
262262
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
263263

@@ -282,7 +282,7 @@ public function testConstructorWillReportOpenWhenGetResponseResolvesWithValidRes
282282
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
283283

284284
$deferred = new Deferred();
285-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
285+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
286286
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
287287
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
288288

@@ -305,7 +305,7 @@ public function testConstructorWillReportOpenWhenGetResponseResolvesWithValidRes
305305
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
306306

307307
$deferred = new Deferred();
308-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
308+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
309309
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
310310
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
311311

@@ -328,7 +328,7 @@ public function testConstructorWillReportOpenWhenGetResponseResolvesWithValidRes
328328
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
329329

330330
$deferred = new Deferred();
331-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
331+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
332332
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
333333
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
334334

@@ -355,7 +355,7 @@ public function testCloseResponseStreamWillStartRetryTimerWithoutErrorEvent()
355355
);
356356

357357
$deferred = new Deferred();
358-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
358+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
359359
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
360360
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
361361

@@ -381,7 +381,7 @@ public function testCloseFromOpenEventWillCloseResponseStreamAndCloseEventSource
381381
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
382382

383383
$deferred = new Deferred();
384-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
384+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
385385
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
386386
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
387387

@@ -404,7 +404,7 @@ public function testEmitMessageWithParsedDataFromEventStream()
404404
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
405405

406406
$deferred = new Deferred();
407-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
407+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
408408
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
409409
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
410410

@@ -431,7 +431,7 @@ public function testEmitMessageWithParsedIdAndDataOverMultipleRowsFromEventStrea
431431
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
432432

433433
$deferred = new Deferred();
434-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
434+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
435435
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
436436
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
437437

@@ -458,7 +458,7 @@ public function testEmitMessageWithParsedEventTypeAndDataWithTrailingWhitespaceF
458458
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
459459

460460
$deferred = new Deferred();
461-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
461+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
462462
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
463463
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
464464

@@ -484,7 +484,7 @@ public function testDoesNotEmitMessageWhenParsedEventStreamHasNoData()
484484
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
485485

486486
$deferred = new Deferred();
487-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
487+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
488488
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
489489
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
490490

@@ -509,7 +509,7 @@ public function testEmitMessageWithParsedDataAndPreviousIdWhenNotGivenAgainFromE
509509
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
510510

511511
$deferred = new Deferred();
512-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
512+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
513513
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
514514
$browser->expects($this->once())->method('requestStreaming')->willReturn($deferred->promise());
515515

@@ -544,7 +544,7 @@ public function testReconnectAfterStreamClosesUsesLastEventIdFromParsedEventStre
544544
);
545545

546546
$deferred = new Deferred();
547-
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
547+
$browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
548548
$browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf();
549549
$browser->expects($this->exactly(2))->method('requestStreaming')->withConsecutive(
550550
['GET', 'http://example.com', ['Accept' => 'text/event-stream', 'Cache-Control' => 'no-cache']],

0 commit comments

Comments
 (0)