Skip to content

Commit

Permalink
Make creating test models more straightforward
Browse files Browse the repository at this point in the history
In doctrine#8962, I established that
swallowing exceptions while creating model was bad because it could hide
other helpful exceptions.

It looks like I based my grep on the comment inside. Today, I found many
other occurrences of this pattern, without the easy to grep comment.

I decided to fix them as well, but in a lazier way: one no longer has to
remember to call dropSchema in tearDown() now, it is automated.
  • Loading branch information
greg0ire committed Feb 19, 2022
1 parent 152c04c commit fbbb858
Show file tree
Hide file tree
Showing 30 changed files with 144 additions and 328 deletions.
22 changes: 7 additions & 15 deletions tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\ORM\Proxy\Proxy;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

use function count;
use function get_class;
Expand All @@ -30,19 +28,13 @@ class OneToOneEagerLoadingTest extends OrmFunctionalTestCase
protected function setUp(): void
{
parent::setUp();
$schemaTool = new SchemaTool($this->_em);
try {
$schemaTool->createSchema(
[
$this->_em->getClassMetadata(Train::class),
$this->_em->getClassMetadata(TrainDriver::class),
$this->_em->getClassMetadata(TrainOwner::class),
$this->_em->getClassMetadata(Waggon::class),
$this->_em->getClassMetadata(TrainOrder::class),
]
);
} catch (Exception $e) {
}
$this->createSchemaForModels(
Train::class,
TrainDriver::class,
TrainOwner::class,
Waggon::class,
TrainOrder::class
);
}

/**
Expand Down
14 changes: 4 additions & 10 deletions tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,16 @@
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

class PersistentCollectionTest extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(PersistentCollectionHolder::class),
$this->_em->getClassMetadata(PersistentCollectionContent::class),
]
);
} catch (Exception $e) {
}
$this->createSchemaForModels(
PersistentCollectionHolder::class,
PersistentCollectionContent::class
);

PersistentObject::setObjectManager($this->_em);
}
Expand Down
10 changes: 1 addition & 9 deletions tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

/**
* Test that Doctrine ORM correctly works with the ObjectManagerAware and PersistentObject
Expand All @@ -25,14 +24,7 @@ protected function setUp(): void
{
parent::setUp();

try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(PersistentEntity::class),
]
);
} catch (Exception $e) {
}
$this->createSchemaForModels(PersistentEntity::class);

PersistentObject::setObjectManager($this->_em);
}
Expand Down
24 changes: 9 additions & 15 deletions tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\OrmFunctionalTestCase;
use Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser as CmsUserProxy;
use Exception;

use function assert;

Expand All @@ -34,20 +33,15 @@ class ProxiesLikeEntitiesTest extends OrmFunctionalTestCase
protected function setUp(): void
{
parent::setUp();
try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(CmsUser::class),
$this->_em->getClassMetadata(CmsTag::class),
$this->_em->getClassMetadata(CmsPhonenumber::class),
$this->_em->getClassMetadata(CmsArticle::class),
$this->_em->getClassMetadata(CmsAddress::class),
$this->_em->getClassMetadata(CmsEmail::class),
$this->_em->getClassMetadata(CmsGroup::class),
]
);
} catch (Exception $e) {
}
$this->createSchemaForModels(
CmsUser::class,
CmsTag::class,
CmsPhonenumber::class,
CmsArticle::class,
CmsAddress::class,
CmsEmail::class,
CmsGroup::class
);

$this->user = new CmsUser();
$this->user->username = 'ocramius';
Expand Down
10 changes: 1 addition & 9 deletions tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Query;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

use function get_class;

Expand All @@ -25,14 +24,7 @@ protected function setUp(): void
{
parent::setUp();

try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(ReadOnlyEntity::class),
]
);
} catch (Exception $e) {
}
$this->createSchemaForModels(ReadOnlyEntity::class);
}

public function testReadOnlyEntityNeverChangeTracked(): void
Expand Down
10 changes: 1 addition & 9 deletions tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\SequenceGenerator;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

/**
* Description of SequenceGeneratorTest
Expand All @@ -25,14 +24,7 @@ protected function setUp(): void
self::markTestSkipped('Only working for Databases that support sequences.');
}

try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(SequenceEntity::class),
]
);
} catch (Exception $e) {
}
$this->createSchemaForModels(SequenceEntity::class);
}

public function testHighAllocationSizeSequence(): void
Expand Down
18 changes: 6 additions & 12 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

/**
* @group DDC-1113
Expand All @@ -25,17 +24,12 @@ protected function setUp(): void
{
parent::setUp();

try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(DDC1113Engine::class),
$this->_em->getClassMetadata(DDC1113Vehicle::class),
$this->_em->getClassMetadata(DDC1113Car::class),
$this->_em->getClassMetadata(DDC1113Bus::class),
]
);
} catch (Exception $e) {
}
$this->createSchemaForModels(
DDC1113Engine::class,
DDC1113Vehicle::class,
DDC1113Car::class,
DDC1113Bus::class
);
}

public function testIssue(): void
Expand Down
16 changes: 5 additions & 11 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,17 @@
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

class DDC1209Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(DDC1209One::class),
$this->_em->getClassMetadata(DDC1209Two::class),
$this->_em->getClassMetadata(DDC1209Three::class),
]
);
} catch (Exception $e) {
}
$this->createSchemaForModels(
DDC1209One::class,
DDC1209Two::class,
DDC1209Three::class
);
}

/**
Expand Down
11 changes: 1 addition & 10 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

/**
* @group DDC-1228
Expand All @@ -21,15 +20,7 @@ class DDC1228Test extends OrmFunctionalTestCase
protected function setUp(): void
{
parent::setUp();
try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(DDC1228User::class),
$this->_em->getClassMetadata(DDC1228Profile::class),
]
);
} catch (Exception $e) {
}
$this->createSchemaForModels(DDC1228User::class, DDC1228Profile::class);
}

public function testOneToOnePersist(): void
Expand Down
10 changes: 1 addition & 9 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

/**
* @group DDC-1238
Expand All @@ -19,14 +18,7 @@ class DDC1238Test extends OrmFunctionalTestCase
protected function setUp(): void
{
parent::setUp();
try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(DDC1238User::class),
]
);
} catch (Exception $e) {
}
$this->createSchemaForModels(DDC1238User::class);
}

public function testIssue(): void
Expand Down
13 changes: 2 additions & 11 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

/**
* @group DDC-1335
Expand All @@ -24,16 +23,8 @@ class DDC1335Test extends OrmFunctionalTestCase
protected function setUp(): void
{
parent::setUp();
try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(DDC1335User::class),
$this->_em->getClassMetadata(DDC1335Phone::class),
]
);
$this->loadFixture();
} catch (Exception $e) {
}
$this->createSchemaForModels(DDC1335User::class, DDC1335Phone::class);
$this->loadFixture();
}

public function testDql(): void
Expand Down
14 changes: 4 additions & 10 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1461Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\ORM\UnitOfWork;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

use function get_class;

Expand All @@ -25,15 +24,10 @@ protected function setUp(): void
{
parent::setUp();

try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(DDC1461TwitterAccount::class),
$this->_em->getClassMetadata(DDC1461User::class),
]
);
} catch (Exception $e) {
}
$this->createSchemaForModels(
DDC1461TwitterAccount::class,
DDC1461User::class
);
}

public function testChangeDetectionDeferredExplicit(): void
Expand Down
16 changes: 5 additions & 11 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1655Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\PostLoad;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

use function get_class;
use function get_debug_type;
Expand All @@ -32,16 +31,11 @@ protected function setUp(): void
{
parent::setUp();

try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(DDC1655Foo::class),
$this->_em->getClassMetadata(DDC1655Bar::class),
$this->_em->getClassMetadata(DDC1655Baz::class),
]
);
} catch (Exception $e) {
}
$this->createSchemaForModels(
DDC1655Foo::class,
DDC1655Bar::class,
DDC1655Baz::class
);
}

public function testPostLoadOneToManyInheritance(): void
Expand Down
10 changes: 1 addition & 9 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2895Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Doctrine\ORM\Mapping\PrePersist;
use Doctrine\ORM\Mapping\PreUpdate;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

use function assert;
use function get_class;
Expand All @@ -24,14 +23,7 @@ class DDC2895Test extends OrmFunctionalTestCase
protected function setUp(): void
{
parent::setUp();
try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(DDC2895::class),
]
);
} catch (Exception $e) {
}
$this->createSchemaForModels(DDC2895::class);
}

public function testPostLoadOneToManyInheritance(): void
Expand Down
Loading

0 comments on commit fbbb858

Please sign in to comment.