Skip to content

Commit

Permalink
Merge branch '2.14.x' into 2.15.x
Browse files Browse the repository at this point in the history
* 2.14.x:
  Remove calls to assertObjectHasAttribute() (doctrine#10502)
  Remove calls to withConsecutive() (doctrine#10501)
  Use recognized array key
  Fix doctrine#9095 by re-applying doctrine#9096
  Use linebreaks
  • Loading branch information
derrabus committed Feb 7, 2023
2 parents 83d56d7 + 0bd5fbf commit 6c17e47
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 20 deletions.
8 changes: 7 additions & 1 deletion lib/Doctrine/ORM/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,13 @@ public function validateClass(ClassMetadataInfo $class)
}
}

if (! $class->isInheritanceTypeNone() && ! $class->isRootEntity() && ! $class->isMappedSuperclass && array_search($class->name, $class->discriminatorMap, true) === false) {
if (
! $class->isInheritanceTypeNone()
&& ! $class->isRootEntity()
&& ($class->reflClass !== null && ! $class->reflClass->isAbstract())
&& ! $class->isMappedSuperclass
&& array_search($class->name, $class->discriminatorMap, true) === false
) {
$ce[] = "Entity class '" . $class->name . "' is part of inheritance hierarchy, but is " .
"not mapped in the root entity '" . $class->rootEntityName . "' discriminator map. " .
'All subclasses must be listed in the discriminator map.';
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/DDC964/DDC964User.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static function loadMetadata(ClassMetadata $metadata): void
'fieldName' => 'address',
'targetEntity' => 'DDC964Address',
'cascade' => ['persist','merge'],
'joinColumn' => ['name' => 'address_id', 'referencedColumnMame' => 'id'],
'joinColumns' => [['name' => 'address_id', 'referencedColumnMame' => 'id']],
]
);

Expand Down
5 changes: 3 additions & 2 deletions tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Doctrine\Tests\PHPUnitCompatibility\MockBuilderCompatibilityTools;

use function count;
use function property_exists;

class ObjectHydratorTest extends HydrationTestCase
{
Expand Down Expand Up @@ -927,10 +928,10 @@ public function testEntityQueryCustomResultSetOrder(): void
self::assertEquals(1, $result[0]->getId());
self::assertEquals(2, $result[1]->getId());

self::assertObjectHasAttribute('boards', $result[0]);
self::assertTrue(property_exists($result[0], 'boards'));
self::assertEquals(3, count($result[0]->boards));

self::assertObjectHasAttribute('boards', $result[1]);
self::assertTrue(property_exists($result[1], 'boards'));
self::assertEquals(1, count($result[1]->boards));
}

Expand Down
14 changes: 4 additions & 10 deletions tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,10 @@ public function testIsTransient(): void
$driver = $this->createMock(MappingDriver::class);
$driver->expects(self::exactly(2))
->method('isTransient')
->withConsecutive(
[CmsUser::class],
[CmsArticle::class]
)
->willReturnMap(
[
[CmsUser::class, true],
[CmsArticle::class, false],
]
);
->willReturnMap([
[CmsUser::class, true],
[CmsArticle::class, false],
]);

$em = $this->createEntityManager($driver);

Expand Down
20 changes: 14 additions & 6 deletions tests/Doctrine/Tests/ORM/Tools/Pagination/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Result;
use Doctrine\ORM\Decorator\EntityManagerDecorator;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
Expand Down Expand Up @@ -64,17 +65,24 @@ public function testExtraParametersAreStrippedWhenWalkerRemovingOriginalSelectEl
$query->setMaxResults(1);
$paginator = (new Paginator($query, true))->setUseOutputWalkers(false);

$receivedParams = [];
$resultMock = $this->createMock(Result::class);
$this->connection
->expects(self::exactly(3))
->method('executeQuery')
->withConsecutive(
[self::anything(), [$paramInWhere]],
[self::anything(), [$paramInWhere]],
[self::anything(), [$paramInSubSelect, $paramInWhere, $returnedIds]]
);
->willReturnCallback(static function (string $sql, array $params) use (&$receivedParams, $resultMock): Result {
$receivedParams[] = $params;

return $resultMock;
});

$paginator->count();
$paginator->getIterator();

self::assertSame([
[$paramInWhere],
[$paramInWhere],
[$paramInSubSelect, $paramInWhere, $returnedIds],
], $receivedParams);
}

public function testPaginatorNotCaringAboutExtraParametersWithoutOutputWalkers(): void
Expand Down
33 changes: 33 additions & 0 deletions tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ public function testMappedSuperclassNotPresentInDiscriminator(): void

$this->assertEquals([], $ce);
}

public function testAbstractChildClassNotPresentInDiscriminator(): void
{
$class1 = $this->em->getClassMetadata(Issue9095AbstractChild::class);
$ce = $this->validator->validateClass($class1);

self::assertEmpty($ce);
}
}

/** @MappedSuperclass */
Expand Down Expand Up @@ -643,3 +651,28 @@ class EmbeddableWithAssociation
*/
private $cart;
}

/**
* @Entity
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorMap({"child" = Issue9095Child::class})
*/
abstract class Issue9095Parent
{
/**
* @var mixed
* @Id
* @Column
*/
protected $key;
}

/** @Entity */
abstract class Issue9095AbstractChild extends Issue9095Parent
{
}

/** @Entity */
class Issue9095Child extends Issue9095AbstractChild
{
}

0 comments on commit 6c17e47

Please sign in to comment.