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.

Greetings,

Andre

Hello Andre,

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

http://www.yiiframework.com/forum/index.php?/topic/11903-chapter-6-issuetest/

and

http://www.yiiframework.com/forum/index.php?/topic/11954-chapter-6-undefined-method-issuetestissues/

Hi again,

I solved the problem.

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


public $fixtures = array(


        'projects'=>'Project', 


    );

the code lines above raise errors while this:


public $fixtures = array(

        'projects'=>'Project', 

    );

works perfectly fine.

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

Greetings,

Andre

Hi,

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?