Yii Framework Forum: Unit test Fails - Yii Framework Forum

Jump to content

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

Unit test Fails Running ProjectTest.php fails with an empty users table

#1 User is offline   Hobbiest 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 13-January 12

Posted 31 January 2012 - 11:42 PM

Booted my computer up again today to get back into the book. I went to run all of my unit tests again, which past just last night (no code was changed or edited), and I have a failure. The failure is as follows:
1) ProjectTest::testGetUserOptions
Failed asserting that false is true.

/trackstar/protected/tests/unit/ProjectTest.php:69

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


The line it is pertaining too is the last assertTrue:

public function testGetUserOptions()
{
	$project = $this->projects('project1');
	$options = $project->userOptions;
	$this->assertTrue(is_array($options));
	$this->assertTrue(count($options) > 0);
}


So I started looking around. Low and behold when I query for all the records in my tbl_user from the trackstar_test database that is configured I get nothing. MySQL tells me the table is empty.

So I experimented, I added data to the table. Ran the unit test again. It fails. Table is empty again.

Now quoting from the Definitive Guide to Yii on this site

Quote

When CDbFixtureManager is referenced for the first time, it will go through every fixture file and use it to reset the corresponding table. It resets a table by truncating the table, resetting the sequence value for the table's auto-incremental primary key, and then inserting the rows of data from the fixture file into the table.


So this leads me to believe something is either wrong with my fixtures or Yii. Odd since they were working just last night and I have not changed them. However, I cannot find anything wrong with them.

My ProjectTest.php has the fixtures defined as:

	public $fixtures = array(
		'projects' => 'Project',
		'users' => 'User',
		'projUsrAssign' => ':tbl_project_user_assignment',
	);



I am either about to lose my mind or I have to blame Yii...

Anyone have any ideas? Let me know what info I can provide to help.
0

#2 User is offline   Jampire 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 10-January 11
  • Location:Gomel, Belarus

Posted 09 February 2012 - 02:50 AM

What is the content of protected/tests/fixtures/tbl_project.php file?
Posted Image
0

#3 User is offline   Hobbiest 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 13-January 12

Posted 09 February 2012 - 09:27 PM

View PostJampire, on 09 February 2012 - 02:50 AM, said:

What is the content of protected/tests/fixtures/tbl_project.php file?


Attached File  tbl_project.php (624bytes)
Number of downloads: 2
0

#4 User is offline   Jampire 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 10-January 11
  • Location:Gomel, Belarus

Posted 10 February 2012 - 03:27 AM

Also I need your protected/tests/fixtures/tbl_user.php and protected/models/Project.php files.
Posted Image
0

#5 User is offline   Hobbiest 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 13-January 12

Posted 10 February 2012 - 08:22 PM

View PostJampire, on 10 February 2012 - 03:27 AM, said:

Also I need your protected/tests/fixtures/tbl_user.php and protected/models/Project.php files.


Attached File  tbl_user.php (523bytes)
Number of downloads: 2

Attached File  Project.php (3.19K)
Number of downloads: 3
0

#6 User is offline   Hobbiest 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 13-January 12

Posted 11 February 2012 - 07:07 PM

I feel like a real idiot... Posted Image

Turns out I previously named my test fixture 'tbl_users' and not 'tbl_user' which is the database table name.
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