0

私は単体テストを書いていますが、非常に奇妙な動作に遭遇しました。

私はテスト フィクスチャを持っているので、データベースに 1 行が表示されることを期待しています (フィクスチャには 1 行しか表示されません)。次のように、findByAttributes を実行するコードをいくつか書きました。

$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();

テストの実行後にこの構成があり、サイコロがヒットすると、データベースに 2 つの行が表示されます。しかし、もしそうなら:

$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.

フィクスチャから 1 行しか表示されません。テスト DB で findByAttributes が行を作成するのはなぜですか?

4

1 に答える 1

0

私のシステムでは、エージェントはシングルトン モデルです。何か派手なことをしていると思います。

シングルトンが存在しない場合は、明らかにシングルトンが作成されます。どっ!

于 2013-05-08T23:48:01.250 に答える