Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b037963

Browse files
committed
Avoid nullable values in some Client's methods
1 parent 9e82562 commit b037963

File tree

3 files changed

+71
-7
lines changed

3 files changed

+71
-7
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,28 @@ public function getCookieJar()
183183
/**
184184
* Returns the current Crawler instance.
185185
*
186-
* @return Crawler|null A Crawler instance
186+
* @return Crawler A Crawler instance
187187
*/
188188
public function getCrawler()
189189
{
190+
if (null === $this->crawler) {
191+
@trigger_error(sprintf('Calling the "%s()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.', __METHOD__), E_USER_DEPRECATED);
192+
}
193+
190194
return $this->crawler;
191195
}
192196

193197
/**
194198
* Returns the current BrowserKit Response instance.
195199
*
196-
* @return Response|null A BrowserKit Response instance
200+
* @return Response A BrowserKit Response instance
197201
*/
198202
public function getInternalResponse()
199203
{
204+
if (null === $this->internalResponse) {
205+
@trigger_error(sprintf('Calling the "%s()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.', __METHOD__), E_USER_DEPRECATED);
206+
}
207+
200208
return $this->internalResponse;
201209
}
202210

@@ -206,22 +214,30 @@ public function getInternalResponse()
206214
* The origin response is the response instance that is returned
207215
* by the code that handles requests.
208216
*
209-
* @return object|null A response instance
217+
* @return object A response instance
210218
*
211219
* @see doRequest()
212220
*/
213221
public function getResponse()
214222
{
223+
if (null === $this->response) {
224+
@trigger_error(sprintf('Calling the "%s()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.', __METHOD__), E_USER_DEPRECATED);
225+
}
226+
215227
return $this->response;
216228
}
217229

218230
/**
219231
* Returns the current BrowserKit Request instance.
220232
*
221-
* @return Request|null A BrowserKit Request instance
233+
* @return Request A BrowserKit Request instance
222234
*/
223235
public function getInternalRequest()
224236
{
237+
if (null === $this->internalRequest) {
238+
@trigger_error(sprintf('Calling the "%s()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.', __METHOD__), E_USER_DEPRECATED);
239+
}
240+
225241
return $this->internalRequest;
226242
}
227243

@@ -231,12 +247,16 @@ public function getInternalRequest()
231247
* The origin request is the request instance that is sent
232248
* to the code that handles requests.
233249
*
234-
* @return object|null A Request instance
250+
* @return object A Request instance
235251
*
236252
* @see doRequest()
237253
*/
238254
public function getRequest()
239255
{
256+
if (null === $this->request) {
257+
@trigger_error(sprintf('Calling the "%s()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.', __METHOD__), E_USER_DEPRECATED);
258+
}
259+
240260
return $this->request;
241261
}
242262

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ public function testGetRequest()
9494
$this->assertEquals('http://example.com/', $client->getRequest()->getUri(), '->getCrawler() returns the Request of the last request');
9595
}
9696

97+
/**
98+
* @group legacy
99+
* @expectedDeprecation Calling the "Symfony\Component\BrowserKit\Client::getRequest()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.
100+
*/
101+
public function testGetRequestNull()
102+
{
103+
$client = new TestClient();
104+
$this->assertNull($client->getRequest());
105+
}
106+
97107
public function testGetRequestWithXHR()
98108
{
99109
$client = new TestClient();
@@ -124,6 +134,16 @@ public function testGetResponse()
124134
$this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getResponse(), '->getCrawler() returns the Response of the last request');
125135
}
126136

137+
/**
138+
* @group legacy
139+
* @expectedDeprecation Calling the "Symfony\Component\BrowserKit\Client::getResponse()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.
140+
*/
141+
public function testGetResponseNull()
142+
{
143+
$client = new TestClient();
144+
$this->assertNull($client->getResponse());
145+
}
146+
127147
public function testGetInternalResponse()
128148
{
129149
$client = new TestClient();
@@ -135,6 +155,16 @@ public function testGetInternalResponse()
135155
$this->assertInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialResponse', $client->getResponse());
136156
}
137157

158+
/**
159+
* @group legacy
160+
* @expectedDeprecation Calling the "Symfony\Component\BrowserKit\Client::getInternalResponse()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.
161+
*/
162+
public function testGetInternalResponseNull()
163+
{
164+
$client = new TestClient();
165+
$this->assertNull($client->getInternalResponse());
166+
}
167+
138168
public function testGetContent()
139169
{
140170
$json = '{"jsonrpc":"2.0","method":"echo","id":7,"params":["Hello World"]}';
@@ -153,6 +183,16 @@ public function testGetCrawler()
153183
$this->assertSame($crawler, $client->getCrawler(), '->getCrawler() returns the Crawler of the last request');
154184
}
155185

186+
/**
187+
* @group legacy
188+
* @expectedDeprecation Calling the "Symfony\Component\BrowserKit\Client::getCrawler()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.
189+
*/
190+
public function testGetCrawlerNull()
191+
{
192+
$client = new TestClient();
193+
$this->assertNull($client->getCrawler());
194+
}
195+
156196
public function testRequestHttpHeaders()
157197
{
158198
$client = new TestClient();
@@ -720,6 +760,10 @@ public function testInternalRequest()
720760
$this->assertInstanceOf('Symfony\Component\BrowserKit\Request', $client->getInternalRequest());
721761
}
722762

763+
/**
764+
* @group legacy
765+
* @expectedDeprecation Calling the "Symfony\Component\BrowserKit\Client::getInternalRequest()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.
766+
*/
723767
public function testInternalRequestNull()
724768
{
725769
$client = new TestClient();

src/Symfony/Component/HttpKernel/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
*
2626
* @author Fabien Potencier <[email protected]>
2727
*
28-
* @method Request|null getRequest() A Request instance
29-
* @method Response|null getResponse() A Response instance
28+
* @method Request getRequest() A Request instance
29+
* @method Response getResponse() A Response instance
3030
*/
3131
class Client extends BaseClient
3232
{

0 commit comments

Comments
 (0)