Get User Options Unit Tests Fail

Hi, I am following Agile Web Application Development with Yii 1.1 and PHP5. On page 126 where i run the Unit tests for ‘tbl_user’ and ‘tbl_project_user_assignment’, I encounter the following error:

Failed asserting that 1 is true

trackstar\protected\tests\unit\ProjectTest.php:67

FAILURES!

Tests: 5, Assertions: 12, Failures: 1.

the function is as follows:




public function testGetUserOptions()

    {

        $project = $this->projects('project2');

        $options = $project->userOptions;

        $this->assertTrue(is_array($options));

        $this->assertTrue(count($options > 0));

    }



i believe the failure occurs with the line


$this->assertTrue(count($options > 0));

since all tests pass when i remove it.

the function being tested is as follows:




        public function getUserOptions()

        {

            $usersArray = CHtml::listData($this->users, 'id', 'username');

            return $usersArray;

        }



Can anyone help?

Always put attention to error message:

Try this:





        $options = array(1, 2, 3, 4, 5);

        var_dump(count($options > 0));

        var_dump($options > 0);

        var_dump(true === 1);

in any php script to see output.

[size="2"]So just pass proper argument to assertion.[/size]

Got it, thanks! I was passing the wrong argument to assertion like you said.