In building a test for an FC I seem to be having trouble in ascertaining whether one method has made calls to two other class methods (all in same FC class).
To start the FC has a processRequest() method. This in turn makes calls to parseAction() and selectCommandClass(). Now how can I write a test case (on processRequest()) to ascertain that a call was made to the other two methods?
Test to date (I know about the desperate call to the mock class
Code: Select all
require_once(APPBASE . 'common.inc.php'); // a common file linking to backend lib - required
require_once(APPBASE . 'System/FrontController/FrontController.php');
Mock::generate('FrontController');
class TestOf_FrontController extends UnitTestCase {
var $_requestarray;
function TestOf_FrontController() {
$this->UnitTestCase('System => FrontController Test');
}
function SetUp() {
$_requestarray = $_REQUEST;
$_REQUEST['action'] = 'system.signup.process';
}
function tearDown() {
$_REQUEST = $_requestarray;
}
function testContructor() {
$front =& new FrontController($this);
$this->assertEqual($front->privatePage,true); //pass
}
function testExecute() {
// ... intercepting filter, etc. down to processRequest()
}
function testProcessRequest() {
// expected: FC should call parseAction() and selectCommand() in processRequest()
// how to accomplish?
$front =& new MockFrontController($this);
$front->expectOnce('parseAction', array());
$front->expectOnce('selectCommandClass', array());
$front->processRequest(); //the desperate "let's give it a long shot" error
$front->tally();
}
function testSelectCommandClass() {
// ...
}
function testParseAction() {
$this->assertWantedPattern('/^[-A-Z\.]*$/i', $_REQUEST['action']);
$front =& new FrontController($this);
$front->parseAction();
$this->assertEqual($front->module,'System'); //pass
$this->assertEqual($front->command,'SignupProcessCommand'); //pass
}
}