Skip to content

Commit 97378c0

Browse files
committed
Add dedicated with* options methods in favour over withOptions
1 parent ca9537c commit 97378c0

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

src/Browser.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ public function withoutBase()
327327
*
328328
* @param array $options
329329
* @return self
330+
*
331+
* @deprecated Since 2.8.0 use withTimeout, withoutTimeout, withFollowRedirects, withMaxRedirects, or withObeySuccessCode instead.
330332
*/
331333
public function withOptions(array $options)
332334
{
@@ -335,4 +337,54 @@ public function withOptions(array $options)
335337

336338
return $browser;
337339
}
340+
341+
public function withTimeout($timeout)
342+
{
343+
$browser = clone $this;
344+
$browser->transaction = $this->transaction->withOptions(array(
345+
'timeout' => $timeout,
346+
));
347+
348+
return $browser;
349+
}
350+
351+
public function withoutTimeout()
352+
{
353+
$browser = clone $this;
354+
$browser->transaction = $this->transaction->withOptions(array(
355+
'timeout' => null,
356+
));
357+
358+
return $browser;
359+
}
360+
361+
public function withFollowRedirects($followRedirects)
362+
{
363+
$browser = clone $this;
364+
$browser->transaction = $this->transaction->withOptions(array(
365+
'followRedirects' => $followRedirects,
366+
));
367+
368+
return $browser;
369+
}
370+
371+
public function withMaxRedirects($maxRedirects)
372+
{
373+
$browser = clone $this;
374+
$browser->transaction = $this->transaction->withOptions(array(
375+
'maxRedirects' => $maxRedirects,
376+
));
377+
378+
return $browser;
379+
}
380+
381+
public function withObeySuccessCode($obeySuccessCode)
382+
{
383+
$browser = clone $this;
384+
$browser->transaction = $this->transaction->withOptions(array(
385+
'obeySuccessCode' => $obeySuccessCode,
386+
));
387+
388+
return $browser;
389+
}
338390
}

tests/FunctionalBrowserTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function testCancelRedirectedRequestShouldReject()
124124
*/
125125
public function testTimeoutDelayedResponseShouldReject()
126126
{
127-
$promise = $this->browser->withOptions(array('timeout' => 0.1))->get($this->base . 'delay/10');
127+
$promise = $this->browser->withTimeout(0.1)->get($this->base . 'delay/10');
128128

129129
Block\await($promise, $this->loop);
130130
}
@@ -137,7 +137,7 @@ public function testTimeoutDelayedResponseShouldReject()
137137
public function testTimeoutDelayedResponseAfterStreamingRequestShouldReject()
138138
{
139139
$stream = new ThroughStream();
140-
$promise = $this->browser->withOptions(array('timeout' => 0.1))->post($this->base . 'delay/10', array(), $stream);
140+
$promise = $this->browser->withTimeout(0.1)->post($this->base . 'delay/10', array(), $stream);
141141
$stream->end();
142142

143143
Block\await($promise, $this->loop);
@@ -149,7 +149,7 @@ public function testTimeoutDelayedResponseAfterStreamingRequestShouldReject()
149149
*/
150150
public function testTimeoutNegativeShouldResolveSuccessfully()
151151
{
152-
Block\await($this->browser->withOptions(array('timeout' => -1))->get($this->base . 'get'), $this->loop);
152+
Block\await($this->browser->withTimeout(-1)->get($this->base . 'get'), $this->loop);
153153
}
154154

155155
/**
@@ -176,7 +176,7 @@ public function testRedirectRequestAbsolute()
176176
*/
177177
public function testNotFollowingRedirectsResolvesWithRedirectResult()
178178
{
179-
$browser = $this->browser->withOptions(array('followRedirects' => false));
179+
$browser = $this->browser->withFollowRedirects(false);
180180

181181
Block\await($browser->get($this->base . 'redirect/3'), $this->loop);
182182
}
@@ -187,7 +187,7 @@ public function testNotFollowingRedirectsResolvesWithRedirectResult()
187187
*/
188188
public function testRejectingRedirectsRejects()
189189
{
190-
$browser = $this->browser->withOptions(array('maxRedirects' => 0));
190+
$browser = $this->browser->withMaxRedirects(0);
191191

192192
Block\await($browser->get($this->base . 'redirect/3'), $this->loop);
193193
}

0 commit comments

Comments
 (0)