forked from reactphp/reactphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponseTest.php
More file actions
78 lines (61 loc) · 2.06 KB
/
Copy pathResponseTest.php
File metadata and controls
78 lines (61 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace React\Tests\HttpClient;
use React\HttpClient\Response;
use React\Tests\Socket\TestCase;
class ResponseTest extends TestCase
{
private $stream;
public function setUp()
{
$this->stream = $this->getMockbuilder('React\Stream\Stream')
->disableOriginalConstructor()
->getMock();
}
/** @test */
public function responseShouldEmitEndEventOnEnd()
{
$this->stream
->expects($this->at(0))
->method('on')
->with('data', $this->anything());
$this->stream
->expects($this->at(1))
->method('on')
->with('error', $this->anything());
$this->stream
->expects($this->at(2))
->method('on')
->with('end', $this->anything());
$response = new Response($this->stream, 'HTTP', '1.0', '200', 'OK', array('Content-Type' => 'text/plain'));
$handler = $this->createCallableMock();
$handler->expects($this->once())
->method('__invoke')
->with('some data', $this->anything());
$response->on('data', $handler);
$handler = $this->createCallableMock();
$handler->expects($this->once())
->method('__invoke')
->with(null, $this->isInstanceOf('React\HttpClient\Response'));
$response->on('end', $handler);
$response->on('close', $this->expectCallableNever());
$this->stream
->expects($this->at(0))
->method('end');
$response->handleData('some data');
$response->handleEnd();
}
/** @test */
public function closedResponseShouldNotBeResumedOrPaused()
{
$response = new Response($this->stream, 'http', '1.0', '200', 'ok', array('content-type' => 'text/plain'));
$this->stream
->expects($this->never())
->method('pause');
$this->stream
->expects($this->never())
->method('resume');
$response->handleEnd();
$response->resume();
$response->pause();
}
}