Commit a4913774 authored by romanb's avatar romanb

[2.0] Added ConnectionTest. Fixed sandbox.

parent 4328a4e9
...@@ -683,10 +683,7 @@ class Connection ...@@ -683,10 +683,7 @@ class Connection
} }
/** /**
* Start a transaction or set a savepoint. * Start a transaction by suspending auto-commit mode.
*
* if trying to set a savepoint and there is no active transaction
* a new transaction is being started.
* *
* @return void * @return void
*/ */
...@@ -702,12 +699,11 @@ class Connection ...@@ -702,12 +699,11 @@ class Connection
} }
/** /**
* Commits the database changes done during a transaction that is in * Commits the current transaction.
* progress or release a savepoint. This function may only be called when
* auto-committing is disabled, otherwise it will fail.
* *
* @return void * @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() public function commit()
{ {
...@@ -736,7 +732,6 @@ class Connection ...@@ -736,7 +732,6 @@ class Connection
* this method can be listened with onPreTransactionRollback and onTransactionRollback * this method can be listened with onPreTransactionRollback and onTransactionRollback
* eventlistener methods * eventlistener methods
* *
* @param string $savepoint Name of a savepoint to rollback to.
* @throws ConnectionException If the rollback operation fails at database level. * @throws ConnectionException If the rollback operation fails at database level.
*/ */
public function rollback() public function rollback()
...@@ -752,6 +747,7 @@ class Connection ...@@ -752,6 +747,7 @@ class Connection
$this->_conn->rollback(); $this->_conn->rollback();
$this->_isRollbackOnly = false; $this->_isRollbackOnly = false;
} else { } else {
$this->_isRollbackOnly = true;
--$this->_transactionNestingLevel; --$this->_transactionNestingLevel;
} }
} }
......
...@@ -341,7 +341,7 @@ final class ClassMetadata extends ClassMetadataInfo ...@@ -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 * @return void
*/ */
......
...@@ -24,6 +24,7 @@ class AllTests ...@@ -24,6 +24,7 @@ class AllTests
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\SqliteSchemaManagerTest'); $suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\SqliteSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\MySqlSchemaManagerTest'); $suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\MySqlSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\PostgreSqlSchemaManagerTest'); $suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\PostgreSqlSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\ConnectionTest');
return $suite; return $suite;
} }
......
<?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());
}
}
}
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace Entities; namespace Entities;
/** @Entity @Table(name="users", indexes={@Index(name="name_idx", columns={"name", "test"})}) */ /** @Entity @Table(name="users") */
class User { class User {
/** /**
* @Id @Column(type="integer") * @Id @Column(type="integer")
...@@ -11,8 +11,6 @@ class User { ...@@ -11,8 +11,6 @@ class User {
private $id; private $id;
/** @Column(type="string", length=50) */ /** @Column(type="string", length=50) */
private $name; private $name;
/** @Column(type="string", length=50) */
private $test;
/** /**
* @OneToOne(targetEntity="Address") * @OneToOne(targetEntity="Address")
* @JoinColumn(name="address_id", referencedColumnName="id") * @JoinColumn(name="address_id", referencedColumnName="id")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment