Skip to content
Permalink
Browse files

Very crude dispatch cycle is working now.

The code is pretty simple right now as it doesn't attempt any fancy
footwork around mocks or giving you ways to only get the just the view
without the layout. It is also not possible to get the view variables
just yet.

I've also added a stub response to smooth over any issues where someone
might try and send a response by accident or on purpose :)
  • Loading branch information...
markstory committed Sep 2, 2014
1 parent eec011e commit 07d559a0bbce8d093f9a0e19683bbe57f399974b
@@ -19,6 +19,7 @@
use Cake\Network\Session;
use Cake\Routing\DispatcherFactory;
use Cake\TestSuite\TestCase;
use Cake\TestSuite\Stub\Response;
/**
* A test case class intended to make integration tests of
@@ -32,7 +33,20 @@
*/
class IntegrationTestCase extends TestCase {
/**
* The data used to build the next request.
*
* @var array
*/
protected $_request = [];
/**
* The response for the most recent request.
*
* @var \Cake\Network\Response
*/
protected $_response;
protected $_session = [];
protected $_cookie = [];
@@ -46,6 +60,7 @@ public function tearDown() {
$this->_request = [];
$this->_session = [];
$this->_cookie = [];
$this->_response = null;
}
/**
@@ -183,6 +198,10 @@ public function delete($url) {
*/
protected function _sendRequest($url, $method, $data = null) {
$request = $this->_buildRequest($url, $method, $data);
$response = new Response();
$dispatcher = DispatcherFactory::create();
$dispatcher->dispatch($request, $response);
$this->_response = $response;
}
/**
@@ -211,7 +230,6 @@ protected function _buildRequest($url, $method, $data) {
unset($this->_request['headers']);
}
$props += $this->_request;
return new Request($props);
}
@@ -0,0 +1,32 @@
<?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\Stub;
use Cake\Network\Response as Base;
/**
* A response class intended for test cases.
*/
class Response extends Base {
/**
* Stub the send() method so headers and output are not sent.
*
* @return void
*/
public function send() {
}
}
@@ -14,6 +14,8 @@
*/
namespace Cake\Test\TestCase\TestSuite;
use Cake\Core\Configure;
use Cake\Routing\DispatcherFactory;
use Cake\Routing\Router;
use Cake\TestSuite\IntegrationTestCase;
@@ -22,9 +24,19 @@
*/
class IntegrationTestCaseTest extends IntegrationTestCase {
/**
* Setup method
*
* @return void
*/
public function setUp() {
parent::setUp();
Router::connect('/:controller/:action/*');
Configure::write('App.namespace', 'TestApp');
Router::connect('/:controller/:action/*', [], ['routeClass' => 'InflectedRoute']);
DispatcherFactory::clear();
DispatcherFactory::add('Routing');
DispatcherFactory::add('ControllerFactory');
}
/**
@@ -47,4 +59,17 @@ public function testRequestBuilding() {
$this->assertEquals(['id' => '1', 'username' => 'mark'], $request->session()->read('User'));
}
/**
* Test sending get requests.
*
* @return void
*/
public function testSendingGet() {
$this->assertNull($this->_response);
$this->get('/request_action/test_request_action');
$this->assertNotEmpty($this->_response);
$this->assertInstanceOf('Cake\Network\Response', $this->_response);
}
}

0 comments on commit 07d559a

Please sign in to comment.
You can’t perform that action at this time.