Skip to content

Commit

Permalink
Make MakesHttpRequest methods accept method chaining (#13529)
Browse files Browse the repository at this point in the history
  • Loading branch information
sileence authored and taylorotwell committed May 12, 2016
1 parent 9ea735d commit e254132
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,12 @@ protected function seeCookie($cookieName, $value = null, $encrypted = true)
$actual = $encrypted
? $this->app['encrypter']->decrypt($cookieValue) : $cookieValue;

return $this->assertEquals(
$this->assertEquals(
$actual, $value,
"Cookie [{$cookieName}] was found, but value [{$actual}] does not match [{$value}]."
);

return $this;
}

/**
Expand Down Expand Up @@ -615,34 +617,38 @@ protected function transformHeadersToServerVars(array $headers)
/**
* Assert that the client response has an OK status code.
*
* @return void
* @return $this
*/
public function assertResponseOk()
{
$actual = $this->response->getStatusCode();

return PHPUnit::assertTrue($this->response->isOk(), "Expected status code 200, got {$actual}.");
PHPUnit::assertTrue($this->response->isOk(), "Expected status code 200, got {$actual}.");

return $this;
}

/**
* Assert that the client response has a given code.
*
* @param int $code
* @return void
* @return $this
*/
public function assertResponseStatus($code)
{
$actual = $this->response->getStatusCode();

return PHPUnit::assertEquals($code, $this->response->getStatusCode(), "Expected status code {$code}, got {$actual}.");
PHPUnit::assertEquals($code, $this->response->getStatusCode(), "Expected status code {$code}, got {$actual}.");

return $this;
}

/**
* Assert that the response view has a given piece of bound data.
*
* @param string|array $key
* @param mixed $value
* @return void
* @return $this
*/
public function assertViewHas($key, $value = null)
{
Expand All @@ -659,13 +665,15 @@ public function assertViewHas($key, $value = null)
} else {
PHPUnit::assertEquals($value, $this->response->original->$key);
}

return $this;
}

/**
* Assert that the view has a given list of bound data.
*
* @param array $bindings
* @return void
* @return $this
*/
public function assertViewHasAll(array $bindings)
{
Expand All @@ -676,13 +684,15 @@ public function assertViewHasAll(array $bindings)
$this->assertViewHas($key, $value);
}
}

return $this;
}

/**
* Assert that the response view is missing a piece of bound data.
*
* @param string $key
* @return void
* @return $this
*/
public function assertViewMissing($key)
{
Expand All @@ -691,14 +701,16 @@ public function assertViewMissing($key)
}

PHPUnit::assertArrayNotHasKey($key, $this->response->original->getData());

return $this;
}

/**
* Assert whether the client was redirected to a given URI.
*
* @param string $uri
* @param array $with
* @return void
* @return $this
*/
public function assertRedirectedTo($uri, $with = [])
{
Expand All @@ -707,6 +719,8 @@ public function assertRedirectedTo($uri, $with = [])
PHPUnit::assertEquals($this->app['url']->to($uri), $this->response->headers->get('Location'));

$this->assertSessionHasAll($with);

return $this;
}

/**
Expand All @@ -715,11 +729,11 @@ public function assertRedirectedTo($uri, $with = [])
* @param string $name
* @param array $parameters
* @param array $with
* @return void
* @return $this
*/
public function assertRedirectedToRoute($name, $parameters = [], $with = [])
{
$this->assertRedirectedTo($this->app['url']->route($name, $parameters), $with);
return $this->assertRedirectedTo($this->app['url']->route($name, $parameters), $with);
}

/**
Expand All @@ -728,11 +742,11 @@ public function assertRedirectedToRoute($name, $parameters = [], $with = [])
* @param string $name
* @param array $parameters
* @param array $with
* @return void
* @return $this
*/
public function assertRedirectedToAction($name, $parameters = [], $with = [])
{
$this->assertRedirectedTo($this->app['url']->action($name, $parameters), $with);
return $this->assertRedirectedTo($this->app['url']->action($name, $parameters), $with);
}

/**
Expand Down

0 comments on commit e254132

Please sign in to comment.