Yii Framework Forum: Model Findbyattributes Seems To Create A Row In Cdbtestcase - Yii Framework Forum

Jump to content

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

Model Findbyattributes Seems To Create A Row In Cdbtestcase Rate Topic: -----

#1 User is offline   Trixtur 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 08-May 13

Posted 08 May 2013 - 05:49 PM

I am writing a unit test, and I stumbled upon a very strange behavior.

I have a test fixture so I expect to see 1 row in the database (there is only 1 row listed in the fixture) I wrote some code to run a findByAttributes as follows:
$client_id = 6;
$unique = array (
    "client_id" => (String) $client_id,
    "id" => "2" //I have a fixture that uses id 1
);

$model = Agent::model()->findByAttributes($unique);
die();

When I have this configuration after my test runs and the die is hit, I see 2 rows in the database. However if I do:
$client_id = 6;
$unique = array (
    "client_id" => (String) $client_id,
    "id" => "2" //I have a fixture that uses id 1
);

die();
$model = Agent::model()->findByAttributes($unique);
//NOTE: I only moved the die() above the findByAttributes.

I see only the 1 row from my fixture. Why is findByAttributes creating a row in my test DB?

I noticed if I only supply the primary key no row is created. It is only when I supply a primary key and an additional value.
0

#2 User is offline   Fabrizio Caldarelli 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 687
  • Joined: 21-March 13
  • Location:Rome, Italy

Posted 08 May 2013 - 06:02 PM

How can you test code after die(), considering php exit after die().
0

#3 User is offline   Trixtur 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 08-May 13

Posted 08 May 2013 - 06:03 PM

View PostFabrizio Caldarelli, on 08 May 2013 - 06:02 PM, said:

How can you test code after die(), considering php exit after die().


I put the die() in so the code will exit and I can examine the test database.
0

#4 User is offline   Trixtur 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 08-May 13

Posted 08 May 2013 - 06:50 PM

The Agent model is a Singleton model in my code, it obviously is going to create one if one does not exist. Sorry for the dumb question.
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