Skip to content

Commit

Permalink
fix tear down of some test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
deeky666 committed Sep 10, 2015
1 parent a46556f commit c5b7757
Showing 1 changed file with 49 additions and 25 deletions.
74 changes: 49 additions & 25 deletions tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,20 @@ public function testForeignKeyConstraintViolationExceptionOnInsert()

$this->setUpForeignKeyConstraintViolationExceptionTest();

$this->_conn->insert("constraint_error_table", array('id' => 1));
$this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1));
try {
$this->_conn->insert("constraint_error_table", array('id' => 1));
$this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1));

$this->setExpectedException('\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException');
$this->setExpectedException('\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException');

try {
$this->_conn->insert('owning_table', array('id' => 2, 'constraint_id' => 2));
} catch (ForeignKeyConstraintViolationException $exception) {
try {
$this->_conn->insert('owning_table', array('id' => 2, 'constraint_id' => 2));
} catch (ForeignKeyConstraintViolationException $exception) {
$this->tearDownForeignKeyConstraintViolationExceptionTest();

throw $exception;
}
} catch (\Exception $exception) {
$this->tearDownForeignKeyConstraintViolationExceptionTest();

throw $exception;
Expand All @@ -88,14 +94,20 @@ public function testForeignKeyConstraintViolationExceptionOnUpdate()

$this->setUpForeignKeyConstraintViolationExceptionTest();

$this->_conn->insert("constraint_error_table", array('id' => 1));
$this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1));
try {
$this->_conn->insert("constraint_error_table", array('id' => 1));
$this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1));

$this->setExpectedException('\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException');
$this->setExpectedException('\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException');

try {
$this->_conn->update('constraint_error_table', array('id' => 2), array('id' => 1));
} catch (ForeignKeyConstraintViolationException $exception) {
try {
$this->_conn->update('constraint_error_table', array('id' => 2), array('id' => 1));
} catch (ForeignKeyConstraintViolationException $exception) {
$this->tearDownForeignKeyConstraintViolationExceptionTest();

throw $exception;
}
} catch (\Exception $exception) {
$this->tearDownForeignKeyConstraintViolationExceptionTest();

throw $exception;
Expand All @@ -112,14 +124,20 @@ public function testForeignKeyConstraintViolationExceptionOnDelete()

$this->setUpForeignKeyConstraintViolationExceptionTest();

$this->_conn->insert("constraint_error_table", array('id' => 1));
$this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1));
try {
$this->_conn->insert("constraint_error_table", array('id' => 1));
$this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1));

$this->setExpectedException('\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException');
$this->setExpectedException('\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException');

try {
$this->_conn->delete('constraint_error_table', array('id' => 1));
} catch (ForeignKeyConstraintViolationException $exception) {
try {
$this->_conn->delete('constraint_error_table', array('id' => 1));
} catch (ForeignKeyConstraintViolationException $exception) {
$this->tearDownForeignKeyConstraintViolationExceptionTest();

throw $exception;
}
} catch (\Exception $exception) {
$this->tearDownForeignKeyConstraintViolationExceptionTest();

throw $exception;
Expand All @@ -132,20 +150,26 @@ public function testForeignKeyConstraintViolationExceptionOnTruncate()
{
$platform = $this->_conn->getDatabasePlatform();

if ( ! $platform->supportsForeignKeyConstraints()) {
if (!$platform->supportsForeignKeyConstraints()) {
$this->markTestSkipped("Only fails on platforms with foreign key constraints.");
}

$this->setUpForeignKeyConstraintViolationExceptionTest();

$this->_conn->insert("constraint_error_table", array('id' => 1));
$this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1));
try {
$this->_conn->insert("constraint_error_table", array('id' => 1));
$this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1));

$this->setExpectedException('\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException');
$this->setExpectedException('\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException');

try {
$this->_conn->executeUpdate($platform->getTruncateTableSQL('constraint_error_table'));
} catch (ForeignKeyConstraintViolationException $exception) {
try {
$this->_conn->executeUpdate($platform->getTruncateTableSQL('constraint_error_table'));
} catch (ForeignKeyConstraintViolationException $exception) {
$this->tearDownForeignKeyConstraintViolationExceptionTest();

throw $exception;
}
} catch (\Exception $exception) {
$this->tearDownForeignKeyConstraintViolationExceptionTest();

throw $exception;
Expand Down

0 comments on commit c5b7757

Please sign in to comment.