I am new to phpunit and unit testing in general. I am trying to convert a large application to cakephp 2.0 and do unit tests for everything.
I am trying to create a mock object in which when $ this-> Session-> read ('Auth.Account.id') is called, it returns 144 ... this will give an account with an identifier that has elements.
however, I get an error because Mock seems to cause errors on other Session :: read ('AuthCode') calls in various beforeFilter calls;
The wait is not fulfilled for the method name is equal when called 1 time (a) Parameter 0 for calling SessionComponent :: read ('AuthCode') does not match the expected value. Failed to claim that two lines are equal.
As I said, I'm new to phpunit and unit testing ... what am I doing wrong?
class PagesController extends MastersController {
public function support(){
if($this->Session->read('Auth.Account.id')) {
$items = $this->Account->Items->find('list', array('conditions'=>array('Items.account_id'=>$this->Session->read('Auth.Account.id'))));
}
$this->set(compact('items'));
}
}
class PagesControllerTestCase extends CakeTestCase {
public function testSupport() {
$this->PagesController = $this->generate('Pages', array(
'methods'=>array('support'),
'components' => array(
'Auth',
'Session',
),
));
$this->PagesController->Session->expects(
$this->once())
->method('read')
->with($this->equalTo('Auth.Account.id'))
->will($this->returnValue(144));
$this->testAction('support');
}
}
source
share