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

Restrict Doctrine orm package version #945

Merged
merged 1 commit into from
Sep 25, 2024
Merged
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
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.0",
"doctrine/orm": "^2.5",
"doctrine/orm": "^2.18",
"friendsofsymfony/rest-bundle": "^3.0",
"jms/serializer-bundle": "^3.5 || ^4.0 || ^5.0",
"lchrusciel/api-test-case": "^5.0",
@@ -89,14 +89,15 @@
"willdurand/hateoas-bundle": "^2.0"
},
"conflict": {
"doctrine/orm": "<2.18 || ^3.0",
"doctrine/doctrine-bundle": "<2.0 || ^3.0",
"friendsofsymfony/rest-bundle": "<3.0",
"jms/serializer-bundle": "<3.5",
"willdurand/hateoas-bundle": "<2.0 || ^2.6",
"twig/twig": "<3.0"
},
"suggest": {
"doctrine/orm": "^2.5",
"doctrine/orm": "^2.20",
"sylius/locale": "^1.0"
},
"config": {
6 changes: 3 additions & 3 deletions src/Bundle/Doctrine/ORM/Form/Builder/DefaultFormBuilder.php
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Sylius\Bundle\ResourceBundle\Form\Builder\DefaultFormBuilderInterface;
use Sylius\Resource\Metadata\MetadataInterface;
use Symfony\Component\Form\FormBuilderInterface;
@@ -41,7 +41,7 @@ public function build(MetadataInterface $metadata, FormBuilderInterface $formBui
$this->doBuild($classMetadata, $formBuilder);
}

private function doBuild(ClassMetadataInfo $classMetadata, FormBuilderInterface $formBuilder): void
private function doBuild(ClassMetadata $classMetadata, FormBuilderInterface $formBuilder): void
{
$fields = $classMetadata->fieldNames;

@@ -79,7 +79,7 @@ private function doBuild(ClassMetadataInfo $classMetadata, FormBuilderInterface
}

foreach ($classMetadata->getAssociationMappings() as $fieldName => $associationMapping) {
if (ClassMetadataInfo::ONE_TO_MANY !== $associationMapping['type']) {
if (ClassMetadata::ONE_TO_MANY !== $associationMapping['type']) {
$formBuilder->add($fieldName, null, ['choice_label' => 'id']);
}
}
11 changes: 5 additions & 6 deletions src/Bundle/EventListener/ORMMappedSuperClassSubscriber.php
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Webmozart\Assert\Assert;

@@ -45,7 +44,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
}
}

private function setAssociationMappings(ClassMetadataInfo $metadata, Configuration $configuration): void
private function setAssociationMappings(ClassMetadata $metadata, Configuration $configuration): void
{
$class = $metadata->getName();
if (!class_exists($class)) {
@@ -90,7 +89,7 @@ private function setAssociationMappings(ClassMetadataInfo $metadata, Configurati
}
}

private function unsetAssociationMappings(ClassMetadataInfo $metadata): void
private function unsetAssociationMappings(ClassMetadata $metadata): void
{
/** @psalm-suppress InvalidArgument */
if (false === $this->isResource($metadata)) {
@@ -109,9 +108,9 @@ private function isRelation(int $type): bool
return in_array(
$type,
[
ClassMetadataInfo::MANY_TO_MANY,
ClassMetadataInfo::ONE_TO_MANY,
ClassMetadataInfo::ONE_TO_ONE,
ClassMetadata::MANY_TO_MANY,
ClassMetadata::ONE_TO_MANY,
ClassMetadata::ONE_TO_ONE,
],
true,
);
3 changes: 1 addition & 2 deletions src/Bundle/EventListener/ORMTranslatableListener.php
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
use Doctrine\ORM\Event\PostLoadEventArgs;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Sylius\Resource\Metadata\MetadataInterface;
use Sylius\Resource\Metadata\RegistryInterface;
use Sylius\Resource\Model\TranslatableInterface;
@@ -108,7 +107,7 @@ private function mapTranslatable(ClassMetadata $metadata): void
'fieldName' => 'translations',
'targetEntity' => $translationResourceMetadata->getClass('model'),
'mappedBy' => 'translatable',
'fetch' => ClassMetadataInfo::FETCH_EXTRA_LAZY,
'fetch' => ClassMetadata::FETCH_EXTRA_LAZY,
'indexBy' => 'locale',
'cascade' => ['persist', 'merge', 'remove'],
'orphanRemoval' => true,
124 changes: 62 additions & 62 deletions src/Bundle/spec/Doctrine/ORM/Form/Builder/DefaultFormBuilderSpec.php
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Bundle\ResourceBundle\Form\Builder\DefaultFormBuilderInterface;
@@ -38,11 +38,11 @@ function it_does_not_support_entities_with_multiple_primary_keys(
MetadataInterface $metadata,
FormBuilderInterface $formBuilder,
EntityManagerInterface $entityManager,
ClassMetadataInfo $classMetadataInfo,
ClassMetadata $classMetadata,
): void {
$metadata->getClass('model')->willReturn('AppBundle\Entity\Book');
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadataInfo);
$classMetadataInfo->identifier = ['id', 'slug'];
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadata);
$classMetadata->identifier = ['id', 'slug'];

$this
->shouldThrow(\RuntimeException::class)
@@ -54,18 +54,18 @@ function it_excludes_non_natural_identifier_from_the_field_list(
MetadataInterface $metadata,
FormBuilderInterface $formBuilder,
EntityManagerInterface $entityManager,
ClassMetadataInfo $classMetadataInfo,
ClassMetadata $classMetadata,
): void {
$metadata->getClass('model')->willReturn('AppBundle\Entity\Book');
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadataInfo);
$classMetadataInfo->fieldNames = ['id', 'name', 'description', 'enabled'];
$classMetadataInfo->identifier = ['id'];
$classMetadataInfo->isIdentifierNatural()->willReturn(false);
$classMetadataInfo->getAssociationMappings()->willReturn([]);
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadata);
$classMetadata->fieldNames = ['id', 'name', 'description', 'enabled'];
$classMetadata->identifier = ['id'];
$classMetadata->isIdentifierNatural()->willReturn(false);
$classMetadata->getAssociationMappings()->willReturn([]);

$classMetadataInfo->getTypeOfField('name')->willReturn(Types::STRING);
$classMetadataInfo->getTypeOfField('description')->willReturn(Types::TEXT);
$classMetadataInfo->getTypeOfField('enabled')->willReturn(Types::BOOLEAN);
$classMetadata->getTypeOfField('name')->willReturn(Types::STRING);
$classMetadata->getTypeOfField('description')->willReturn(Types::TEXT);
$classMetadata->getTypeOfField('enabled')->willReturn(Types::BOOLEAN);

$formBuilder->add('name', null, [])->willReturn($formBuilder);
$formBuilder->add('description', null, [])->willReturn($formBuilder);
@@ -83,19 +83,19 @@ function it_does_not_exclude_natural_identifier_from_the_field_list(
MetadataInterface $metadata,
FormBuilderInterface $formBuilder,
EntityManagerInterface $entityManager,
ClassMetadataInfo $classMetadataInfo,
ClassMetadata $classMetadata,
): void {
$metadata->getClass('model')->willReturn('AppBundle\Entity\Book');
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadataInfo);
$classMetadataInfo->fieldNames = ['id', 'name', 'description', 'enabled'];
$classMetadataInfo->identifier = ['id'];
$classMetadataInfo->isIdentifierNatural()->willReturn(true);
$classMetadataInfo->getAssociationMappings()->willReturn([]);
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadata);
$classMetadata->fieldNames = ['id', 'name', 'description', 'enabled'];
$classMetadata->identifier = ['id'];
$classMetadata->isIdentifierNatural()->willReturn(true);
$classMetadata->getAssociationMappings()->willReturn([]);

$classMetadataInfo->getTypeOfField('id')->willReturn(Types::INTEGER);
$classMetadataInfo->getTypeOfField('name')->willReturn(Types::STRING);
$classMetadataInfo->getTypeOfField('description')->willReturn(Types::TEXT);
$classMetadataInfo->getTypeOfField('enabled')->willReturn(Types::BOOLEAN);
$classMetadata->getTypeOfField('id')->willReturn(Types::INTEGER);
$classMetadata->getTypeOfField('name')->willReturn(Types::STRING);
$classMetadata->getTypeOfField('description')->willReturn(Types::TEXT);
$classMetadata->getTypeOfField('enabled')->willReturn(Types::BOOLEAN);

$formBuilder->add('id', null, [])->willReturn($formBuilder);
$formBuilder->add('name', null, [])->willReturn($formBuilder);
@@ -114,17 +114,17 @@ function it_uses_metadata_to_create_appropriate_fields(
MetadataInterface $metadata,
FormBuilderInterface $formBuilder,
EntityManagerInterface $entityManager,
ClassMetadataInfo $classMetadataInfo,
ClassMetadata $classMetadata,
): void {
$metadata->getClass('model')->willReturn('AppBundle\Entity\Book');
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadataInfo);
$classMetadataInfo->fieldNames = ['name', 'description', 'enabled'];
$classMetadataInfo->isIdentifierNatural()->willReturn(true);
$classMetadataInfo->getAssociationMappings()->willReturn([]);
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadata);
$classMetadata->fieldNames = ['name', 'description', 'enabled'];
$classMetadata->isIdentifierNatural()->willReturn(true);
$classMetadata->getAssociationMappings()->willReturn([]);

$classMetadataInfo->getTypeOfField('name')->willReturn(Types::STRING);
$classMetadataInfo->getTypeOfField('description')->willReturn(Types::TEXT);
$classMetadataInfo->getTypeOfField('enabled')->willReturn(Types::BOOLEAN);
$classMetadata->getTypeOfField('name')->willReturn(Types::STRING);
$classMetadata->getTypeOfField('description')->willReturn(Types::TEXT);
$classMetadata->getTypeOfField('enabled')->willReturn(Types::BOOLEAN);

$formBuilder->add('name', null, [])->willReturn($formBuilder);
$formBuilder->add('description', null, [])->willReturn($formBuilder);
@@ -141,18 +141,18 @@ function it_uses_single_text_widget_for_datetime_field(
MetadataInterface $metadata,
FormBuilderInterface $formBuilder,
EntityManagerInterface $entityManager,
ClassMetadataInfo $classMetadataInfo,
ClassMetadata $classMetadata,
): void {
$metadata->getClass('model')->willReturn('AppBundle\Entity\Book');
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadataInfo);
$classMetadataInfo->fieldNames = ['name', 'description', 'enabled', 'publishedAt'];
$classMetadataInfo->isIdentifierNatural()->willReturn(true);
$classMetadataInfo->getAssociationMappings()->willReturn([]);
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadata);
$classMetadata->fieldNames = ['name', 'description', 'enabled', 'publishedAt'];
$classMetadata->isIdentifierNatural()->willReturn(true);
$classMetadata->getAssociationMappings()->willReturn([]);

$classMetadataInfo->getTypeOfField('name')->willReturn(Types::STRING);
$classMetadataInfo->getTypeOfField('description')->willReturn(Types::TEXT);
$classMetadataInfo->getTypeOfField('enabled')->willReturn(Types::BOOLEAN);
$classMetadataInfo->getTypeOfField('publishedAt')->willReturn(Types::DATETIME_MUTABLE);
$classMetadata->getTypeOfField('name')->willReturn(Types::STRING);
$classMetadata->getTypeOfField('description')->willReturn(Types::TEXT);
$classMetadata->getTypeOfField('enabled')->willReturn(Types::BOOLEAN);
$classMetadata->getTypeOfField('publishedAt')->willReturn(Types::DATETIME_MUTABLE);

$formBuilder->add('name', null, [])->willReturn($formBuilder);
$formBuilder->add('description', null, [])->willReturn($formBuilder);
@@ -171,21 +171,21 @@ function it_also_creates_fields_for_relations_other_than_one_to_many(
MetadataInterface $metadata,
FormBuilderInterface $formBuilder,
EntityManagerInterface $entityManager,
ClassMetadataInfo $classMetadataInfo,
ClassMetadata $classMetadata,
): void {
$metadata->getClass('model')->willReturn('AppBundle\Entity\Book');
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadataInfo);
$classMetadataInfo->fieldNames = ['name', 'description', 'enabled', 'publishedAt'];
$classMetadataInfo->isIdentifierNatural()->willReturn(true);
$classMetadataInfo->getAssociationMappings()->willReturn([
'category' => ['type' => ClassMetadataInfo::MANY_TO_ONE],
'users' => ['type' => ClassMetadataInfo::ONE_TO_MANY],
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadata);
$classMetadata->fieldNames = ['name', 'description', 'enabled', 'publishedAt'];
$classMetadata->isIdentifierNatural()->willReturn(true);
$classMetadata->getAssociationMappings()->willReturn([
'category' => ['type' => ClassMetadata::MANY_TO_ONE],
'users' => ['type' => ClassMetadata::ONE_TO_MANY],
]);

$classMetadataInfo->getTypeOfField('name')->willReturn(Types::STRING);
$classMetadataInfo->getTypeOfField('description')->willReturn(Types::TEXT);
$classMetadataInfo->getTypeOfField('enabled')->willReturn(Types::BOOLEAN);
$classMetadataInfo->getTypeOfField('publishedAt')->willReturn(Types::DATETIME_MUTABLE);
$classMetadata->getTypeOfField('name')->willReturn(Types::STRING);
$classMetadata->getTypeOfField('description')->willReturn(Types::TEXT);
$classMetadata->getTypeOfField('enabled')->willReturn(Types::BOOLEAN);
$classMetadata->getTypeOfField('publishedAt')->willReturn(Types::DATETIME_MUTABLE);

$formBuilder->add('name', null, [])->willReturn($formBuilder);
$formBuilder->add('description', null, [])->willReturn($formBuilder);
@@ -208,19 +208,19 @@ function it_excludes_common_fields_like_createdAt_and_updatedAt(
MetadataInterface $metadata,
FormBuilderInterface $formBuilder,
EntityManagerInterface $entityManager,
ClassMetadataInfo $classMetadataInfo,
ClassMetadata $classMetadata,
): void {
$metadata->getClass('model')->willReturn('AppBundle\Entity\Book');
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadataInfo);
$classMetadataInfo->fieldNames = ['name', 'description', 'enabled', 'createdAt', 'updatedAt'];
$classMetadataInfo->isIdentifierNatural()->willReturn(true);
$classMetadataInfo->getAssociationMappings()->willReturn([]);

$classMetadataInfo->getTypeOfField('name')->willReturn(Types::STRING);
$classMetadataInfo->getTypeOfField('description')->willReturn(Types::TEXT);
$classMetadataInfo->getTypeOfField('enabled')->willReturn(Types::BOOLEAN);
$classMetadataInfo->getTypeOfField('createdAt')->willReturn(Types::DATETIME_MUTABLE);
$classMetadataInfo->getTypeOfField('updatedAt')->willReturn(Types::DATETIME_MUTABLE);
$entityManager->getClassMetadata('AppBundle\Entity\Book')->willReturn($classMetadata);
$classMetadata->fieldNames = ['name', 'description', 'enabled', 'createdAt', 'updatedAt'];
$classMetadata->isIdentifierNatural()->willReturn(true);
$classMetadata->getAssociationMappings()->willReturn([]);

$classMetadata->getTypeOfField('name')->willReturn(Types::STRING);
$classMetadata->getTypeOfField('description')->willReturn(Types::TEXT);
$classMetadata->getTypeOfField('enabled')->willReturn(Types::BOOLEAN);
$classMetadata->getTypeOfField('createdAt')->willReturn(Types::DATETIME_MUTABLE);
$classMetadata->getTypeOfField('updatedAt')->willReturn(Types::DATETIME_MUTABLE);

$formBuilder->add('name', null, [])->willReturn($formBuilder);
$formBuilder->add('description', null, [])->willReturn($formBuilder);
3 changes: 2 additions & 1 deletion src/Component/composer.json
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@
},
"require-dev": {
"behat/transliterator": "^1.3",
"doctrine/orm": "^2.5",
"doctrine/orm": "^2.18",
"matthiasnoback/symfony-dependency-injection-test": "^4.2.1 || ^5.1",
"phpspec/phpspec": "^7.3",
"phpspec/prophecy-phpunit": "^2.0",
@@ -59,6 +59,7 @@
"twig/twig": "^3.0"
},
"conflict": {
"doctrine/orm": "<2.18 || ^3.0",
"twig/twig": "<3.0"
},
"extra": {
5 changes: 2 additions & 3 deletions src/Component/src/Doctrine/Common/State/PersistProcessor.php
Original file line number Diff line number Diff line change
@@ -13,8 +13,7 @@

namespace Sylius\Resource\Doctrine\Common\State;

use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager as DoctrineObjectManager;
use Sylius\Resource\Context\Context;
@@ -60,7 +59,7 @@ private function getManager(object $data): ?DoctrineObjectManager
private function isDeferredExplicit(DoctrineObjectManager $manager, object $data): bool
{
$classMetadata = $manager->getClassMetadata($this->getObjectClass($data));
if (($classMetadata instanceof ClassMetadataInfo || $classMetadata instanceof ClassMetadata) && method_exists($classMetadata, 'isChangeTrackingDeferredExplicit')) {
if ($classMetadata instanceof ClassMetadata && method_exists($classMetadata, 'isChangeTrackingDeferredExplicit')) {
return $classMetadata->isChangeTrackingDeferredExplicit();
}

Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@

namespace Sylius\Resource\Tests\Doctrine\Common\State;

use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use PHPUnit\Framework\TestCase;
@@ -79,7 +79,7 @@ public function testItPersistsWhenDeferredExplicitly(): void
{
$manager = $this->prophesize(ObjectManager::class);
$operation = $this->prophesize(Operation::class);
$classMetadataInfo = $this->prophesize(ClassMetadataInfo::class);
$classMetadataInfo = $this->prophesize(ClassMetadata::class);
$data = new \stdClass();

$this->managerRegistry->getManagerForClass(\stdClass::class)->willReturn($manager);