Yii Framework Forum: CH13: SysMessageTest Failure. - Yii Framework Forum

Jump to content

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

CH13: SysMessageTest Failure. Fails on testing of SysMessage(Fixture not loading?)

#1 User is offline   Cliff 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 27-January 12
  • Location:Ontario, CANADA

Posted 12 May 2012 - 01:05 PM

I am on CH13 of the book specifically page: 326.
My SysMessageTest is failing:

Quote

There was 1 failure:

1) SysMessageTest::testGetLatest
Failed asserting that false is true.

trackstar\protected\tests\unit\SysMessageTest.php:12
phpunit:46

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.


My Code is as follows:

SysMessageTest.php
<?php

class SysMessageTest extends CDbTestCase
{
        public $fixtures=array(
            'messages'=>'SysMessage',
        );
        
        public function testGetLatest()
        {
            $message = SysMessage::getLatest();
            $this->assertTrue($message instanceof SysMessage);
        }
}


tbl_sys_message.php
<?php
return array(
    'message1'=>array(
        'message' => 'This is a test message',
        'create_time' => new CDbExpression('NOW()'),
        'create_user_id' => 1,
        'update_time' => new CDbExpression('NOW()'),
        'update_user_id' => 1,
    ),
);


GetLatest function in SysMessage AR Class
public static function getLatest()
        {
                //see if it is in the cache, if so, just return it
                if( ($cache=Yii::app()->cache)!==null)
                {
                    $key='TrackStar.ProjectListing.SystemMessage';
                    if(($sysMessage=$cache->get($key))!==false)
                        return $sysMessage;
                }
                
                //The system message was either not found in the cache, or
                //there is no cache component defined for the application
                //retrieve the system message from the database
                $sysMessage = SysMessage::model()->find(array(
                    'order'=>'t.update_time DESC',
                ));
                
                if($sysMessage != null)
                {
                    //a valid message was found. Store it in cache for future retrievals
                    if(isset($key))
                    $cache->set($key,$sysMessage,300);
                    return $sysMessage;
                }
                else
                    return null;
        }

0

#2 User is offline   Cliff 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 27-January 12
  • Location:Ontario, CANADA

Posted 12 May 2012 - 01:08 PM

Now I did get this test to pass by continuing on and generating the cache with the ProjectController::actionIndex call. However once I changed the cache location in the test.php configuration so the dev and test cache locations are different it would then again fail.
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