[2.0] Added ConnectionTest. Fixed sandbox.
This commit is contained in:
parent
4328a4e9e3
commit
a4913774c8
@ -683,10 +683,7 @@ class Connection
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a transaction or set a savepoint.
|
||||
*
|
||||
* if trying to set a savepoint and there is no active transaction
|
||||
* a new transaction is being started.
|
||||
* Start a transaction by suspending auto-commit mode.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -702,12 +699,11 @@ class Connection
|
||||
}
|
||||
|
||||
/**
|
||||
* Commits the database changes done during a transaction that is in
|
||||
* progress or release a savepoint. This function may only be called when
|
||||
* auto-committing is disabled, otherwise it will fail.
|
||||
* Commits the current transaction.
|
||||
*
|
||||
* @return void
|
||||
* @throws ConnectionException If the commit failed.
|
||||
* @throws ConnectionException If the commit failed due to no active transaction or
|
||||
* because the transaction was marked for rollback only.
|
||||
*/
|
||||
public function commit()
|
||||
{
|
||||
@ -736,7 +732,6 @@ class Connection
|
||||
* this method can be listened with onPreTransactionRollback and onTransactionRollback
|
||||
* eventlistener methods
|
||||
*
|
||||
* @param string $savepoint Name of a savepoint to rollback to.
|
||||
* @throws ConnectionException If the rollback operation fails at database level.
|
||||
*/
|
||||
public function rollback()
|
||||
@ -752,6 +747,7 @@ class Connection
|
||||
$this->_conn->rollback();
|
||||
$this->_isRollbackOnly = false;
|
||||
} else {
|
||||
$this->_isRollbackOnly = true;
|
||||
--$this->_transactionNestingLevel;
|
||||
}
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ final class ClassMetadata extends ClassMetadataInfo
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores some state that could not be serialized/unserialized.
|
||||
* Restores some state that can not be serialized/unserialized.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@ -24,6 +24,7 @@ class AllTests
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\SqliteSchemaManagerTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\MySqlSchemaManagerTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\PostgreSqlSchemaManagerTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\ConnectionTest');
|
||||
|
||||
return $suite;
|
||||
}
|
||||
|
64
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
Normal file
64
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional;
|
||||
|
||||
use Doctrine\DBAL\ConnectionException;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
|
||||
public function testTransactionNestingBehavior()
|
||||
{
|
||||
try {
|
||||
$this->_conn->beginTransaction();
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
|
||||
try {
|
||||
$this->_conn->beginTransaction();
|
||||
$this->assertEquals(2, $this->_conn->getTransactionNestingLevel());
|
||||
throw new \Exception;
|
||||
$this->_conn->commit(); // never reached
|
||||
} catch (\Exception $e) {
|
||||
$this->_conn->rollback();
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
//no rethrow
|
||||
}
|
||||
$this->assertTrue($this->_conn->getRollbackOnly());
|
||||
|
||||
$this->_conn->commit(); // should throw exception
|
||||
$this->fail('Transaction commit after failed nested transaction should fail.');
|
||||
} catch (ConnectionException $e) {
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
$this->_conn->rollback();
|
||||
$this->assertEquals(0, $this->_conn->getTransactionNestingLevel());
|
||||
}
|
||||
}
|
||||
|
||||
public function testTransactionBehavior()
|
||||
{
|
||||
try {
|
||||
$this->_conn->beginTransaction();
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
|
||||
throw new \Exception;
|
||||
|
||||
$this->_conn->commit(); // never reached
|
||||
} catch (\Exception $e) {
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
$this->_conn->rollback();
|
||||
$this->assertEquals(0, $this->_conn->getTransactionNestingLevel());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->_conn->beginTransaction();
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
$this->_conn->commit();
|
||||
} catch (\Exception $e) {
|
||||
$this->_conn->rollback();
|
||||
$this->assertEquals(0, $this->_conn->getTransactionNestingLevel());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Entities;
|
||||
|
||||
/** @Entity @Table(name="users", indexes={@Index(name="name_idx", columns={"name", "test"})}) */
|
||||
/** @Entity @Table(name="users") */
|
||||
class User {
|
||||
/**
|
||||
* @Id @Column(type="integer")
|
||||
@ -11,8 +11,6 @@ class User {
|
||||
private $id;
|
||||
/** @Column(type="string", length=50) */
|
||||
private $name;
|
||||
/** @Column(type="string", length=50) */
|
||||
private $test;
|
||||
/**
|
||||
* @OneToOne(targetEntity="Address")
|
||||
* @JoinColumn(name="address_id", referencedColumnName="id")
|
||||
|
Loading…
Reference in New Issue
Block a user