Skip to content

Commit

Permalink
Merge branch '2.9.x' into merge/2.9.x
Browse files Browse the repository at this point in the history
* 2.9.x:
  Fix return type at `EntityManagerInterface::get(Partial)Reference()` (doctrine#8922)
  Fix class casing and avoid name collisions
  Remove unused performance base test class
  Drop unused test base classes
  Fix mapped superclass missing in discriminator map
  • Loading branch information
derrabus committed Sep 11, 2021
2 parents 01ab70d + fb89129 commit a053662
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 113 deletions.
9 changes: 7 additions & 2 deletions lib/Doctrine/ORM/EntityManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use BadMethodCallException;
use DateTimeInterface;
use Doctrine\Common\EventManager;
use Doctrine\Common\Proxy\Proxy;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
use Doctrine\ORM\Proxy\ProxyFactory;
Expand Down Expand Up @@ -173,7 +174,7 @@ public function createQueryBuilder();
* @psalm-param class-string<T> $entityName
*
* @return object|null The entity reference.
* @psalm-return ?T
* @psalm-return (T&Proxy)|null
*
* @throws ORMException
*
Expand All @@ -198,8 +199,12 @@ public function getReference($entityName, $id);
*
* @param string $entityName The name of the entity type.
* @param mixed $identifier The entity identifier.
* @psalm-param class-string<T> $entityName
*
* @return object|null The (partial) entity reference
* @psalm-return (T&Proxy)|null
*
* @return object|null The (partial) entity reference.
* @template T
*/
public function getPartialReference($entityName, $identifier);

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function validateClass(ClassMetadataInfo $class)
}
}

if (! $class->isInheritanceTypeNone() && ! $class->isRootEntity() && array_search($class->name, $class->discriminatorMap, true) === false) {
if (! $class->isInheritanceTypeNone() && ! $class->isRootEntity() && ! $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
1 change: 0 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@
<exclude-pattern>lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php</exclude-pattern>
<exclude-pattern>lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php</exclude-pattern>
<!-- the impact of changing this would be too big -->
<exclude-pattern>tests/Doctrine/Tests/DbalFunctionalTestCase.php</exclude-pattern>
<exclude-pattern>tests/Doctrine/Tests/OrmFunctionalTestCase.php</exclude-pattern>
</rule>
<rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps">
Expand Down
14 changes: 12 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,22 @@ parameters:
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getReference\\(\\) should return T\\|null but returns Doctrine\\\\Common\\\\Proxy\\\\Proxy\\.$#"
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getPartialReference\\(\\) should return \\(Doctrine\\\\Common\\\\Proxy\\\\Proxy&T\\)\\|null but returns object\\.$#"
count: 1
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getReference\\(\\) should return T\\|null but returns object\\|null\\.$#"
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getPartialReference\\(\\) should return \\(Doctrine\\\\Common\\\\Proxy\\\\Proxy&T\\)\\|null but returns object\\|null\\.$#"
count: 1
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getReference\\(\\) should return \\(Doctrine\\\\Common\\\\Proxy\\\\Proxy&T\\)\\|null but returns Doctrine\\\\Common\\\\Proxy\\\\Proxy\\.$#"
count: 1
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getReference\\(\\) should return \\(Doctrine\\\\Common\\\\Proxy\\\\Proxy&T\\)\\|null but returns object\\|null\\.$#"
count: 1
path: lib/Doctrine/ORM/EntityManager.php

Expand Down
8 changes: 6 additions & 2 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -462,18 +462,22 @@
<code>is_object($entity)</code>
<code>is_object($entity)</code>
</DocblockTypeContradiction>
<InvalidReturnStatement occurrences="7">
<InvalidReturnStatement occurrences="10">
<code>$entity</code>
<code>$entity</code>
<code>$entity</code>
<code>$entity</code>
<code>$entity instanceof $class-&gt;name ? $entity : null</code>
<code>$entity instanceof $class-&gt;name ? $entity : null</code>
<code>$persister-&gt;load($sortedId, null, null, [], $lockMode)</code>
<code>$persister-&gt;loadById($sortedId)</code>
<code>$this-&gt;find($entityName, $sortedId)</code>
<code>$this-&gt;metadataFactory-&gt;getMetadataFor($className)</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="3">
<InvalidReturnType occurrences="4">
<code>?T</code>
<code>getClassMetadata</code>
<code>getPartialReference</code>
<code>getReference</code>
</InvalidReturnType>
<InvalidScalarArgument occurrences="1">
Expand Down
39 changes: 0 additions & 39 deletions tests/Doctrine/Tests/DbalFunctionalTestCase.php

This file was deleted.

12 changes: 0 additions & 12 deletions tests/Doctrine/Tests/DbalTestCase.php

This file was deleted.

43 changes: 43 additions & 0 deletions tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\DiscriminatorMap;
use Doctrine\ORM\Mapping\Embeddable;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\InheritanceType;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\JoinTable;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\MappedSuperclass;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\ORM\Mapping\OrderBy;
Expand Down Expand Up @@ -211,6 +214,46 @@ public function testInvalidAssociationInsideEmbeddable(): void
$ce
);
}

/**
* @group 8771
*/
public function testMappedSuperclassNotPresentInDiscriminator(): void
{
$class1 = $this->em->getClassMetadata(MappedSuperclassEntity::class);
$ce = $this->validator->validateClass($class1);

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

/**
* @MappedSuperclass
*/
abstract class MappedSuperclassEntity extends ParentEntity
{
}

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

/**
* @Entity
*/
class ChildEntity extends MappedSuperclassEntity
{
}

/**
Expand Down
54 changes: 0 additions & 54 deletions tests/Doctrine/Tests/OrmPerformanceTestCase.php

This file was deleted.

0 comments on commit a053662

Please sign in to comment.