Skip to content

Commit d5f65ba

Browse files
authored
Merge pull request #8962 from greg0ire/dont-swallow-exceptions
Stop swallowing exceptions
2 parents ef9c984 + 96b4c76 commit d5f65ba

11 files changed

+138
-117
lines changed

tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ class DefaultValuesTest extends OrmFunctionalTestCase
2424
protected function setUp(): void
2525
{
2626
parent::setUp();
27-
try {
28-
$this->_schemaTool->createSchema(
29-
[
30-
$this->_em->getClassMetadata(DefaultValueUser::class),
31-
$this->_em->getClassMetadata(DefaultValueAddress::class),
32-
]
33-
);
34-
} catch (Exception $e) {
35-
// Swallow all exceptions. We do not test the schema tool here.
36-
}
27+
$this->_schemaTool->createSchema([
28+
$this->_em->getClassMetadata(DefaultValueUser::class),
29+
$this->_em->getClassMetadata(DefaultValueAddress::class),
30+
]);
31+
}
32+
33+
protected function tearDown(): void
34+
{
35+
$this->_schemaTool->dropSchema([
36+
$this->_em->getClassMetadata(DefaultValueUser::class),
37+
$this->_em->getClassMetadata(DefaultValueAddress::class),
38+
]);
39+
parent::tearDown();
3740
}
3841

3942
/**

tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php

+22-16
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,31 @@
3434
use function count;
3535
use function current;
3636
use function get_class;
37+
use function iterator_to_array;
3738
use function sprintf;
3839

3940
class LifecycleCallbackTest extends OrmFunctionalTestCase
4041
{
4142
protected function setUp(): void
4243
{
4344
parent::setUp();
44-
try {
45-
$this->_schemaTool->createSchema(
46-
[
47-
$this->_em->getClassMetadata(LifecycleCallbackEventArgEntity::class),
48-
$this->_em->getClassMetadata(LifecycleCallbackTestEntity::class),
49-
$this->_em->getClassMetadata(LifecycleCallbackTestUser::class),
50-
$this->_em->getClassMetadata(LifecycleCallbackCascader::class),
51-
]
52-
);
53-
} catch (Exception $e) {
54-
// Swallow all exceptions. We do not test the schema tool here.
55-
}
45+
$this->_schemaTool->createSchema([
46+
$this->_em->getClassMetadata(LifecycleCallbackEventArgEntity::class),
47+
$this->_em->getClassMetadata(LifecycleCallbackTestEntity::class),
48+
$this->_em->getClassMetadata(LifecycleCallbackTestUser::class),
49+
$this->_em->getClassMetadata(LifecycleCallbackCascader::class),
50+
]);
51+
}
52+
53+
protected function tearDown(): void
54+
{
55+
$this->_schemaTool->dropSchema([
56+
$this->_em->getClassMetadata(LifecycleCallbackEventArgEntity::class),
57+
$this->_em->getClassMetadata(LifecycleCallbackTestEntity::class),
58+
$this->_em->getClassMetadata(LifecycleCallbackTestUser::class),
59+
$this->_em->getClassMetadata(LifecycleCallbackCascader::class),
60+
]);
61+
parent::tearDown();
5662
}
5763

5864
public function testPreSavePostSaveCallbacksAreInvoked(): void
@@ -261,7 +267,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIteration(): void
261267

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

264-
$result = $query->iterate();
270+
$result = iterator_to_array($query->iterate());
265271

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

273-
$iterableResult = $query->toIterable();
279+
$iterableResult = iterator_to_array($query->toIterable());
274280

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

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

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

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

310316
foreach ($result as $entity) {
311317
self::assertTrue($entity->postLoadCallbackInvoked);

tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php

+42-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\Tests\ORM\Functional\Locking;
66

77
use DateTime;
8+
use Doctrine\DBAL\Connection;
89
use Doctrine\DBAL\LockMode;
910
use Doctrine\ORM\Mapping\Column;
1011
use Doctrine\ORM\Mapping\DiscriminatorColumn;
@@ -24,28 +25,38 @@
2425

2526
class OptimisticTest extends OrmFunctionalTestCase
2627
{
28+
/** @var Connection */
29+
private $_conn;
30+
2731
protected function setUp(): void
2832
{
2933
parent::setUp();
34+
$this->_conn = $this->_em->getConnection();
35+
}
3036

31-
try {
32-
$this->_schemaTool->createSchema(
33-
[
34-
$this->_em->getClassMetadata(OptimisticJoinedParent::class),
35-
$this->_em->getClassMetadata(OptimisticJoinedChild::class),
36-
$this->_em->getClassMetadata(OptimisticStandard::class),
37-
$this->_em->getClassMetadata(OptimisticTimestamp::class),
38-
]
39-
);
40-
} catch (Exception $e) {
41-
// Swallow all exceptions. We do not test the schema tool here.
42-
}
37+
private function createSchema(): void
38+
{
39+
$this->_schemaTool->createSchema([
40+
$this->_em->getClassMetadata(OptimisticJoinedParent::class),
41+
$this->_em->getClassMetadata(OptimisticJoinedChild::class),
42+
$this->_em->getClassMetadata(OptimisticStandard::class),
43+
$this->_em->getClassMetadata(OptimisticTimestamp::class),
44+
]);
45+
}
4346

44-
$this->_conn = $this->_em->getConnection();
47+
private function dropSchema(): void
48+
{
49+
$this->_schemaTool->dropSchema([
50+
$this->_em->getClassMetadata(OptimisticJoinedParent::class),
51+
$this->_em->getClassMetadata(OptimisticJoinedChild::class),
52+
$this->_em->getClassMetadata(OptimisticStandard::class),
53+
$this->_em->getClassMetadata(OptimisticTimestamp::class),
54+
]);
4555
}
4656

4757
public function testJoinedChildInsertSetsInitialVersionValue(): OptimisticJoinedChild
4858
{
59+
$this->createSchema();
4960
$test = new OptimisticJoinedChild();
5061

5162
$test->name = 'child';
@@ -83,10 +94,13 @@ public function testJoinedChildFailureThrowsException(OptimisticJoinedChild $chi
8394
} catch (OptimisticLockException $e) {
8495
self::assertSame($test, $e->getEntity());
8596
}
97+
98+
$this->dropSchema();
8699
}
87100

88101
public function testJoinedParentInsertSetsInitialVersionValue(): OptimisticJoinedParent
89102
{
103+
$this->createSchema();
90104
$test = new OptimisticJoinedParent();
91105

92106
$test->name = 'parent';
@@ -123,10 +137,14 @@ public function testJoinedParentFailureThrowsException(OptimisticJoinedParent $p
123137
} catch (OptimisticLockException $e) {
124138
self::assertSame($test, $e->getEntity());
125139
}
140+
141+
$this->dropSchema();
126142
}
127143

128144
public function testMultipleFlushesDoIncrementalUpdates(): void
129145
{
146+
$this->createSchema();
147+
130148
$test = new OptimisticStandard();
131149

132150
for ($i = 0; $i < 5; $i++) {
@@ -138,10 +156,14 @@ public function testMultipleFlushesDoIncrementalUpdates(): void
138156
self::assertIsInt($test->getVersion());
139157
self::assertEquals($i + 1, $test->getVersion());
140158
}
159+
160+
$this->dropSchema();
141161
}
142162

143163
public function testStandardInsertSetsInitialVersionValue(): OptimisticStandard
144164
{
165+
$this->createSchema();
166+
145167
$test = new OptimisticStandard();
146168

147169
$test->name = 'test';
@@ -179,10 +201,13 @@ public function testStandardFailureThrowsException(OptimisticStandard $entity):
179201
} catch (OptimisticLockException $e) {
180202
self::assertSame($test, $e->getEntity());
181203
}
204+
205+
$this->dropSchema();
182206
}
183207

184208
public function testLockWorksWithProxy(): void
185209
{
210+
$this->createSchema();
186211
$test = new OptimisticStandard();
187212
$test->name = 'test';
188213

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

197222
$this->addToAssertionCount(1);
223+
$this->dropSchema();
198224
}
199225

200226
public function testOptimisticTimestampSetsDefaultValue(): OptimisticTimestamp
201227
{
228+
$this->createSchema();
202229
$test = new OptimisticTimestamp();
203230

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

275302
self::assertNotNull($caughtException, 'No OptimisticLockingException was thrown');
276303
self::assertSame($test, $caughtException->getEntity());
304+
305+
$this->dropSchema();
277306
}
278307
}
279308

tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,10 @@ protected function setUp(): void
3333

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

36-
try {
37-
$this->_schemaTool->createSchema(
38-
[
39-
$this->_em->getClassMetadata(NotifyUser::class),
40-
$this->_em->getClassMetadata(NotifyGroup::class),
41-
]
42-
);
43-
} catch (Exception $e) {
44-
// Swallow all exceptions. We do not test the schema tool here.
45-
}
36+
$this->_schemaTool->createSchema([
37+
$this->_em->getClassMetadata(NotifyUser::class),
38+
$this->_em->getClassMetadata(NotifyGroup::class),
39+
]);
4640
}
4741

4842
public function testChangeTracking(): void

tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,9 @@ public function testLazyLoadsAssociation(): void
9999

100100
public function testMultiSelfReference(): void
101101
{
102-
try {
103-
$this->_schemaTool->createSchema(
104-
[
105-
$this->_em->getClassMetadata(MultiSelfReference::class),
106-
]
107-
);
108-
} catch (Exception $e) {
109-
// Swallow all exceptions. We do not test the schema tool here.
110-
}
102+
$this->_schemaTool->createSchema([
103+
$this->_em->getClassMetadata(MultiSelfReference::class),
104+
]);
111105

112106
$entity1 = new MultiSelfReference();
113107
$this->_em->persist($entity1);

tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php

+5-11
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,11 @@ class OrderedJoinedTableInheritanceCollectionTest extends OrmFunctionalTestCase
3030
protected function setUp(): void
3131
{
3232
parent::setUp();
33-
try {
34-
$this->_schemaTool->createSchema(
35-
[
36-
$this->_em->getClassMetadata(OJTICPet::class),
37-
$this->_em->getClassMetadata(OJTICCat::class),
38-
$this->_em->getClassMetadata(OJTICDog::class),
39-
]
40-
);
41-
} catch (Exception $e) {
42-
// Swallow all exceptions. We do not test the schema tool here.
43-
}
33+
$this->_schemaTool->createSchema([
34+
$this->_em->getClassMetadata(OJTICPet::class),
35+
$this->_em->getClassMetadata(OJTICCat::class),
36+
$this->_em->getClassMetadata(OJTICDog::class),
37+
]);
4438

4539
$dog = new OJTICDog();
4640
$dog->name = 'Poofy';

tests/Doctrine/Tests/ORM/Functional/SequenceEmulatedIdentityStrategyTest.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@ protected function setUp(): void
2626
'This test is special to platforms emulating IDENTITY key generation strategy through sequences.'
2727
);
2828
} else {
29-
try {
30-
$this->_schemaTool->createSchema(
31-
[$this->_em->getClassMetadata(SequenceEmulatedIdentityEntity::class)]
32-
);
33-
} catch (Exception $e) {
34-
// Swallow all exceptions. We do not test the schema tool here.
35-
}
29+
$this->_schemaTool->createSchema(
30+
[$this->_em->getClassMetadata(SequenceEmulatedIdentityEntity::class)]
31+
);
3632
}
3733
}
3834

tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,10 @@ class DDC1690Test extends OrmFunctionalTestCase
2424
protected function setUp(): void
2525
{
2626
parent::setUp();
27-
try {
28-
$this->_schemaTool->createSchema(
29-
[
30-
$this->_em->getClassMetadata(DDC1690Parent::class),
31-
$this->_em->getClassMetadata(DDC1690Child::class),
32-
]
33-
);
34-
} catch (Exception $e) {
35-
// Swallow all exceptions. We do not test the schema tool here.
36-
}
27+
$this->_schemaTool->createSchema([
28+
$this->_em->getClassMetadata(DDC1690Parent::class),
29+
$this->_em->getClassMetadata(DDC1690Child::class),
30+
]);
3731
}
3832

3933
public function testChangeTracking(): void

tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,10 @@ class DDC440Test extends OrmFunctionalTestCase
2424
protected function setUp(): void
2525
{
2626
parent::setUp();
27-
try {
28-
$this->_schemaTool->createSchema(
29-
[
30-
$this->_em->getClassMetadata(DDC440Phone::class),
31-
$this->_em->getClassMetadata(DDC440Client::class),
32-
]
33-
);
34-
} catch (Exception $e) {
35-
// Swallow all exceptions. We do not test the schema tool here.
36-
}
27+
$this->_schemaTool->createSchema([
28+
$this->_em->getClassMetadata(DDC440Phone::class),
29+
$this->_em->getClassMetadata(DDC440Client::class),
30+
]);
3731
}
3832

3933
/**

0 commit comments

Comments
 (0)