[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/active_record/tests/cases/ -> lmbARTransactionTest.class.php (source)

   1  <?php
   2  /*

   3   * Limb PHP Framework

   4   *

   5   * @link http://limb-project.com

   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)

   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html

   8   */
   9  lmb_require('limb/active_record/src/lmbActiveRecord.class.php');
  10  lmb_require('limb/dbal/src/lmbSimpleDb.class.php');
  11  require_once(dirname(__FILE__) . '/lmbActiveRecordTest.class.php');//need TestOneTableObjectFailing

  12  
  13  class lmbARTransactionTest extends UnitTestCase
  14  {
  15    function setUp()
  16    {
  17      $this->conn = lmbToolkit :: instance()->getDefaultDbConnection();
  18      $this->db = new lmbSimpleDb($this->conn);
  19  
  20      $this->_cleanUp();
  21    }
  22  
  23    function tearDown()
  24    {
  25      $this->_cleanUp();
  26    }
  27  
  28    function _cleanUp()
  29    {
  30      $this->db->delete('test_one_table_object');
  31    }
  32  
  33    function  testSaveInTransaction()
  34    {
  35      $this->conn->beginTransaction();
  36  
  37      $obj = new TestOneTableObjectFailing();
  38      $obj->setContent('hey');
  39  
  40      $this->assertTrue($obj->trySave());
  41  
  42      $this->conn->commitTransaction();
  43  
  44      $this->assertEqual($this->db->count('test_one_table_object'), 1);
  45    }
  46  
  47    function  testSaveRollbacksTransaction()
  48    {
  49      $this->conn->beginTransaction();
  50  
  51      $obj = new TestOneTableObjectFailing();
  52      $obj->setContent('hey');
  53      $obj->fail = new Exception('whatever');
  54  
  55      $this->assertFalse($obj->trySave());
  56  
  57      $this->conn->commitTransaction();
  58  
  59      $this->assertEqual($this->db->count('test_one_table_object'), 0);
  60    }
  61  }
  62  ?>


Generated: Fri Aug 29 04:49:26 2008 Cross-referenced by PHPXref 0.7