Skip to content

Commit

Permalink
Stop swallowing exceptions
Browse files Browse the repository at this point in the history
This was probably done in order to get rid of exceptions about tables
already existing, but may and does swallow other exceptions as well, for
instance exceptions about sequences failing to be created on Oracle
because the identifier is too long. This makes it unnecessarily hard to
understand what is going on.
  • Loading branch information
greg0ire committed Aug 28, 2021
1 parent a06bbaf commit 96b4c76
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 117 deletions.
23 changes: 13 additions & 10 deletions tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ class DefaultValuesTest extends OrmFunctionalTestCase
protected function setUp(): void
{
parent::setUp();
try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(DefaultValueUser::class),
$this->_em->getClassMetadata(DefaultValueAddress::class),
]
);
} catch (Exception $e) {
// Swallow all exceptions. We do not test the schema tool here.
}
$this->_schemaTool->createSchema([
$this->_em->getClassMetadata(DefaultValueUser::class),
$this->_em->getClassMetadata(DefaultValueAddress::class),
]);
}

protected function tearDown(): void
{
$this->_schemaTool->dropSchema([
$this->_em->getClassMetadata(DefaultValueUser::class),
$this->_em->getClassMetadata(DefaultValueAddress::class),
]);
parent::tearDown();
}

/**
Expand Down
38 changes: 22 additions & 16 deletions tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,31 @@
use function count;
use function current;
use function get_class;
use function iterator_to_array;
use function sprintf;

class LifecycleCallbackTest extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(LifecycleCallbackEventArgEntity::class),
$this->_em->getClassMetadata(LifecycleCallbackTestEntity::class),
$this->_em->getClassMetadata(LifecycleCallbackTestUser::class),
$this->_em->getClassMetadata(LifecycleCallbackCascader::class),
]
);
} catch (Exception $e) {
// Swallow all exceptions. We do not test the schema tool here.
}
$this->_schemaTool->createSchema([
$this->_em->getClassMetadata(LifecycleCallbackEventArgEntity::class),
$this->_em->getClassMetadata(LifecycleCallbackTestEntity::class),
$this->_em->getClassMetadata(LifecycleCallbackTestUser::class),
$this->_em->getClassMetadata(LifecycleCallbackCascader::class),
]);
}

protected function tearDown(): void
{
$this->_schemaTool->dropSchema([
$this->_em->getClassMetadata(LifecycleCallbackEventArgEntity::class),
$this->_em->getClassMetadata(LifecycleCallbackTestEntity::class),
$this->_em->getClassMetadata(LifecycleCallbackTestUser::class),
$this->_em->getClassMetadata(LifecycleCallbackCascader::class),
]);
parent::tearDown();
}

public function testPreSavePostSaveCallbacksAreInvoked(): void
Expand Down Expand Up @@ -261,7 +267,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIteration(): void

$query = $this->_em->createQuery(sprintf($dql, $e1->getId(), $e2->getId()));

$result = $query->iterate();
$result = iterator_to_array($query->iterate());

foreach ($result as $entity) {
self::assertTrue($entity[0]->postLoadCallbackInvoked);
Expand All @@ -270,7 +276,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIteration(): void
break;
}

$iterableResult = $query->toIterable();
$iterableResult = iterator_to_array($query->toIterable());

foreach ($iterableResult as $entity) {
self::assertTrue($entity->postLoadCallbackInvoked);
Expand All @@ -296,7 +302,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIterationWithSimple
'SELECT e FROM Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity AS e'
);

$result = $query->iterate(null, Query::HYDRATE_SIMPLEOBJECT);
$result = iterator_to_array($query->iterate(null, Query::HYDRATE_SIMPLEOBJECT));

foreach ($result as $entity) {
self::assertTrue($entity[0]->postLoadCallbackInvoked);
Expand All @@ -305,7 +311,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIterationWithSimple
break;
}

$result = $query->toIterable([], Query::HYDRATE_SIMPLEOBJECT);
$result = iterator_to_array($query->toIterable([], Query::HYDRATE_SIMPLEOBJECT));

foreach ($result as $entity) {
self::assertTrue($entity->postLoadCallbackInvoked);
Expand Down
55 changes: 42 additions & 13 deletions tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Tests\ORM\Functional\Locking;

use DateTime;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
Expand All @@ -24,28 +25,38 @@

class OptimisticTest extends OrmFunctionalTestCase
{
/** @var Connection */
private $_conn;

protected function setUp(): void
{
parent::setUp();
$this->_conn = $this->_em->getConnection();
}

try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(OptimisticJoinedParent::class),
$this->_em->getClassMetadata(OptimisticJoinedChild::class),
$this->_em->getClassMetadata(OptimisticStandard::class),
$this->_em->getClassMetadata(OptimisticTimestamp::class),
]
);
} catch (Exception $e) {
// Swallow all exceptions. We do not test the schema tool here.
}
private function createSchema(): void
{
$this->_schemaTool->createSchema([
$this->_em->getClassMetadata(OptimisticJoinedParent::class),
$this->_em->getClassMetadata(OptimisticJoinedChild::class),
$this->_em->getClassMetadata(OptimisticStandard::class),
$this->_em->getClassMetadata(OptimisticTimestamp::class),
]);
}

$this->_conn = $this->_em->getConnection();
private function dropSchema(): void
{
$this->_schemaTool->dropSchema([
$this->_em->getClassMetadata(OptimisticJoinedParent::class),
$this->_em->getClassMetadata(OptimisticJoinedChild::class),
$this->_em->getClassMetadata(OptimisticStandard::class),
$this->_em->getClassMetadata(OptimisticTimestamp::class),
]);
}

public function testJoinedChildInsertSetsInitialVersionValue(): OptimisticJoinedChild
{
$this->createSchema();
$test = new OptimisticJoinedChild();

$test->name = 'child';
Expand Down Expand Up @@ -83,10 +94,13 @@ public function testJoinedChildFailureThrowsException(OptimisticJoinedChild $chi
} catch (OptimisticLockException $e) {
self::assertSame($test, $e->getEntity());
}

$this->dropSchema();
}

public function testJoinedParentInsertSetsInitialVersionValue(): OptimisticJoinedParent
{
$this->createSchema();
$test = new OptimisticJoinedParent();

$test->name = 'parent';
Expand Down Expand Up @@ -123,10 +137,14 @@ public function testJoinedParentFailureThrowsException(OptimisticJoinedParent $p
} catch (OptimisticLockException $e) {
self::assertSame($test, $e->getEntity());
}

$this->dropSchema();
}

public function testMultipleFlushesDoIncrementalUpdates(): void
{
$this->createSchema();

$test = new OptimisticStandard();

for ($i = 0; $i < 5; $i++) {
Expand All @@ -138,10 +156,14 @@ public function testMultipleFlushesDoIncrementalUpdates(): void
self::assertIsInt($test->getVersion());
self::assertEquals($i + 1, $test->getVersion());
}

$this->dropSchema();
}

public function testStandardInsertSetsInitialVersionValue(): OptimisticStandard
{
$this->createSchema();

$test = new OptimisticStandard();

$test->name = 'test';
Expand Down Expand Up @@ -179,10 +201,13 @@ public function testStandardFailureThrowsException(OptimisticStandard $entity):
} catch (OptimisticLockException $e) {
self::assertSame($test, $e->getEntity());
}

$this->dropSchema();
}

public function testLockWorksWithProxy(): void
{
$this->createSchema();
$test = new OptimisticStandard();
$test->name = 'test';

Expand All @@ -195,10 +220,12 @@ public function testLockWorksWithProxy(): void
$this->_em->lock($proxy, LockMode::OPTIMISTIC, 1);

$this->addToAssertionCount(1);
$this->dropSchema();
}

public function testOptimisticTimestampSetsDefaultValue(): OptimisticTimestamp
{
$this->createSchema();
$test = new OptimisticTimestamp();

$test->name = 'Testing';
Expand Down Expand Up @@ -274,6 +301,8 @@ public function testOptimisticTimestampLockFailureThrowsException(OptimisticTime

self::assertNotNull($caughtException, 'No OptimisticLockingException was thrown');
self::assertSame($test, $caughtException->getEntity());

$this->dropSchema();
}
}

Expand Down
14 changes: 4 additions & 10 deletions tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,10 @@ protected function setUp(): void

$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8383');

try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(NotifyUser::class),
$this->_em->getClassMetadata(NotifyGroup::class),
]
);
} catch (Exception $e) {
// Swallow all exceptions. We do not test the schema tool here.
}
$this->_schemaTool->createSchema([
$this->_em->getClassMetadata(NotifyUser::class),
$this->_em->getClassMetadata(NotifyGroup::class),
]);
}

public function testChangeTracking(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,9 @@ public function testLazyLoadsAssociation(): void

public function testMultiSelfReference(): void
{
try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(MultiSelfReference::class),
]
);
} catch (Exception $e) {
// Swallow all exceptions. We do not test the schema tool here.
}
$this->_schemaTool->createSchema([
$this->_em->getClassMetadata(MultiSelfReference::class),
]);

$entity1 = new MultiSelfReference();
$this->_em->persist($entity1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,11 @@ class OrderedJoinedTableInheritanceCollectionTest extends OrmFunctionalTestCase
protected function setUp(): void
{
parent::setUp();
try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(OJTICPet::class),
$this->_em->getClassMetadata(OJTICCat::class),
$this->_em->getClassMetadata(OJTICDog::class),
]
);
} catch (Exception $e) {
// Swallow all exceptions. We do not test the schema tool here.
}
$this->_schemaTool->createSchema([
$this->_em->getClassMetadata(OJTICPet::class),
$this->_em->getClassMetadata(OJTICCat::class),
$this->_em->getClassMetadata(OJTICDog::class),
]);

$dog = new OJTICDog();
$dog->name = 'Poofy';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ protected function setUp(): void
'This test is special to platforms emulating IDENTITY key generation strategy through sequences.'
);
} else {
try {
$this->_schemaTool->createSchema(
[$this->_em->getClassMetadata(SequenceEmulatedIdentityEntity::class)]
);
} catch (Exception $e) {
// Swallow all exceptions. We do not test the schema tool here.
}
$this->_schemaTool->createSchema(
[$this->_em->getClassMetadata(SequenceEmulatedIdentityEntity::class)]
);
}
}

Expand Down
14 changes: 4 additions & 10 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@ class DDC1690Test extends OrmFunctionalTestCase
protected function setUp(): void
{
parent::setUp();
try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(DDC1690Parent::class),
$this->_em->getClassMetadata(DDC1690Child::class),
]
);
} catch (Exception $e) {
// Swallow all exceptions. We do not test the schema tool here.
}
$this->_schemaTool->createSchema([
$this->_em->getClassMetadata(DDC1690Parent::class),
$this->_em->getClassMetadata(DDC1690Child::class),
]);
}

public function testChangeTracking(): void
Expand Down
14 changes: 4 additions & 10 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@ class DDC440Test extends OrmFunctionalTestCase
protected function setUp(): void
{
parent::setUp();
try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(DDC440Phone::class),
$this->_em->getClassMetadata(DDC440Client::class),
]
);
} catch (Exception $e) {
// Swallow all exceptions. We do not test the schema tool here.
}
$this->_schemaTool->createSchema([
$this->_em->getClassMetadata(DDC440Phone::class),
$this->_em->getClassMetadata(DDC440Client::class),
]);
}

/**
Expand Down
Loading

0 comments on commit 96b4c76

Please sign in to comment.