Friday, February 26, 2010

Re: Unit testing questions

It's rarely a wasted post, even if it just makes others look and think. It's all a learning process...

Jeremy Burns


On 26 Feb 2010, at 10:12, WebRenovator wrote:

> Hi
>
> I had another look at the code. Turns out I had made a mistake in the
> model name. It was referencing the wrong model. The save method didn't
> complain at all that the data didn't match the expected data (probably
> because i haven't yet set up those validation rules). Also, i double
> checked the normal process, and the record wasn't actually saving to
> the db.
>
> My apologies for the wasted post. Thanks your time and help :)
>
> On Feb 25, 4:17 pm, Grzegorz Pawlik <grzegorzpaw...@gmail.com> wrote:
>> Do You have fixtures defined? AFAIR I had similar problem, when no
>> fixtures loaded. Try creating fixtures with
>> var $import("model"=>"ModelName", "records"=> false);
>> var $records = array();
>>
>> For each model that is used in tests...
>>
>> On 25 Lut, 15:07, WebRenovator <ngev...@gmail.com> wrote:
>>
>>> ok.... here it is
>>
>>> class DATABASE_CONFIG {
>>
>>> var $default = array(
>>> 'driver' => 'mysqli',
>>> 'persistent' => false,
>>> 'host' => 'localhost',
>>> 'login' => 'boost',
>>> 'password' => 'boost',
>>> 'database' => 'boost',
>>> 'prefix' => '',
>>> );
>>
>>> var $test = array(
>>> 'driver' => 'mysqli',
>>> 'persistent' => false,
>>> 'host' => 'localhost',
>>> 'login' => 'apptest',
>>> 'password' => 'apptest',
>>> 'database' => 'apptest',
>>> 'prefix' => 'boost_',
>>> );}
>>
>>> ?>
>>
>>> for what its worth, it works the other way around .. ie if i write to
>>> the db in the test it picks it up in the code... but just not the
>>> other way round (as defined above)
>>
>>> On Feb 25, 3:24 pm, Grzegorz Pawlik <grzegorzpaw...@gmail.com> wrote:
>>
>>>> Please post contents of Your app/config/database.php file...
>>
>>>> On 24 Lut, 11:39, Nico <ngev...@gmail.com> wrote:
>>
>>>>> Greetings
>>
>>>>> I've run into something strange whiletestingmy models. Here's a
>>>>> scenaro (names have been changed for simplicity). I have 2 models,
>>>>> Article and Comment. in the article model i have code as such:
>>
>>>>> function myAction() {
>>>>> $this->Comment->save($data)}
>>
>>>>> now, I'm wanting to test this as part of my articleunittest, so i've
>>>>> got something similar to
>>
>>>>> $this->assertTrue(count($this->Article->Comment->find('all')) > 0);
>>
>>>>> The test returns an empty false (since no records have been written to
>>>>> the database), but when running the application as normal, it works.
>>>>> My theory is that the Article model isn't writing data to the Comment
>>>>> database table during the test since the Comment model hasn't been
>>>>> initialized. I've tried including the Comment model in the article
>>>>> test (as an import) as well as doing this in the startTest function
>>
>>>>> function startTest() {
>>>>> $this->Article =& ClassRegistry::init('Article');
>>>>> $this->Article->Comment =& ClassRegistry::init('Comment');
>>
>>>>> }
>>
>>>>> Still no luck. Has anybody had this experience before? What am I doing
>>>>> wrong?
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> 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?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate