Skip to content

Commit 26bd70d

Browse files
committed
Stop swallowing exceptions
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.
1 parent a06bbaf commit 26bd70d

11 files changed

+136
-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

+21-16
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,23 @@ class LifecycleCallbackTest extends OrmFunctionalTestCase
4141
protected function setUp(): void
4242
{
4343
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-
}
44+
$this->_schemaTool->createSchema([
45+
$this->_em->getClassMetadata(LifecycleCallbackEventArgEntity::class),
46+
$this->_em->getClassMetadata(LifecycleCallbackTestEntity::class),
47+
$this->_em->getClassMetadata(LifecycleCallbackTestUser::class),
48+
$this->_em->getClassMetadata(LifecycleCallbackCascader::class),
49+
]);
50+
}
51+
52+
protected function tearDown(): void
53+
{
54+
$this->_schemaTool->dropSchema([
55+
$this->_em->getClassMetadata(LifecycleCallbackCascader::class),
56+
$this->_em->getClassMetadata(LifecycleCallbackTestUser::class),
57+
$this->_em->getClassMetadata(LifecycleCallbackTestEntity::class),
58+
$this->_em->getClassMetadata(LifecycleCallbackEventArgEntity::class),
59+
]);
60+
parent::tearDown();
5661
}
5762

5863
public function testPreSavePostSaveCallbacksAreInvoked(): void
@@ -261,7 +266,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIteration(): void
261266

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

264-
$result = $query->iterate();
269+
$result = iterator_to_array($query->iterate());
265270

266271
foreach ($result as $entity) {
267272
self::assertTrue($entity[0]->postLoadCallbackInvoked);
@@ -270,7 +275,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIteration(): void
270275
break;
271276
}
272277

273-
$iterableResult = $query->toIterable();
278+
$iterableResult = iterator_to_array($query->toIterable());
274279

275280
foreach ($iterableResult as $entity) {
276281
self::assertTrue($entity->postLoadCallbackInvoked);
@@ -296,7 +301,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIterationWithSimple
296301
'SELECT e FROM Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity AS e'
297302
);
298303

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

301306
foreach ($result as $entity) {
302307
self::assertTrue($entity[0]->postLoadCallbackInvoked);
@@ -305,7 +310,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIterationWithSimple
305310
break;
306311
}
307312

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

310315
foreach ($result as $entity) {
311316
self::assertTrue($entity->postLoadCallbackInvoked);

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

+41-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,37 @@
2425

2526
class OptimisticTest extends OrmFunctionalTestCase
2627
{
28+
private Connection $_conn;
29+
2730
protected function setUp(): void
2831
{
2932
parent::setUp();
33+
$this->_conn = $this->_em->getConnection();
34+
}
3035

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-
}
36+
private function createSchema(): void
37+
{
38+
$this->_schemaTool->createSchema([
39+
$this->_em->getClassMetadata(OptimisticJoinedParent::class),
40+
$this->_em->getClassMetadata(OptimisticJoinedChild::class),
41+
$this->_em->getClassMetadata(OptimisticStandard::class),
42+
$this->_em->getClassMetadata(OptimisticTimestamp::class),
43+
]);
44+
}
4345

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

4756
public function testJoinedChildInsertSetsInitialVersionValue(): OptimisticJoinedChild
4857
{
58+
$this->createSchema();
4959
$test = new OptimisticJoinedChild();
5060

5161
$test->name = 'child';
@@ -83,10 +93,13 @@ public function testJoinedChildFailureThrowsException(OptimisticJoinedChild $chi
8393
} catch (OptimisticLockException $e) {
8494
self::assertSame($test, $e->getEntity());
8595
}
96+
97+
$this->dropSchema();
8698
}
8799

88100
public function testJoinedParentInsertSetsInitialVersionValue(): OptimisticJoinedParent
89101
{
102+
$this->createSchema();
90103
$test = new OptimisticJoinedParent();
91104

92105
$test->name = 'parent';
@@ -123,10 +136,14 @@ public function testJoinedParentFailureThrowsException(OptimisticJoinedParent $p
123136
} catch (OptimisticLockException $e) {
124137
self::assertSame($test, $e->getEntity());
125138
}
139+
140+
$this->dropSchema();
126141
}
127142

128143
public function testMultipleFlushesDoIncrementalUpdates(): void
129144
{
145+
$this->createSchema();
146+
130147
$test = new OptimisticStandard();
131148

132149
for ($i = 0; $i < 5; $i++) {
@@ -138,10 +155,14 @@ public function testMultipleFlushesDoIncrementalUpdates(): void
138155
self::assertIsInt($test->getVersion());
139156
self::assertEquals($i + 1, $test->getVersion());
140157
}
158+
159+
$this->dropSchema();
141160
}
142161

143162
public function testStandardInsertSetsInitialVersionValue(): OptimisticStandard
144163
{
164+
$this->createSchema();
165+
145166
$test = new OptimisticStandard();
146167

147168
$test->name = 'test';
@@ -179,10 +200,13 @@ public function testStandardFailureThrowsException(OptimisticStandard $entity):
179200
} catch (OptimisticLockException $e) {
180201
self::assertSame($test, $e->getEntity());
181202
}
203+
204+
$this->dropSchema();
182205
}
183206

184207
public function testLockWorksWithProxy(): void
185208
{
209+
$this->createSchema();
186210
$test = new OptimisticStandard();
187211
$test->name = 'test';
188212

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

197221
$this->addToAssertionCount(1);
222+
$this->dropSchema();
198223
}
199224

200225
public function testOptimisticTimestampSetsDefaultValue(): OptimisticTimestamp
201226
{
227+
$this->createSchema();
202228
$test = new OptimisticTimestamp();
203229

204230
$test->name = 'Testing';
@@ -274,6 +300,8 @@ public function testOptimisticTimestampLockFailureThrowsException(OptimisticTime
274300

275301
self::assertNotNull($caughtException, 'No OptimisticLockingException was thrown');
276302
self::assertSame($test, $caughtException->getEntity());
303+
304+
$this->dropSchema();
277305
}
278306
}
279307

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)