Skip to content

Commit

Permalink
Add test for assertStatusCode and cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Dec 15, 2014
1 parent ef0ad44 commit 9f4865f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 43 deletions.
86 changes: 43 additions & 43 deletions src/TestSuite/IntegrationTestCase.php
Expand Up @@ -91,7 +91,7 @@ abstract class IntegrationTestCase extends TestCase {
protected $_requestSession;

/**
* Reset the EventManager for before each test.
* Resets the EventManager for before each test.
*
* @return void
*/
Expand All @@ -101,7 +101,7 @@ public function setUp() {
}

/**
* Clear the state used for requests.
* Clears the state used for requests.
*
* @return void
*/
Expand All @@ -118,7 +118,7 @@ public function tearDown() {
}

/**
* Configure the data for the *next* request.
* Configures the data for the *next* request.
*
* This data is cleared in the tearDown() method.
*
Expand All @@ -133,7 +133,7 @@ public function configRequest(array $data) {
}

/**
* Set session data.
* Sets session data.
*
* This method lets you configure the session data
* you want to be used for requests that follow. The session
Expand All @@ -150,7 +150,7 @@ public function session(array $data) {
}

/**
* Set a request cookie for future requests.
* Sets a request cookie for future requests.
*
* This method lets you configure the session data
* you want to be used for requests that follow. The session
Expand All @@ -168,7 +168,7 @@ public function cookie($name, $value) {
}

/**
* Perform a GET request using the current request data.
* Performs a GET request using the current request data.
*
* The response of the dispatched request will be stored as
* a property. You can use various assert methods to check the
Expand All @@ -182,7 +182,7 @@ public function get($url) {
}

/**
* Perform a POST request using the current request data.
* Performs a POST request using the current request data.
*
* The response of the dispatched request will be stored as
* a property. You can use various assert methods to check the
Expand All @@ -197,7 +197,7 @@ public function post($url, $data = []) {
}

/**
* Perform a PATCH request using the current request data.
* Performs a PATCH request using the current request data.
*
* The response of the dispatched request will be stored as
* a property. You can use various assert methods to check the
Expand All @@ -212,7 +212,7 @@ public function patch($url, $data = []) {
}

/**
* Perform a PUT request using the current request data.
* Performs a PUT request using the current request data.
*
* The response of the dispatched request will be stored as
* a property. You can use various assert methods to check the
Expand All @@ -227,7 +227,7 @@ public function put($url, $data = []) {
}

/**
* Perform a DELETE request using the current request data.
* Performs a DELETE request using the current request data.
*
* The response of the dispatched request will be stored as
* a property. You can use various assert methods to check the
Expand All @@ -241,7 +241,7 @@ public function delete($url) {
}

/**
* Create and send the request into a Dispatcher instance.
* Creates and send the request into a Dispatcher instance.
*
* Receives and stores the response for future inspection.
*
Expand Down Expand Up @@ -272,7 +272,7 @@ protected function _sendRequest($url, $method, $data = []) {
}

/**
* Add additional event spies to the controller/view event manager.
* Adds additional event spies to the controller/view event manager.
*
* @param \Cake\Event\Event $event A dispatcher event.
* @return void
Expand All @@ -292,7 +292,7 @@ public function controllerSpy($event) {
}

/**
* Attempt to render an error response for a given exception.
* Attempts to render an error response for a given exception.
*
* This method will attempt to use the configured exception renderer.
* If that class does not exist, the built-in renderer will be used.
Expand All @@ -311,7 +311,7 @@ protected function _handleError($exception) {
}

/**
* Create a request object with the configured options and parameters.
* Creates a request object with the configured options and parameters.
*
* @param string|array $url The URL
* @param string $method The HTTP method
Expand Down Expand Up @@ -345,7 +345,25 @@ protected function _buildRequest($url, $method, $data) {
}

/**
* Assert that the response status code is in the 2xx range.
* Fetches a view variable by name.
*
* If the view variable does not exist, null will be returned.
*
* @param string $name The view variable to get.
* @return mixed The view variable if set.
*/
public function viewVariable($name) {
if (empty($this->_controller->viewVars)) {
$this->fail('There are no view variables, perhaps you need to run a request?');
}
if (isset($this->_controller->viewVars[$name])) {
return $this->_controller->viewVars[$name];
}
return null;
}

/**
* Asserts that the response status code is in the 2xx range.
*
* @return void
*/
Expand All @@ -354,7 +372,7 @@ public function assertResponseOk() {
}

/**
* Assert that the response status code is in the 4xx range.
* Asserts that the response status code is in the 4xx range.
*
* @return void
*/
Expand All @@ -363,7 +381,7 @@ public function assertResponseError() {
}

/**
* Assert that the response status code is in the 5xx range.
* Asserts that the response status code is in the 5xx range.
*
* @return void
*/
Expand Down Expand Up @@ -400,7 +418,7 @@ protected function _assertStatus($min, $max, $message) {
}

/**
* Assert that the Location header is correct.
* Asserts that the Location header is correct.
*
* @param string|array $url The url you expected the client to go to. This
* can either be a string URL or an array compatible with Router::url()
Expand All @@ -419,7 +437,7 @@ public function assertRedirect($url, $message = '') {
}

/**
* Assert response headers
* Asserts response headers
*
* @param string $header The header to check
* @param string $content The content to check for.
Expand All @@ -438,7 +456,7 @@ public function assertHeader($header, $content, $message = '') {
}

/**
* Assert content type
* Asserts content type
*
* @param string $type The content-type to check for.
* @param string $message The failure message that will be appended to the generated message.
Expand All @@ -457,7 +475,7 @@ public function assertContentType($type, $message = '') {
}

/**
* Assert content exists in the response body.
* Asserts content exists in the response body.
*
* @param string $content The content to check for.
* @param string $message The failure message that will be appended to the generated message.
Expand All @@ -471,7 +489,7 @@ public function assertResponseContains($content, $message = '') {
}

/**
* Assert that the search string was in the template name.
* Asserts that the search string was in the template name.
*
* @param string $content The content to check for.
* @param string $message The failure message that will be appended to the generated message.
Expand All @@ -485,7 +503,7 @@ public function assertTemplate($content, $message = '') {
}

/**
* Assert that the search string was in the layout name.
* Asserts that the search string was in the layout name.
*
* @param string $content The content to check for.
* @param string $message The failure message that will be appended to the generated message.
Expand All @@ -499,25 +517,7 @@ public function assertLayout($content, $message = '') {
}

/**
* Fetch a view variable by name.
*
* If the view variable does not exist null will be returned.
*
* @param string $name The view variable to get.
* @return mixed The view variable if set.
*/
public function viewVariable($name) {
if (empty($this->_controller->viewVars)) {
$this->fail('There are no view variables, perhaps you need to run a request?');
}
if (isset($this->_controller->viewVars[$name])) {
return $this->_controller->viewVars[$name];
}
return null;
}

/**
* Assert session contents
* Asserts session contents
*
* @param string $expected The expected contents.
* @param string $path The session data path. Uses Hash::get() compatible notation
Expand All @@ -533,7 +533,7 @@ public function assertSession($expected, $path, $message = '') {
}

/**
* Assert cookie values
* Asserts cookie values
*
* @param string $expected The expected contents.
* @param string $name The cookie name.
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase/TestSuite/IntegrationTestCaseTest.php
Expand Up @@ -153,6 +153,9 @@ public function testAssertResponseStatusCodes() {

$this->_response->statusCode(505);
$this->assertResponseFailure();

$this->_response->statusCode(301);
$this->assertResponseCode(301);
}

/**
Expand Down

0 comments on commit 9f4865f

Please sign in to comment.