使用默认的数据库,而不是测试,我在CakePHP中2测试模型,并嘲笑这样的模式:创建PHPUnit的嘲弄模型CakePHP的
$this->User = $this->getMock('User', array(
'_saveUploadedFile',
'_removeUploadedFile',
));
$this->User->expects($this->any())
->method('_saveUploadedFile')
->with($data, Configure::read('App.myDirectory'), true);
->will($this->returnValue(true));
$this->User->expects($this->any())
->method('_removeUploadedFile')
->with($data, Configure::read('App.myDirectory'))
->will($this->returnValue(true));
由于与数据库的任何操作引发以下错误:
"Database table mock__user_b6241a4cs for model User was not found."
我重新定义了模型信息:
$this->User->alias = 'User';
$this->User->useTable = 'users';
现在的测试工作好吧,但它使用database.php
中的$default
数据库而不是$test
。会发生什么?
为什么测试数据库配置在使用模拟对象时发生变化?它可能与数据库权限有关,导致模拟对象无法创建自定义表?
谢谢!