0

I´m following the manual 'Agile Web Application Develpment with Yii1.1 and PHP5', and I don´t know, why do the test CRUD is failed,

It was created correctly 'Entity AR class' from Gii after tested correctly 'db connection' also (Chapter 4) but at the moment to create testCRUD the output return is a false assertionm, like this:

OK (1 test, 0 assertions)

Just there is one step that I din´t followed in the manual, and was create CDbConnection class, cause testsConnection was ok. And besides, I check all changes class Test and main.php file and was ok.

EntityTest.php

class EntityTest extends CDbTestCase
{   
    public function testCRUD()
    {
    }
}

Entity.php

    public function testCRUD()
    {
    $newEntity=new Entity;
    $newEntity->setAttributes(
        array(
                'name' => 'Test Entity 1',
                'description' => 'Test entity number one',
                'type_id' => 1,
                'location_lat' => 77,
                'location_lon' => 77,
                'create_time' => '2013-02-16 20:36:00',
                'create_user_id' => 1,
                'update_time' => '0000-00-00 00:00:00',
                'update_user_id' => 0,
            )
    );
    $this->assertTrue($newEntity->save(false));

    $retrievedEntity=Entity::model()->findByPk(1);
    $this->assertTrue($retrievedEntity instanceof Entity);
    $this->assertEquals('Salva la Prospe',$retrievedProject->name);
}           

Cheers.

1 Answers1

1

The test runs methods in its own class, it does not call test methods in the object it is testing.

This explains why it says 0 assertions. Your test is just an empty method.

Simply move all your testCRUD code from the Entity.php file to the EntityTest.php file and it should work.

Willem Renzema
  • 5,177
  • 1
  • 17
  • 24
  • Thanks Renzema, it was such as you said. I don´t know, what was he thinking? Difficult to belive but I thought that in Test class was not possible to use directly CRUD operations with which handle the information data. It has been a very useful answer. – Salvatore Roncone Feb 18 '13 at 21:50