Skip to content

Commit

Permalink
Skip tests related to PersistentObject if that class is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Feb 5, 2022
1 parent 5f882b1 commit ce60137
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\PersistentObject;

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;

/**
* @Entity
*/
class PersistentCollectionContent extends PersistentObject
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
* @var int
*/
protected $id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\PersistentObject;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
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\ManyToMany;

/**
* @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;
}
}
38 changes: 38 additions & 0 deletions tests/Doctrine/Tests/Models/PersistentObject/PersistentEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\PersistentObject;

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;

/**
* @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;
}
75 changes: 8 additions & 67 deletions tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@

namespace Doctrine\Tests\ORM\Functional;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
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\ManyToMany;
use Doctrine\Tests\Models\PersistentObject\PersistentCollectionContent;
use Doctrine\Tests\Models\PersistentObject\PersistentCollectionHolder;
use Doctrine\Tests\OrmFunctionalTestCase;
use Exception;

use function class_exists;

class PersistentCollectionTest extends OrmFunctionalTestCase
{
protected function setUp(): void
{
if (! class_exists(PersistentObject::class)) {
self::markTestSkipped('This test requires doctrine/persistence 2');
}

parent::setUp();
try {
$this->_schemaTool->createSchema(
Expand Down Expand Up @@ -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;
}
38 changes: 7 additions & 31 deletions tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}

0 comments on commit ce60137

Please sign in to comment.