English 中文(简体)
在使用交响乐的Prop propel 进行单位测试时,如何在预期例外之后重设连接?
原标题:In a unit test using Propel in symfony, how can I reset the connection after an expected Exception

在1.4号交响曲中工作,为我的ORM(不确定如何找到Propel版本)。

在对数据库中具有独特限制的物体进行单位测试时,I测试是否捕获例外:

try {
  $room1a->save();
  // Shouldn t have saved, so shouldn t have an id
  $t->ok(!$room1a->getId(), "Failed to save duplicate room");
} catch (Exception $e) {
  $t->ok($e, "Threw exception on creating duplicate room");
}

如果我纠正了重复的重复,再试一次,

$room1a->setCode( 1a );
$room1a->save();
$t->ok($room1a->getId()), "Saved this time");

我得到"无法获得序列代号":

     PropelException: Unable to get sequence id. [wrapped:                
  SQLSTATE[25P02]: In failed sql transaction: 7 ERROR:  current        
  transaction is aborted, commands ignored until end of transaction    
  block]                                                               
  (in                                                                  
  lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel/util/BasePeer.php
  on line 264)  

我尝试过重塑对象(即一个新的房间对象)并保存它,结果相同;似乎在相关(?)方面有一个需要重塑的状态。

我找到的唯一办法 就是收回交易 开始新的交易

问题回答

我找到了答案:transactions 应该如何运作。

我在一次交易中包装我的单位测试脚本, 以免改变数据库, 我还没有意识到, 提出限制错误会中止交易 。

我有点烦恼,因为我不得不开始新的交易 并重新设置数据, 供随后的测试。





相关问题
To populate select options at backend using Symfony?

the symfony form is, nation =>new sfWidgetFormChoice(array( choices => NationPeer::getAllNation())), township =>new sfWidgetFormChoice(array( choices => TownshipPeer::...

Seriously speeding up PHP?

I ve been writing PHP for years, and have used every framework under the sun, but one thing has always bugged me... and that s that the whole bloody thing has to be interpreted and executed every time ...

How to unit-test an enterprise symfony project?

I´m working on a huge project at my work. We have about 200 database tables, accordingly a huge number of Models, Actions and so on. How should I begin to write tests for this? My biggest problem ...

edit profile from frontend - symfony

I succeeded to create a register form, and now users can register my site. But I can t create a form where users can edit their profile. I have sf_guard_user and sf_guard_user_profile in my schema....

热门标签