Chapter 5, Page 90 - Using Fixtures

Hi everyone,

I can’t seem to read values from the fixtures array in ProjectTest.php.

What am I doing wrong?

My code looks as follows:

$retrievedProject = $this->projects['project1'];

and the output for the unit test says this

1) ProjectTest::testRead

Exception: Unknown property 'projects' for class 'ProjectTest'.

where am I going wrong? any help would be appreciated.



Hello Andre,

Please first take a look at both of these threads to see if they help you with your problem:


Hi again,

I solved the problem.

Somehow it matters if you have blank lines in this piece of code.

public $fixtures = array(



the code lines above raise errors while this:

public $fixtures = array(



works perfectly fine.

Seems a little weird to me, but at least I figured it out :)




I have exactly the same problem . I tried solution above but nothing works. Also I check and double check code inside ProjectTest.php, fixtures data and seems to be no typo errors but non of above didn’t work.

Please if anyone cn help to resolve this problem I’m stuck here.

I’m on yii-1.1.2.r2086.

Thanks in advance

Perhaps one needs to create tests for their tests? :lol:

One good reason that I do not use the TDD approach.

I would like to agree with Backslider’s first statement/question. There should absolutely be tests written for core framework functionality in Yii, including the testing framework. Second statement respectfully disagree. No reason to quit unit testing when it gets difficult, tests are almost always more difficult to write than the models being tested.

As for the specific problem that we are addressing in this thread, my strong advice is to make sure that your table name in the model that you are testing is exactly the same as the fixture file name. For example, if my model’s table name is LOOKUP, then my fixture file name should be ‘LOOKUP.php’ <-- note that the capitalization matters.

Maybe it shouldn’t?