|
7 | 7 | use React\Stream\Stream; |
8 | 8 | use React\Promise\RejectedPromise; |
9 | 9 | use React\Promise\Deferred; |
| 10 | +use React\Promise\Promise; |
10 | 11 |
|
11 | 12 | class RequestTest extends TestCase |
12 | 13 | { |
@@ -442,15 +443,36 @@ public function pipeShouldPipeDataIntoTheRequestBody() |
442 | 443 |
|
443 | 444 | /** |
444 | 445 | * @test |
445 | | - * @expectedException InvalidArgumentException |
446 | | - * @expectedExceptionMessage $data must be null or scalar |
447 | 446 | */ |
448 | | - public function endShouldOnlyAcceptScalars() |
| 447 | + public function writeShouldStartConnecting() |
449 | 448 | { |
450 | 449 | $requestData = new RequestData('POST', 'http://www.example.com'); |
451 | 450 | $request = new Request($this->connector, $requestData); |
452 | 451 |
|
453 | | - $request->end(array()); |
| 452 | + $this->connector->expects($this->once()) |
| 453 | + ->method('connect') |
| 454 | + ->with('www.example.com:80') |
| 455 | + ->willReturn(new Promise(function () { })); |
| 456 | + |
| 457 | + $request->write('test'); |
| 458 | + } |
| 459 | + |
| 460 | + /** |
| 461 | + * @test |
| 462 | + */ |
| 463 | + public function endShouldStartConnectingAndChangeStreamIntoNonWritableMode() |
| 464 | + { |
| 465 | + $requestData = new RequestData('POST', 'http://www.example.com'); |
| 466 | + $request = new Request($this->connector, $requestData); |
| 467 | + |
| 468 | + $this->connector->expects($this->once()) |
| 469 | + ->method('connect') |
| 470 | + ->with('www.example.com:80') |
| 471 | + ->willReturn(new Promise(function () { })); |
| 472 | + |
| 473 | + $request->end(); |
| 474 | + |
| 475 | + $this->assertFalse($request->isWritable()); |
454 | 476 | } |
455 | 477 |
|
456 | 478 | /** |
@@ -479,6 +501,21 @@ public function writeAfterCloseReturnsFalse() |
479 | 501 | $this->assertFalse($request->write('nope')); |
480 | 502 | } |
481 | 503 |
|
| 504 | + /** |
| 505 | + * @test |
| 506 | + */ |
| 507 | + public function endAfterCloseIsNoOp() |
| 508 | + { |
| 509 | + $requestData = new RequestData('POST', 'http://www.example.com'); |
| 510 | + $request = new Request($this->connector, $requestData); |
| 511 | + |
| 512 | + $this->connector->expects($this->never()) |
| 513 | + ->method('connect'); |
| 514 | + |
| 515 | + $request->close(); |
| 516 | + $request->end(); |
| 517 | + } |
| 518 | + |
482 | 519 | /** @test */ |
483 | 520 | public function requestShouldRelayErrorEventsFromResponse() |
484 | 521 | { |
|
0 commit comments