如何在测试时模拟CakeRquest对象

I'm using cake 2.x and I'm trying to mock the CakeRequest object. Here's my attempt:

$AppUsers = $this->generate('AppUsers', array(
        'models' => array(
            'AppUser' => array('testIfValidates')
        ),
        'components' => array(
            'Auth',
            'Session',
            'Email' => array('send')
        )
    ));
 $request = $this->getMock('CakeRequest');
    $this->controller->request = $request;
    $this->controller->request->expects($this->once())
        ->method('is')
        ->with('ajax')
        ->will($this->returnValue(true));
 $this->testAction('/AppUsers/add');

And in my controller

 public function add() {
$this->request->is('ajax');
}

I get the error: Expectation failed for method name is equal to when invoked 1 time(s). Method was expected to be called 1 times, actually called 0 times. Any ideas on how I can make this work?