Yii Fixtures --- Exception: Unknown 'projects' properties for class 'ProjectTest'

I am following "Agile web application development with yii 1.1 and php5" and I am in the testing section with sections. I followed their code, but I cannot access the device ...

I run my tests with phpunit and it returns me this

c:\wamp\www\agileBook\protected\tests>phpunit unit/ProjectTest.php
PHPUnit 3.6.11 by Sebastian Bergmann.

Configuration read from C:\wamp\www\agileBook\protected\tests\phpunit.xml

←[31;1mE←[0m

Time: 0 seconds, Memory: 5.75Mb

There was 1 error:

1) ProjectTest::testRead
Exception: Unknown property 'projects' for class 'ProjectTest'.

C:\wamp\yii\framework\test\CDbTestCase.php:63
C:\wamp\www\agileBook\protected\tests\unit\ProjectTest.php:11
C:\wamp\bin\php\php5.3.13\phpunit:46

←[37;41m←[2KFAILURES!
←[0m←[37;41m←[2KTests: 1, Assertions: 0, Errors: 1.
←[0m←[2K

      

How can I get it to work?

Thank you for your help

my fixture: C: \ wamp \ www \ agileBook \ protected \ tests \ fixtures \ tbl_project.php

<?php 

return array(

    'project1' => array(
        'name' => 'Test Project 1',
        'description' =>'This is test project 1',
        'create_time' =>'',
        'create_user_id' =>'',
        'update_time' =>'',
        'update_user_id' =>'',
    ),
    'project2' => array(
        'name' => 'Test Project 2',
        'description' =>'This is test project 2',
        'create_time' =>'',
        'create_user_id' =>'',
        'update_time' =>'',
        'update_user_id' =>'',
    ),

),

?>

      

my test class Project: C: \ wamp \ www \ agileBook \ protected \ tests \ unit \ ProjectTest.php

I changed $ this-> projects ('project1') (from the book) to $ this-> projects ['project1'] because I can see in the forum post that projects are an array and not a method.

<?php

class ProjectTest extends CDbTestCase{

    public $fixture = array('projects'=>'Project');

    public function testRead(){
    // READ the new project
        $receivedProject = $this->projects['project1'];
        $this->assertTrue($receivedProject instanceof Project);
        $this->assertEquals($receivedProject->name,'Test Project 1');

    }

}

?>

      

my test config: C: \ wamp \ www \ agileBook \ protected \ config \ test.php

<?php

return CMap::mergeArray(
require(dirname(__FILE__).'/main.php'),
array(
    'components'=>array(
        'fixture'=>array(
            'class'=>'system.test.CDbFixtureManager',
        ),
        'db'=>array(
            'connectionString' => 'mysql:host=localhost;dbname=trackstar_test',
            'emulatePrepare' => true,
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
        ),
    ),
)
);

      

+3


source to share


2 answers


I found a bug ...

public $fixtures = array('projects'=>'Project'); 

      



Mounting requires "S"

Hope this helps someone

0


source


As mentioned, $ fixture needs to be fixed before $ fixtures.

I just wanted to comment on this:

I changed $ this-> projects ('project1') (from the book) to $ this-> projects ['project1'] because I can see in the forum post that projects are an array and not a method.



If you do this, the test above will fail. The reason is in the Yii documentation:

    // return all rows in the 'Comment' fixture table
    $comments = $this->comments; 
    // return the row whose alias is 'sample1' in the `Post` fixture table
    $post = $this->posts['sample1'];
    // return the AR instance representing the 'sample1' fixture data row
    $post = $this->posts('sample1');

      

http://www.yiiframework.com/doc/guide/1.1/en/test.unit

+1


source







All Articles