views:

35

answers:

3

Hi,

There is something weird going on in my code so i have to ask.

I have a part of a test:

public function testGetAddresses()
{
    //$this->markTestIncomplete('Not implemented yet');
    $this->assertTrue($this->_prs->getAddresses() instanceof Crm_Collection);
}

This test fails.

But when I do this:

if ($entity->getAddresses() instanceof Crm_Collection) {
    echo "TRUE!";
} else {
    echo "FALSE!";
}

It outputs TRUE!

Anybody knows what is going on or might this be a bug in phpunit?

Thanks!

+1  A: 

I doubt this is a PHPUnit's bug. Since you call getAddresses() method on two different objects I guess that in test that fails this method really returns something which is not Crm_Collection.

Is there a chance that getAddresses() method could return null or throw an exception?

vadimbelyaev
It couldnt return null, it just returns an empty collection.All other tests are running 100% fine. There are two classes inherited from the entity. It's the same class btw, the manual test is just a manual set variable.
baklap
A: 

Are other tests OK? Do you run the tests from a browser?

When you run PHP code from commandline I strongly recommend to set a correct path to php.ini. Otherwise PHP will use default values which might be different from your current php.ini

Not sure if this will solve your trouble but it's good to know. Once I spend couple of hours before I found this out.

php -c "c:/program files/apache software foundation/Apache2.2/" -f /path/to/your/script.php

dwich
I run my tests with cruisecontrol combined with phpUnderControl, the other 1000 tests are running fine. Just these two are giving me an error.
baklap
Even in Netbeans when I test locally it works. Maybe it has something to do with the database. Ill dump my local db to my CI server. Weirdness.
baklap
+1  A: 

Why vadimbelyaev said:

I don't think it's an issue with phpunit, doublecheck your code.

Additionally you can use:

$this->assertType("Classname", $object)

so you get a nice error in case it fails. (Phpunit will tell you "expected class, got null" instead of "expected true, got false" with helps a lot while debugging :) )

edorian
You were right, it returned null. Let's see why.Stupid me.
baklap
Happens to everyone from time to time. Glad we could help you solve that problem :)
edorian