1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the php-phantomjs. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace JonnyW\PhantomJs\Tests\Unit\Http; |
10
|
|
|
|
11
|
|
|
use JonnyW\PhantomJs\Http\MessageFactory; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* PHP PhantomJs |
15
|
|
|
* |
16
|
|
|
* @author Jon Wenmoth <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class MessageFactoryTest extends \PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
22
|
|
|
/** ++++++++++++++ TESTS ++++++++++++++ **/ |
23
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Test factory method creates message factory. |
27
|
|
|
* |
28
|
|
|
* @access public |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
public function testFactoryMethodCreatesMessageFactory() |
32
|
|
|
{ |
33
|
|
|
$this->assertInstanceOf('\JonnyW\PhantomJs\Http\MessageFactory', MessageFactory::getInstance()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Test can create request. |
38
|
|
|
* |
39
|
|
|
* @access public |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
public function testCanCreateRequest() |
43
|
|
|
{ |
44
|
|
|
$messageFactory = $this->getMessageFactory(); |
45
|
|
|
|
46
|
|
|
$this->assertInstanceOf('\JonnyW\PhantomJs\Http\Request', $messageFactory->createRequest()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Test can create request with URL. |
51
|
|
|
* |
52
|
|
|
* @access public |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
public function testCanCreateRequestWithUrl() |
56
|
|
|
{ |
57
|
|
|
$url = 'http://test.com'; |
58
|
|
|
|
59
|
|
|
$messageFactory = $this->getMessageFactory(); |
60
|
|
|
$request = $messageFactory->createRequest($url); |
61
|
|
|
|
62
|
|
|
$this->assertEquals($url, $request->getUrl()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Test can create request with method. |
67
|
|
|
* |
68
|
|
|
* @access public |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
public function testCanCreateRequestWithMethod() |
72
|
|
|
{ |
73
|
|
|
$method = 'POST'; |
74
|
|
|
|
75
|
|
|
$messageFactory = $this->getMessageFactory(); |
76
|
|
|
$request = $messageFactory->createRequest(null, $method); |
77
|
|
|
|
78
|
|
|
$this->assertEquals($method, $request->getMethod()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Test can create request with timeout. |
83
|
|
|
* |
84
|
|
|
* @access public |
85
|
|
|
* @return void |
86
|
|
|
*/ |
87
|
|
|
public function testCanCreateRequestWithTimeout() |
88
|
|
|
{ |
89
|
|
|
$timeout = 123456789; |
90
|
|
|
|
91
|
|
|
$messageFactory = $this->getMessageFactory(); |
92
|
|
|
$request = $messageFactory->createRequest(null, 'GET', $timeout); |
93
|
|
|
|
94
|
|
|
$this->assertEquals($timeout, $request->getTimeout()); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Test can create capture request. |
99
|
|
|
* |
100
|
|
|
* @access public |
101
|
|
|
* @return void |
102
|
|
|
*/ |
103
|
|
|
public function testCanCreateCaptureRequest() |
104
|
|
|
{ |
105
|
|
|
$messageFactory = $this->getMessageFactory(); |
106
|
|
|
|
107
|
|
|
$this->assertInstanceOf('\JonnyW\PhantomJs\Http\CaptureRequest', $messageFactory->createCaptureRequest()); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Test can create capture request with URL. |
112
|
|
|
* |
113
|
|
|
* @access public |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
|
|
public function testCanCreateCaptureRequestWithUrl() |
117
|
|
|
{ |
118
|
|
|
$url = 'http://test.com'; |
119
|
|
|
|
120
|
|
|
$messageFactory = $this->getMessageFactory(); |
121
|
|
|
$captureRequest = $messageFactory->createCaptureRequest($url); |
122
|
|
|
|
123
|
|
|
$this->assertEquals($url, $captureRequest->getUrl()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Test can create capture request |
128
|
|
|
* with method. |
129
|
|
|
* |
130
|
|
|
* @access public |
131
|
|
|
* @return void |
132
|
|
|
*/ |
133
|
|
|
public function testCanCreateCaptureRequestWithMethod() |
134
|
|
|
{ |
135
|
|
|
$method = 'POST'; |
136
|
|
|
|
137
|
|
|
$messageFactory = $this->getMessageFactory(); |
138
|
|
|
$captureRequest = $messageFactory->createCaptureRequest(null, $method); |
139
|
|
|
|
140
|
|
|
$this->assertEquals($method, $captureRequest->getMethod()); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Test can create capture request with timeout. |
145
|
|
|
* |
146
|
|
|
* @access public |
147
|
|
|
* @return void |
148
|
|
|
*/ |
149
|
|
|
public function testCanCreateCaptureRequestWithTimeout() |
150
|
|
|
{ |
151
|
|
|
$timeout = 123456789; |
152
|
|
|
|
153
|
|
|
$messageFactory = $this->getMessageFactory(); |
154
|
|
|
$captureRequest = $messageFactory->createCaptureRequest(null, 'GET', $timeout); |
155
|
|
|
|
156
|
|
|
$this->assertEquals($timeout, $captureRequest->getTimeout()); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Test can create response. |
161
|
|
|
* |
162
|
|
|
* @access public |
163
|
|
|
* @return void |
164
|
|
|
*/ |
165
|
|
|
public function testCanCreateResponse() |
166
|
|
|
{ |
167
|
|
|
$messageFactory = $this->getMessageFactory(); |
168
|
|
|
|
169
|
|
|
$this->assertInstanceOf('\JonnyW\PhantomJs\Http\Response', $messageFactory->createResponse()); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
173
|
|
|
/** ++++++++++ TEST ENTITIES ++++++++++ **/ |
174
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Get message factory instance. |
178
|
|
|
* |
179
|
|
|
* @access protected |
180
|
|
|
* @return \JonnyW\PhantomJs\Http\MessageFactory |
181
|
|
|
*/ |
182
|
|
|
protected function getMessageFactory() |
183
|
|
|
{ |
184
|
|
|
$messageFactory = new MessageFactory(); |
185
|
|
|
|
186
|
|
|
return $messageFactory; |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|