Yii Framework Forum: following book Agile Web Application Development fixtures issue - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

following book Agile Web Application Development fixtures issue

#1 User is offline   apolinux 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 13-February 12

Posted 16 June 2012 - 03:56 PM

I have followed the book Agile Web Application Development with Yii 1.1 and PHP5, and made the examples in a similar way like was described in the book, but applying to my own design.

All went ok until chapter 5 page 91. I got the error well known running the script CommerceTest, similar to ProjectTest but applied to my site:

There was 1 error:

1) CommerceTest::testRead
Exception: Unknown method 'commerces' for class 'CommerceTest'.

/xdir/yii/framework/test/CDbTestCase.php:78
/xdir/protected/tests/unit/CommerceTest.php:44
/xdir/protected/tests/unit/CommerceTest.php:44

In CommerceTest appears:

<?php
class CommerceTest extends CDbTestCase
{
public $fixtures=array
(
'commerces'=>'Commerce',
);

...

public function testRead()
{
$retrievedProject = $this->commerces('commerce1'); // <--- line 44
$this->assertTrue($retrievedProject instanceof Commerce);
$this->assertEquals('Test commerce 1',$retrievedProject->name);
}

I have searched all the web looking for the answer, and I tried everything, but nothing worked. The last try I did was to run the script with debug in netbeans, and I could get the answer, at least for me it worked.

In the fixtures dir, I just changed the name from "commerce.php" to "dbname.commerce.php" , and that's it, the test ran ok.

The only question is why worked or why is not well documented in the book.

thanks for your answers.
I prefer to teach fishing rather than give some fish
0

#2 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 513
  • Joined: 08-August 09

Posted 17 June 2012 - 01:02 AM

If you'd var_dump($this->commerces), you'd see it's an array (you return array() in relevant file).

Thus, you need to use square brackets to reach it's values, e.g.
$this->commerces['commerce1']


Otherwise it looks like you're trying to call a method commerces().
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users