Yii Framework Forum: Get User Options Unit Tests Fail - Yii Framework Forum

Jump to content

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

Get User Options Unit Tests Fail

#1 User is offline   hlogi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 05-February 13

Posted 05 February 2013 - 02:34 PM

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?
0

#2 User is offline   yugene 

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

Posted 06 February 2013 - 03:27 AM

Always put attention to error message:

Quote

Failed asserting that 1 is true
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.

So just pass proper argument to assertion.
0

#3 User is offline   hlogi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 05-February 13

Posted 06 February 2013 - 06:20 AM

Got it, thanks! I was passing the wrong argument to assertion like you said.
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