From 7e1e22dd84f8e66deb5d81e30d7a89d27e8e541b Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 5 Feb 2022 18:37:52 +0100 Subject: [PATCH] Skip tests related to PersistentObject if that class is missing --- .../PersistentCollectionContent.php | 23 ++++++ .../PersistentCollectionHolder.php | 58 ++++++++++++++ .../PersistentObject/PersistentEntity.php | 36 +++++++++ .../Functional/PersistentCollectionTest.php | 75 ++----------------- .../ORM/Functional/PersistentObjectTest.php | 38 ++-------- 5 files changed, 132 insertions(+), 98 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/PersistentObject/PersistentCollectionContent.php create mode 100644 tests/Doctrine/Tests/Models/PersistentObject/PersistentCollectionHolder.php create mode 100644 tests/Doctrine/Tests/Models/PersistentObject/PersistentEntity.php diff --git a/tests/Doctrine/Tests/Models/PersistentObject/PersistentCollectionContent.php b/tests/Doctrine/Tests/Models/PersistentObject/PersistentCollectionContent.php new file mode 100644 index 00000000000..e31db9532a5 --- /dev/null +++ b/tests/Doctrine/Tests/Models/PersistentObject/PersistentCollectionContent.php @@ -0,0 +1,23 @@ +collection = new ArrayCollection(); + } + + public function addElement(PersistentCollectionContent $element): void + { + $this->collection->add($element); + } + + /** + * @return Collection + */ + public function getCollection(): Collection + { + return clone $this->collection; + } + + /** + * @return Collection + */ + public function getRawCollection(): Collection + { + return $this->collection; + } +} diff --git a/tests/Doctrine/Tests/Models/PersistentObject/PersistentEntity.php b/tests/Doctrine/Tests/Models/PersistentObject/PersistentEntity.php new file mode 100644 index 00000000000..bdfc41a143e --- /dev/null +++ b/tests/Doctrine/Tests/Models/PersistentObject/PersistentEntity.php @@ -0,0 +1,36 @@ +_schemaTool->createSchema( @@ -105,63 +106,3 @@ public function testMatchingDoesNotModifyTheGivenCriteria(): void self::assertEmpty($criteria->getOrderings()); } } - -/** - * @Entity - */ -class PersistentCollectionHolder extends PersistentObject -{ - /** - * @Id - * @Column(type="integer") - * @GeneratedValue - * @var int - */ - protected $id; - - /** - * @var Collection - * @ManyToMany(targetEntity="PersistentCollectionContent", cascade={"all"}, fetch="EXTRA_LAZY") - */ - protected $collection; - - public function __construct() - { - $this->collection = new ArrayCollection(); - } - - public function addElement(PersistentCollectionContent $element): void - { - $this->collection->add($element); - } - - /** - * @return Collection - */ - public function getCollection(): Collection - { - return clone $this->collection; - } - - /** - * @return Collection - */ - public function getRawCollection(): Collection - { - return $this->collection; - } -} - -/** - * @Entity - */ -class PersistentCollectionContent extends PersistentObject -{ - /** - * @Id - * @Column(type="integer") - * @GeneratedValue - * @var int - */ - protected $id; -} diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php index 37063374cef..3c0923f9285 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php @@ -5,14 +5,12 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Persistence\PersistentObject; -use Doctrine\ORM\Mapping\Column; -use Doctrine\ORM\Mapping\Entity; -use Doctrine\ORM\Mapping\GeneratedValue; -use Doctrine\ORM\Mapping\Id; -use Doctrine\ORM\Mapping\ManyToOne; +use Doctrine\Tests\Models\PersistentObject\PersistentEntity; use Doctrine\Tests\OrmFunctionalTestCase; use Exception; +use function class_exists; + /** * Test that Doctrine ORM correctly works with the ObjectManagerAware and PersistentObject * classes from Common. @@ -23,6 +21,10 @@ class PersistentObjectTest extends OrmFunctionalTestCase { protected function setUp(): void { + if (! class_exists(PersistentObject::class)) { + self::markTestSkipped('This test requires doctrine/persistence 2'); + } + parent::setUp(); try { @@ -93,29 +95,3 @@ public function testSetAssociation(): void self::assertSame($entity, $entity->getParent()); } } - -/** - * @Entity - */ -class PersistentEntity extends PersistentObject -{ - /** - * @Id - * @Column(type="integer") - * @GeneratedValue - * @var int - */ - protected $id; - - /** - * @Column(type="string") - * @var string - */ - protected $name; - - /** - * @ManyToOne(targetEntity="PersistentEntity") - * @var PersistentEntity - */ - protected $parent; -}