Skip to content

Commit

Permalink
Add dedicated with* options methods in favour over withOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Mar 13, 2020
1 parent ca9537c commit 3d65b77
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
30 changes: 30 additions & 0 deletions src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ public function withoutBase()
*
* @param array $options
* @return self
*
* @deprecated Since 2.8.0 use withTimeout, withFollowRedirects, withMaxRedirects, or withObeySuccessCode instead.
*/
public function withOptions(array $options)
{
Expand All @@ -335,4 +337,32 @@ public function withOptions(array $options)

return $browser;
}

public function withTimeout($timeout)
{
return $this->withOptions(array(
'timeout' => $timeout,
));
}

public function withFollowRedirects($followRedirects)
{
return $this->withOptions(array(
'followRedirects' => $followRedirects,
));
}

public function withMaxRedirects($maxRedirects)
{
return $this->withOptions(array(
'maxRedirects' => $maxRedirects,
));
}

public function withObeySuccessCode($obeySuccessCode)
{
return $this->withOptions(array(
'obeySuccessCode' => $obeySuccessCode,
));
}
}
10 changes: 5 additions & 5 deletions tests/FunctionalBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function testCancelRedirectedRequestShouldReject()
*/
public function testTimeoutDelayedResponseShouldReject()
{
$promise = $this->browser->withOptions(array('timeout' => 0.1))->get($this->base . 'delay/10');
$promise = $this->browser->withTimeout(0.1)->get($this->base . 'delay/10');

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

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

/**
Expand All @@ -176,7 +176,7 @@ public function testRedirectRequestAbsolute()
*/
public function testNotFollowingRedirectsResolvesWithRedirectResult()
{
$browser = $this->browser->withOptions(array('followRedirects' => false));
$browser = $this->browser->withFollowRedirects(false);

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

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

0 comments on commit 3d65b77

Please sign in to comment.