使用默認的數據庫,而不是測試,我在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
。會發生什麼?
爲什麼測試數據庫配置在使用模擬對象時發生變化?它可能與數據庫權限有關,導致模擬對象無法創建自定義表?
謝謝!