|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Doctrine\Tests\ORM\Functional\Ticket; |
| 6 | + |
| 7 | +use Doctrine\Common\Collections\Collection; |
| 8 | +use Doctrine\ORM\Mapping as ORM; |
| 9 | +use Doctrine\ORM\Mapping\MappingException; |
| 10 | +use Doctrine\Tests\OrmTestCase; |
| 11 | + |
| 12 | +use function get_parent_class; |
| 13 | +use function method_exists; |
| 14 | + |
| 15 | +class GH10449Test extends OrmTestCase |
| 16 | +{ |
| 17 | + public function testToManyAssociationOnMappedSuperclassShallBeRejected(): void |
| 18 | + { |
| 19 | + $em = $this->getTestEntityManager(); |
| 20 | + $classes = [GH10449MappedSuperclass::class, GH10449Entity::class, GH10449ToManyAssociationTarget::class]; |
| 21 | + |
| 22 | + $this->expectException(MappingException::class); |
| 23 | + $this->expectExceptionMessageMatches('/illegal to put an inverse side one-to-many or many-to-many association on mapped superclass/'); |
| 24 | + |
| 25 | + foreach ($classes as $class) { |
| 26 | + $cm = $em->getClassMetadata($class); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Override for BC with PHPUnit <8 |
| 32 | + */ |
| 33 | + public function expectExceptionMessageMatches(string $regularExpression): void |
| 34 | + { |
| 35 | + if (method_exists(get_parent_class($this), 'expectExceptionMessageMatches')) { |
| 36 | + parent::expectExceptionMessageMatches($regularExpression); |
| 37 | + } else { |
| 38 | + parent::expectExceptionMessageRegExp($regularExpression); |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +/** |
| 44 | + * @ORM\Entity |
| 45 | + */ |
| 46 | +class GH10449ToManyAssociationTarget |
| 47 | +{ |
| 48 | + /** |
| 49 | + * @ORM\Column(type="integer") |
| 50 | + * @ORM\Id |
| 51 | + * @ORM\GeneratedValue |
| 52 | + * |
| 53 | + * @var int |
| 54 | + */ |
| 55 | + public $id; |
| 56 | + |
| 57 | + /** |
| 58 | + * @ORM\ManyToOne(targetEntity="GH10449MappedSuperclass", inversedBy="targets") |
| 59 | + * |
| 60 | + * @var GH10449MappedSuperclass |
| 61 | + */ |
| 62 | + public $base; |
| 63 | +} |
| 64 | + |
| 65 | +/** |
| 66 | + * @ORM\MappedSuperclass |
| 67 | + */ |
| 68 | +class GH10449MappedSuperclass |
| 69 | +{ |
| 70 | + /** |
| 71 | + * @ORM\Column(type="integer") |
| 72 | + * @ORM\Id |
| 73 | + * @ORM\GeneratedValue |
| 74 | + * |
| 75 | + * @var int |
| 76 | + */ |
| 77 | + public $id; |
| 78 | + |
| 79 | + /** |
| 80 | + * @ORM\OneToMany(targetEntity="GH10449ToManyAssociationTarget", mappedBy="base") |
| 81 | + * |
| 82 | + * @var Collection |
| 83 | + */ |
| 84 | + public $targets; |
| 85 | +} |
| 86 | + |
| 87 | +/** |
| 88 | + * @ORM\Entity |
| 89 | + */ |
| 90 | +class GH10449Entity extends GH10449MappedSuperclass |
| 91 | +{ |
| 92 | +} |
0 commit comments