Wednesday, November 30, 2011

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

It worked, but in addition I have to set the model alias:

$this->User->alias = 'User';

because a simple `$this->User->read(null, 1)` raised an error saying
that 'User.a_column' couldn't be found.


On Nov 24, 3:22 pm, José Lorenzo <jose....@gmail.com> wrote:
> 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: