Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,51 @@ env:
fail-fast: true

jobs:
phpunit-unstable:
name: "PHPUnit with unstable dependencies"
runs-on: "ubuntu-20.04"

strategy:
matrix:
php-version:
- "8.1"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
with:
fetch-depth: 2

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
extensions: "pdo, pdo_sqlite"
coverage: "pcov"
ini-values: "zend.assertions=1"

- name: "Require specific doctrine/persistence version"
run: "composer require doctrine/persistence '3.0.x-dev as 2.4.0' --no-update"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --coverage-clover=coverage-no-cache.xml"
env:
ENABLE_SECOND_LEVEL_CACHE: 0

- name: "Run PHPUnit with Second Level Cache"
run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --exclude-group performance,non-cacheable,locking_functional --coverage-clover=coverage-cache.xml"
env:
ENABLE_SECOND_LEVEL_CACHE: 1

- name: "Upload coverage file"
uses: "actions/upload-artifact@v2"
with:
name: "phpunit-sqlite-${{ matrix.php-version }}-unstable-coverage"
path: "coverage*.xml"

phpunit-smoke-check:
name: "PHPUnit with SQLite"
runs-on: "ubuntu-20.04"
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ jobs:
- "8.1"
dbal-version:
- "default"
- "2.13"
persistence-version:
- "default"
include:
- php-version: "8.1"
dbal-version: "2.13"
persistence-version: "default"
- php-version: "8.1"
dbal-version: "default"
persistence-version: "'3.0.x-dev as 2.4.0'"

steps:
- name: "Checkout code"
Expand All @@ -37,19 +45,27 @@ jobs:
run: "composer require doctrine/dbal ^${{ matrix.dbal-version }} --no-update"
if: "${{ matrix.dbal-version != 'default' }}"

- name: "Require specific persistence version"
run: "composer require doctrine/persistence ${{ matrix.persistence-version }} --no-update"
if: "${{ matrix.persistence-version != 'default' }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "highest"

- name: "Run a static analysis with phpstan/phpstan"
run: "vendor/bin/phpstan analyse"
if: "${{ matrix.dbal-version == 'default' }}"
if: "${{ matrix.dbal-version == 'default' && matrix.persistence-version == 'default'}}"

- name: "Run a static analysis with phpstan/phpstan"
run: "vendor/bin/phpstan analyse -c phpstan-dbal2.neon"
if: "${{ matrix.dbal-version == '2.13' }}"

- name: "Run a static analysis with phpstan/phpstan"
run: "vendor/bin/phpstan analyse -c phpstan-persistence3.neon"
if: "${{ matrix.dbal-version == 'default' && matrix.persistence-version != 'default'}}"

static-analysis-psalm:
name: "Static Analysis with Psalm"
runs-on: "ubuntu-20.04"
Expand Down
23 changes: 23 additions & 0 deletions lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ORM\Decorator;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Persistence\ObjectManagerDecorator;

Expand Down Expand Up @@ -43,6 +44,28 @@ public function getExpressionBuilder()
return $this->wrapped->getExpressionBuilder();
}

/**
* {@inheritdoc}
*
* @psalm-param class-string<T> $className
*
* @psalm-return EntityRepository<T>
*
* @template T of object
*/
public function getRepository($className)
{
return $this->wrapped->getRepository($className);
}

/**
* {@inheritdoc}
*/
public function getClassMetadata($className)
{
return $this->wrapped->getClassMetadata($className);
}

/**
* {@inheritdoc}
*/
Expand Down
10 changes: 10 additions & 0 deletions lib/Doctrine/ORM/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
use Doctrine\Common\Collections\AbstractLazyCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Selectable;
use Doctrine\Common\Persistence\PersistentObject;
use Doctrine\DBAL\LockMode;
use Doctrine\Deprecations\Deprecation;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;
use Doctrine\ORM\Exception\NotSupported;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Doctrine\ORM\Repository\Exception\InvalidMagicMethodCall;
use Doctrine\Persistence\ObjectRepository;

use function array_slice;
use function class_exists;
use function lcfirst;
use function sprintf;
use function str_starts_with;
Expand Down Expand Up @@ -168,6 +171,13 @@ public function clear()
__METHOD__
);

if (! class_exists(PersistentObject::class)) {
throw NotSupported::createForPersistence3(sprintf(
'Partial clearing of entities for class %s',
$this->_class->rootEntityName
));
}

$this->_em->clear($this->_class->rootEntityName);
}

Expand Down
14 changes: 14 additions & 0 deletions lib/Doctrine/ORM/Exception/NotSupported.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Doctrine\ORM\Exception;

use function sprintf;

final class NotSupported extends ORMException
{
public static function create(): self
Expand All @@ -15,4 +17,16 @@ public static function createForDbal3(): self
{
return new self('Feature was deprecated in doctrine/dbal 2.x and is not supported by installed doctrine/dbal:3.x, please see the doctrine/deprecations logs for new alternative approaches.');
}

public static function createForPersistence3(string $context): self
{
return new self(sprintf(
<<<'EXCEPTION'
Context: %s
Problem: Feature was deprecated in doctrine/persistence 2.x and is not supported by installed doctrine/persistence:3.x
Solution: See the doctrine/deprecations logs for new alternative approaches.
EXCEPTION,
$context
));
}
}
8 changes: 8 additions & 0 deletions phpstan-persistence3.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
includes:
- phpstan.neon

parameters:
ignoreErrors:
-
message: '/clear.*invoked with 1 parameter/'
path: lib/Doctrine/ORM/EntityRepository.php
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<referencedClass name="Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand"/>
<referencedClass name="Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand"/>
<referencedClass name="Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand"/>
<referencedClass name="Doctrine\Common\Persistence\PersistentObject"/>
</errorLevel>
</DeprecatedClass>
<DeprecatedInterface>
Expand Down
10 changes: 10 additions & 0 deletions tests/Doctrine/Tests/Models/Company/CompanyFlexContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\EntityResult;
use Doctrine\ORM\Mapping\FieldResult;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\JoinTable;
use Doctrine\ORM\Mapping\ManyToMany;
Expand Down Expand Up @@ -65,6 +67,14 @@
#[ORM\Entity]
class CompanyFlexContract extends CompanyContract
{
/**
* @Id
* @GeneratedValue
* @Column(type="integer")
* @var int
*/
public $id;

/**
* @Column(type="integer")
* @var int
Expand Down
51 changes: 34 additions & 17 deletions tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
use Doctrine\ORM\Decorator\EntityManagerDecorator;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\ResultSetMapping;
use Generator;
use LogicException;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionMethod;
use ReflectionNamedType;
use stdClass;

use function array_fill;
use function assert;
use function in_array;
use function sprintf;

class EntityManagerDecoratorTest extends TestCase
{
Expand All @@ -40,21 +45,18 @@ protected function setUp(): void
$this->wrapped = $this->createMock(EntityManagerInterface::class);
}

/** @psalm-return array<string, mixed[]> */
public function getMethodParameters(): array
/** @psalm-return Generator<string, mixed[]> */
public function getMethodParameters(): Generator
{
$class = new ReflectionClass(EntityManagerInterface::class);
$methods = [];
$class = new ReflectionClass(EntityManagerInterface::class);

foreach ($class->getMethods() as $method) {
if ($method->isConstructor() || $method->isStatic() || ! $method->isPublic()) {
continue;
}

$methods[$method->getName()] = $this->getParameters($method);
yield $method->getName() => $this->getParameters($method);
}

return $methods;
}

/**
Expand All @@ -77,19 +79,34 @@ static function (): void {
];
}

if ($method->getNumberOfRequiredParameters() === 0) {
return [$method->getName(), []];
}
$parameters = [];

if ($method->getNumberOfRequiredParameters() > 0) {
return [$method->getName(), array_fill(0, $method->getNumberOfRequiredParameters(), 'req') ?: []];
}
foreach ($method->getParameters() as $parameter) {
if ($parameter->getType() === null) {
$parameters[] = 'mixed';
continue;
}

if ($method->getNumberOfParameters() !== $method->getNumberOfRequiredParameters()) {
return [$method->getName(), array_fill(0, $method->getNumberOfParameters(), 'all') ?: []];
$type = $parameter->getType();
assert($type instanceof ReflectionNamedType);
switch ($type->getName()) {
case 'string':
$parameters[] = 'parameter';
break;

case 'object':
$parameters[] = new stdClass();
break;

default:
throw new LogicException(sprintf(
'Type %s is not handled yet',
(string) $parameter->getType()
));
}
}

return [];
return [$method->getName(), $parameters];
}

/**
Expand Down
9 changes: 8 additions & 1 deletion tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
use BadMethodCallException;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Persistence\PersistentObject;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\Logging\Middleware as LoggingMiddleware;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Exception\InvalidEntityRepository;
use Doctrine\ORM\Exception\NotSupported;
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\Exception\UnrecognizedIdentifierFields;
use Doctrine\ORM\Mapping\MappingException;
Expand Down Expand Up @@ -1155,7 +1157,12 @@ public function testDeprecatedClear(): void
{
$repository = $this->_em->getRepository(CmsAddress::class);

$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8460');
if (class_exists(PersistentObject::class)) {
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8460');
} else {
$this->expectException(NotSupported::class);
$this->expectExceptionMessage(CmsAddress::class);
}

$repository->clear();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ public function testIssue(): void
$connection = $this->createMock(Connection::class);

$configuration
->expects(self::any())
->method('getMetadataDriverImpl')
->will(self::returnValue($mockDriver));

$entityManager->expects(self::any())->method('getConfiguration')->will(self::returnValue($configuration));
$entityManager->expects(self::any())->method('getConnection')->will(self::returnValue($connection));
$entityManager
->expects(self::any())
->method('getEventManager')
->will(self::returnValue($this->createMock(EventManager::class)));

$metadataFactory->expects(self::any())->method('newClassMetadataInstance')->will(self::returnValue($mockMetadata));
$metadataFactory->method('newClassMetadataInstance')->will(self::returnValue($mockMetadata));
$metadataFactory->expects(self::once())->method('wakeupReflection');

$metadataFactory->setEntityManager($entityManager);

$mockMetadata->method('getName')->willReturn(DDC2359Foo::class);

self::assertSame($mockMetadata, $metadataFactory->getMetadataFor(DDC2359Foo::class));
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH7512Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ protected function setUp(): void

public function testFindEntityByAssociationPropertyJoinedChildWithClearMetadata(): void
{
// unset metadata for entity B as though it hasn't been touched yet in application lifecycle.
$this->_em->getMetadataFactory()->setMetadataFor(GH7512EntityB::class, null);
$result = $this->_em->getRepository(GH7512EntityC::class)->findBy([
// pretend we are starting afresh
$this->_em = $this->getEntityManager();
$result = $this->_em->getRepository(GH7512EntityC::class)->findBy([
'entityA' => new GH7512EntityB(),
]);
$this->assertEmpty($result);
Expand Down