Skip to content

Commit

Permalink
Failing test: Illegal to-many association on MappedSuperclass not rej…
Browse files Browse the repository at this point in the history
…ected
  • Loading branch information
mpdude committed Jan 24, 2023
1 parent ed56f42 commit 87f85ab
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH10449Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\Tests\OrmTestCase;

class GH10449Test extends OrmTestCase
{
public function testToManyAssociationOnMappedSuperclassShallBeRejected(): void
{
$em = $this->getTestEntityManager();
$classes = [GH10449MappedSuperclass::class, GH10449Entity::class, GH10449ToManyAssociationTarget::class];

$this->expectException(MappingException::class);
$this->expectExceptionMessageMatches('/illegal to put an inverse side one-to-many or many-to-many association on mapped superclass/');

foreach ($classes as $class) {
$em->getClassMetadata($class);
}
}

/**
* Override for BC with PHPUnit <8
*/
public function expectExceptionMessageMatches(string $regularExpression): void
{
if (method_exists(get_parent_class($this), 'expectExceptionMessageMatches')) {
parent::expectExceptionMessageMatches($regularExpression);
} else {
parent::expectExceptionMessageRegExp($regularExpression);
}
}
}

/**
* @ORM\Entity
*/
class GH10449ToManyAssociationTarget
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*
* @var int
*/
public $id;

/**
* @ORM\ManyToOne(targetEntity="GH10449MappedSuperclass", inversedBy="targets")
*
* @var GH10449MappedSuperclass
*/
public $base;
}

/**
* @ORM\MappedSuperclass
*/
class GH10449MappedSuperclass
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*
* @var int
*/
public $id;

/**
* @ORM\OneToMany(targetEntity="GH10449ToManyAssociationTarget", mappedBy="base")
*
* @var Collection
*/
public $targets;
}

/**
* @ORM\Entity
*/
class GH10449Entity extends GH10449MappedSuperclass
{
}

0 comments on commit 87f85ab

Please sign in to comment.