Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Not much here, but getting something down is a start.
- Loading branch information
Showing
1 changed file
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
<?php | ||
/** | ||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||
* @since 3.0.0 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Cake\TestSuite; | ||
|
||
use Cake\TestSuite\TestCase; | ||
|
||
/** | ||
* A test case class intended to make integration tests of | ||
* your controllers easier. | ||
* | ||
* This test class provides a number of helper methods and features | ||
* that make dispatching requests and checking their responses simpler. | ||
* It favours full integration tests over mock objects as you can test | ||
* more of your code easily and avoid some of the maintenance pitfalls | ||
* that mock objects create. | ||
*/ | ||
class IntegrationTestCase extends TestCase { | ||
|
||
protected $_request = []; | ||
protected $_session = []; | ||
protected $_cookie = []; | ||
|
||
/** | ||
* Clear the state used for requests. | ||
* | ||
* @return void | ||
*/ | ||
public function tearDown() { | ||
parent::tearDown(); | ||
$this->_request = []; | ||
$this->_session = []; | ||
$this->_cookie = []; | ||
} | ||
|
||
/** | ||
* Configure the data for tne *next* request. | ||
* | ||
* This data is cleared in the tearDown() method. | ||
* | ||
* You can call this method multiple times to append into | ||
* the current state. | ||
* | ||
* @param array $data The request data to use. | ||
* @return void | ||
*/ | ||
public function configRequest(array $data) { | ||
$this->_request = $data + $this->_request; | ||
} | ||
|
||
/** | ||
* Set session data. | ||
* | ||
* This method lets you configure the session data | ||
* you want to be used for requests that follow. The session | ||
* state is reset in each tearDown(). | ||
* | ||
* You can call this method multiple times to append into | ||
* the current state. | ||
* | ||
* @param array $data The session data to use. | ||
* @return void | ||
*/ | ||
public function session(array $data) { | ||
$this->_session = $data + $this->_session; | ||
} | ||
|
||
/** | ||
* Set 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 | ||
* state is reset in each tearDown(). | ||
* | ||
* You can call this method multiple times to append into | ||
* the current state. | ||
* | ||
* @param string $name The cookie name to use. | ||
* @param mixed $value The value of the cookie. | ||
* @return void | ||
*/ | ||
public function cookie($name, $value) { | ||
$this->_cookie[$name] = $value; | ||
} | ||
|
||
/** | ||
* Perform 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 | ||
* response. | ||
* | ||
* @param string $url The url to request. | ||
* @return void | ||
*/ | ||
public function get($url) { | ||
$this->_sendRequest($url, 'GET'); | ||
} | ||
|
||
/** | ||
* Perform 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 | ||
* response. | ||
* | ||
* @param string $url The url to request. | ||
* @param array $data The data for the request. | ||
* @return void | ||
*/ | ||
public function post($url, $data = []) { | ||
$this->_sendRequest($url, 'POST', $data); | ||
} | ||
|
||
/** | ||
* Perform 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 | ||
* response. | ||
* | ||
* @param string $url The url to request. | ||
* @param array $data The data for the request. | ||
* @return void | ||
*/ | ||
public function patch($url, $data = []) { | ||
$this->_sendRequest($url, 'PATCH', $data); | ||
} | ||
|
||
/** | ||
* Perform 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 | ||
* response. | ||
* | ||
* @param string $url The url to request. | ||
* @param array $data The data for the request. | ||
* @return void | ||
*/ | ||
public function put($url, $data = []) { | ||
$this->_sendRequest($url, 'PUT', $data); | ||
} | ||
|
||
/** | ||
* Perform 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 | ||
* response. | ||
* | ||
* @param string $url The url to request. | ||
* @return void | ||
*/ | ||
public function delete($url) { | ||
$this->_sendRequest($url, 'DELETE'); | ||
} | ||
|
||
/** | ||
* Create and send the request into a Dispatcher instance. | ||
* | ||
* Receives and stores the response for future inspection. | ||
* | ||
* @param string $url The url | ||
* @param string $method The HTTP method | ||
* @param array|null $data The request data. | ||
* @return void | ||
*/ | ||
protected function _sendRequest($url, $method, $data = null) { | ||
} | ||
|
||
} |