Session 使用断言会话值进行CakePHP测试
我有一个带操作手册的控制器:Session 使用断言会话值进行CakePHP测试,session,cakephp,testing,assert,Session,Cakephp,Testing,Assert,我有一个带操作手册的控制器: class SeatFormController extends AppController{ public function book($layout,$tourcode,$date){ if($tourcode){ $this->Session->write('seatform_tourcode',$tourcode); ..... } } } 现在,我有了SeatForm
class SeatFormController extends AppController{
public function book($layout,$tourcode,$date){
if($tourcode){
$this->Session->write('seatform_tourcode',$tourcode);
.....
}
}
}
现在,我有了SeatFormController测试类
class SeatFormControllerTest extends ControllerTestCase{
public function testBook(){
$result = $this->testAction('/tour/seat_form/book/plumeriabali/TPPTN6TM31-TPW');
}
}
如何断言会话变量“seatform_tourcode”的值。
我试图在测试中使用$this->controller->Session->read('seatform\u tourcode')
,但它不起作用。
我还尝试:
$tourcode = 'TPPTN6TM31-TPW';
$this->controller->Session->expects(
$this->once())->method('read')
->with($this->equalTo('seatform_tourcode'))
->will($this->returnValue($tourcode));
但似乎并没有达到我的预期
有什么建议吗?非常感谢 我认为我们可以使用:
$this->assertEquals($_SESSION['seatform_tourcode'.$tourcode],$tourcode);