Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doctrine/orm 3 support #417

Merged
merged 1 commit into from
Feb 9, 2025
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
51 changes: 18 additions & 33 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ parameters:
count: 1
path: src/EventListener/ORM/SortableListener.php

-
message: "#^Method Nucleos\\\\Doctrine\\\\EventListener\\\\ORM\\\\TablePrefixEventListener\\:\\:addSequenceGenerator\\(\\) has parameter \\$definition with no value type specified in iterable type array\\.$#"
count: 1
path: src/EventListener/ORM/TablePrefixEventListener.php

-
message: "#^Method Nucleos\\\\Doctrine\\\\EventListener\\\\ORM\\\\TablePrefixEventListener\\:\\:evaluteMapping\\(\\) has parameter \\$mapping with no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -36,12 +31,12 @@ parameters:
path: src/EventListener/ORM/TablePrefixEventListener.php

-
message: "#^Parameter \\#1 \\$definition of method Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\<object\\>\\:\\:setSequenceGeneratorDefinition\\(\\) expects array\\{sequenceName\\?\\: string, allocationSize\\?\\: int\\|string, initialValue\\?\\: int\\|string, quoted\\?\\: mixed\\}, array\\{sequenceName\\: string, allocationSize\\: string, initialValue\\: string, quoted\\?\\: mixed\\}\\|array\\{sequenceName\\: string\\}\\|null given\\.$#"
message: "#^Parameter \\#1 \\$definition of method Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata\\<object\\>\\:\\:setSequenceGeneratorDefinition\\(\\) expects array\\{sequenceName\\?\\: string, allocationSize\\?\\: int\\|string, initialValue\\?\\: int\\|string, quoted\\?\\: mixed\\}, array\\{sequenceName\\: string, allocationSize\\: string, initialValue\\: string, quoted\\?\\: mixed\\}\\|array\\{sequenceName\\: string\\}\\|null given\\.$#"
count: 1
path: src/EventListener/ORM/TablePrefixEventListener.php

-
message: "#^Parameter \\#3 \\$definition of method Nucleos\\\\Doctrine\\\\EventListener\\\\ORM\\\\TablePrefixEventListener\\:\\:addSequenceGenerator\\(\\) expects array, array\\<string, mixed\\>\\|null given\\.$#"
message: "#^Parameter \\#3 \\$definition of method Nucleos\\\\Doctrine\\\\EventListener\\\\ORM\\\\TablePrefixEventListener\\:\\:addSequenceGenerator\\(\\) expects array\\{allocationSize\\: int\\}, array\\{sequenceName\\: string, allocationSize\\: string, initialValue\\: string, quoted\\?\\: mixed\\}\\|array\\{sequenceName\\: string\\}\\|null given\\.$#"
count: 1
path: src/EventListener/ORM/TablePrefixEventListener.php

Expand All @@ -50,50 +45,45 @@ parameters:
count: 1
path: src/EventListener/ORM/UniqueActiveListener.php

-
message: "#^Call to function method_exists\\(\\) with Doctrine\\\\DBAL\\\\Connection and 'createSchemaManager' will always evaluate to true\\.$#"
count: 1
path: src/Migration/IdToUuidMigration.php

-
message: "#^Property Nucleos\\\\Doctrine\\\\Migration\\\\IdToUuidMigration\\:\\:\\$schemaManager with generic class Doctrine\\\\DBAL\\\\Schema\\\\AbstractSchemaManager does not specify its types\\: T$#"
count: 1
path: src/Migration/IdToUuidMigration.php

-
message: "#^Method Nucleos\\\\Doctrine\\\\Tests\\\\Bridge\\\\Symfony\\\\App\\\\AppKernel\\:\\:configureContainer\\(\\) has parameter \\$container with no type specified\\.$#"
count: 1
path: tests/Bridge/Symfony/App/AppKernel.php
message: "#^Call to method method\\(\\) on an unknown class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\.$#"
count: 4
path: src/Test/ORM/EntityManagerMockFactory.php

-
message: "#^Method Nucleos\\\\Doctrine\\\\Tests\\\\Bridge\\\\Symfony\\\\App\\\\AppKernel\\:\\:configureContainer\\(\\) has parameter \\$loader with no type specified\\.$#"
message: "#^Call to protected method createMock\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\.$#"
count: 1
path: tests/Bridge/Symfony/App/AppKernel.php
path: src/Test/ORM/EntityManagerMockFactory.php

-
message: "#^Method Nucleos\\\\Doctrine\\\\Tests\\\\Bridge\\\\Symfony\\\\App\\\\AppKernel\\:\\:configureRoutes\\(\\) has parameter \\$routes with no type specified\\.$#"
message: "#^Class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo not found\\.$#"
count: 1
path: tests/Bridge/Symfony/App/AppKernel.php
path: src/Test/ORM/EntityManagerMockFactory.php

-
message: "#^Call to method getResponse\\(\\) on an unknown class Symfony\\\\Component\\\\HttpKernel\\\\Client\\.$#"
message: "#^Trying to mock an undefined method getFieldNames\\(\\) on class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\.$#"
count: 1
path: tests/Bridge/Symfony/Bundle/BundleIntegrationTest.php
path: src/Test/ORM/EntityManagerMockFactory.php

-
message: "#^Call to method request\\(\\) on an unknown class Symfony\\\\Component\\\\HttpKernel\\\\Client\\.$#"
message: "#^Trying to mock an undefined method getIdentifier\\(\\) on class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\.$#"
count: 1
path: tests/Bridge/Symfony/Bundle/BundleIntegrationTest.php
path: src/Test/ORM/EntityManagerMockFactory.php

-
message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Client not found\\.$#"
message: "#^Trying to mock an undefined method getName\\(\\) on class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\.$#"
count: 1
path: tests/Bridge/Symfony/Bundle/BundleIntegrationTest.php
path: src/Test/ORM/EntityManagerMockFactory.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\TestCase\\:\\:createStub\\(\\)\\.$#"
count: 2
path: tests/EventListener/ORM/LifecycleDateListenerTest.php
message: "#^Trying to mock an undefined method getTableName\\(\\) on class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\.$#"
count: 1
path: src/Test/ORM/EntityManagerMockFactory.php

-
message: "#^Call to function assert\\(\\) with true will always evaluate to true\\.$#"
Expand Down Expand Up @@ -125,8 +115,3 @@ parameters:
count: 1
path: tests/Fixtures/DemoEntityManager.php

-
message: "#^Call to function method_exists\\(\\) with Doctrine\\\\DBAL\\\\Connection and 'createSchemaManager' will always evaluate to true\\.$#"
count: 1
path: tests/Migration/IdToUuidMigrationTest.php

11 changes: 7 additions & 4 deletions src/EventListener/ORM/TablePrefixEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
use Doctrine\ORM\Id\SequenceGenerator;
use Doctrine\ORM\Mapping\AssociationMapping;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;

final class TablePrefixEventListener implements EventSubscriber
{
Expand Down Expand Up @@ -102,12 +102,12 @@

private function prefixExists(string $name): bool
{
return 0 === strpos($name, (string) $this->prefix);
return str_starts_with($name, (string) $this->prefix);

Check warning on line 105 in src/EventListener/ORM/TablePrefixEventListener.php

View check run for this annotation

Codecov / codecov/patch

src/EventListener/ORM/TablePrefixEventListener.php#L105

Added line #L105 was not covered by tests
}

private function evaluteMapping(ClassMetadata $classMetadata, array $mapping, string $fieldName): void
private function evaluteMapping(ClassMetadata $classMetadata, array|AssociationMapping $mapping, string $fieldName): void

Check warning on line 108 in src/EventListener/ORM/TablePrefixEventListener.php

View check run for this annotation

Codecov / codecov/patch

src/EventListener/ORM/TablePrefixEventListener.php#L108

Added line #L108 was not covered by tests
{
if (ClassMetadataInfo::MANY_TO_MANY !== $mapping['type']) {
if (ClassMetadata::MANY_TO_MANY !== $mapping['type']) {

Check warning on line 110 in src/EventListener/ORM/TablePrefixEventListener.php

View check run for this annotation

Codecov / codecov/patch

src/EventListener/ORM/TablePrefixEventListener.php#L110

Added line #L110 was not covered by tests
return;
}

Expand All @@ -120,6 +120,9 @@
}
}

/**
* @param array{allocationSize: int} $definition
*/
private function addSequenceGenerator(ClassMetadata $classMetadata, EntityManagerInterface $em, array $definition): void
{
$sequenceGenerator = new SequenceGenerator(
Expand Down
2 changes: 0 additions & 2 deletions src/Migration/IdToUuidMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Types;
Expand Down Expand Up @@ -475,7 +474,6 @@ private function restoreConstraintsAndIndexes(): void
*/
private function hasCombinedPrimaryKey(array $foreignKey): bool
{
/** @var Column $key */
foreach ($foreignKey['primaryKey'] as $key) {
if ($key === $foreignKey['key']) {
return true;
Expand Down
5 changes: 5 additions & 0 deletions src/Test/ORM/EntityManagerMockFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\QueryBuilder;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -74,6 +75,10 @@
*/
private static function prepareMetadata(TestCase $test, array $fields): MockObject
{
if (class_exists(EntityManager::class)) {
return $test->createMock(ClassMetadata::class);

Check warning on line 79 in src/Test/ORM/EntityManagerMockFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Test/ORM/EntityManagerMockFactory.php#L78-L79

Added lines #L78 - L79 were not covered by tests
}

$metadata = $test->getMockBuilder(ClassMetadataInfo::class)->disableOriginalConstructor()->getMock();
$metadata->method('getFieldNames')->willReturn($fields);
$metadata->method('getName')->willReturn('className');
Expand Down