Thursday, November 24, 2011

Re: Creating a mocked model uses default database instead of test in PHPUnit

When mocking a model it is recommended that you pass the correct parameters to the contstructor:


$this->User = $this->getMock('User', array('_saveUploadedFile', '_removeUploadedFile'), array(false, 'users', 'test'));

The third parameter indicates that you want to use the 'users' table and the 'test' datasource for your mock object. That is what CakePHP internally does when you instantiate a new model in your tests using ClassRegistry::init()

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: