Skip to content

Commit

Permalink
Restrict Doctrine orm package version
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Sep 24, 2024
1 parent e8f7349 commit 28c57c1
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 81 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions src/Bundle/Doctrine/ORM/Form/Builder/DefaultFormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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']);
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/Bundle/EventListener/ORMMappedSuperClassSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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,
);
Expand Down
3 changes: 1 addition & 2 deletions src/Bundle/EventListener/ORMTranslatableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
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
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Component/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -59,6 +59,7 @@
"twig/twig": "^3.0"
},
"conflict": {
"doctrine/orm": "<2.18 || ^3.0",
"twig/twig": "<3.0"
},
"extra": {
Expand Down
5 changes: 2 additions & 3 deletions src/Component/src/Doctrine/Common/State/PersistProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 28c57c1

Please sign in to comment.