8000 Fix Doctrine deprecations · symfony/symfony@58e449f · GitHub
[go: up one dir, main page]

Skip to content

Commit 58e449f

Browse files
Fix Doctrine deprecations
1 parent 094729f commit 58e449f

File tree

64 files changed

+477
-82
lines changed
  • Tests
  • Component
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    64 files changed

    +477
    -82
    lines changed

    src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php

    Lines changed: 4 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -11,6 +11,7 @@
    1111

    1212
    namespace Symfony\Bridge\Doctrine\Form\ChoiceList;
    1313

    14+
    use Doctrine\DBAL\ArrayParameterType;
    1415
    use Doctrine\DBAL\Connection;
    1516
    use Doctrine\DBAL\Types\ConversionException;
    1617
    use Doctrine\DBAL\Types\Type;
    @@ -78,15 +79,15 @@ public function getEntitiesByIds(string $identifier, array $values)
    7879
    $entity = current($qb->getRootEntities());
    7980
    $metadata = $qb->getEntityManager()->getClassMetadata($entity);
    8081
    if (\in_array($type = $metadata->getTypeOfField($identifier), ['integer', 'bigint', 'smallint'])) {
    81-
    $parameterType = Connection::PARAM_INT_ARRAY;
    82+
    $parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY;
    8283

    8384
    // Filter out non-integer values (e.g. ""). If we don't, some
    8485
    // databases such as PostgreSQL fail.
    8586
    $values = array_values(array_filter($values, function ($v) {
    8687
    return (string) $v === (string) (int) $v || ctype_digit($v);
    8788
    }));
    8889
    } elseif (\in_array($type, ['ulid', 'uuid', 'guid'])) {
    89-
    $parameterType = Connection::PARAM_STR_ARRAY;
    90+
    $parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY;
    9091

    9192
    // Like above, but we just filter out empty strings.
    9293
    $values = array_values(array_filter($values, function ($v) {
    @@ -107,7 +108,7 @@ public function getEntitiesByIds(string $identifier, array $values)
    107108
    unset($value);
    108109
    }
    109110
    } else {
    110-
    $parameterType = Connection::PARAM_STR_ARRAY;
    111+
    $parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY;
    111112
    }
    112113
    if (!$values) {
    113114
    return [];

    src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php

    Lines changed: 21 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -12,10 +12,14 @@
    1212
    namespace Symfony\Bridge\Doctrine\Test;
    1313

    1414
    use Doctrine\Common\Annotations\AnnotationReader;
    15+
    use Doctrine\DBAL\DriverManager;
    16+
    use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
    1517
    use Doctrine\ORM\Configuration;
    1618
    use Doctrine\ORM\EntityManager;
    1719
    use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
    20+
    use Doctrine\ORM\Mapping\Driver\AttributeDriver;
    1821
    use Doctrine\ORM\Mapping\Driver\XmlDriver;
    22+
    use Doctrine\ORM\ORMSetup;
    1923
    use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
    2024
    use Doctrine\Persistence\Mapping\Driver\SymfonyFileLocator;
    2125
    use PHPUnit\Framework\TestCase;
    @@ -53,7 +57,11 @@ public static function createTestEntityManager(Configuration $config = null)
    5357
    'memory' => true,
    5458
    ];
    5559

    56-
    return EntityManager::create($params, $config);
    60+
    if (!(new \ReflectionMethod(EntityManager::class, '__construct'))->isPublic()) {
    61+
    return EntityManager::create($params, $config);
    62+
    }
    63+
    64+
    return new EntityManager(DriverManager::getConnection($params, $config), $config);
    5765
    }
    5866

    5967
    /**
    @@ -65,12 +73,19 @@ public static function createTestConfiguration()
    6573
    trigger_deprecation('symfony/doctrine-bridge', '5.3', '"%s" is deprecated and will be removed in 6.0.', __CLASS__);
    6674
    }
    6775

    68-
    $config = new Configuration();
    76+
    $config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
    6977
    $config->setEntityNamespaces(['SymfonyTestsDoctrine' => 'Symfony\Bridge\Doctrine\Tests\Fixtures']);
    7078
    $config->setAutoGenerateProxyClasses(true);
    7179
    $config->setProxyDir(sys_get_temp_dir());
    7280
    $config->setProxyNamespace('SymfonyTests\Doctrine');
    73-
    $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
    81+
    if (\PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) {
    82+
    $config->setMetadataDriverImpl(new AttributeDriver([__DIR__.'/../Tests/Fixtures' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'], true));
    83+
    } else {
    84+
    $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), null, true));
    85+
    }
    86+
    if (class_exists(DefaultSchemaManagerFactory::class)) {
    87+
    $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
    88+
    }
    7489

    7590
    return $config;
    7691
    }
    @@ -91,7 +106,9 @@ public static function createTestConfigurationWithXmlLoader()
    91106
    new XmlDriver(
    92107
    new SymfonyFileLocator(
    93108
    [__DIR__.'/../Tests/Resources/orm' => 'Symfony\\Bridge\\Doctrine\\Tests\\Fixtures'], '.orm.xml'
    94-
    )
    109+
    ),
    110+
    '.orm.xml',
    111+
    true
    95112
    ),
    96113
    'Symfony\\Bridge\\Doctrine\\Tests\\Fixtures'
    97114
    );

    src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php

    Lines changed: 5 additions & 5 deletions
    Original file line numberDiff line numberDiff line change
    @@ -190,7 +190,7 @@ public function testMappingTypeDetection()
    190190

    191191
    // The ordinary fixtures contain annotation
    192192
    $mappingType = $method->invoke($this->extension, __DIR__.'/../Fixtures', $container);
    193-
    $this->assertSame($mappingType, 'annotation');
    193+
    $this->assertSame($mappingType, \PHP_VERSION_ID < 80000 ? 'annotation' : 'attribute');
    194194

    195195
    // In the attribute folder, attributes are used
    196196
    $mappingType = $method->invoke($this->extension, __DIR__.'/../Fixtures/Attribute', $container);
    @@ -278,9 +278,9 @@ public function testUnrecognizedCacheDriverException()
    278278

    279279
    public static function providerBundles()
    280280
    {
    281-
    yield ['AnnotationsBundle', 'annotation', '/Entity'];
    282-
    yield ['AnnotationsOneLineBundle', 'annotation', '/Entity'];
    283-
    yield ['FullEmbeddableAnnotationsBundle', 'annotation', '/Entity'];
    281+
    yield ['AnnotationsBundle', \PHP_VERSION_ID < 80000 ? 'annotation' : 'attribute', '/Entity'];
    282+
    yield ['AnnotationsOneLineBundle', \PHP_VERSION_ID < 80000 ? 'annotation' : 'attribute', '/Entity'];
    283+
    yield ['FullEmbeddableAnnotationsBundle', \PHP_VERSION_ID < 80000 ? 'annotation' : 'attribute', '/Entity'];
    284284
    if (\PHP_VERSION_ID >= 80000) {
    285285
    yield ['AttributesBundle', 'attribute', '/Entity'];
    286286
    yield ['FullEmbeddableAttributesBundle', 'attribute', '/Entity'];
    @@ -291,7 +291,7 @@ public static function providerBundles()
    291291

    292292
    yield ['SrcXmlBundle', 'xml', '/Resources/config/doctrine'];
    293293

    294-
    yield ['NewAnnotationsBundle', 'annotation', \DIRECTORY_SEPARATOR.'src/Entity'];
    294+
    yield ['NewAnnotationsBundle', \PHP_VERSION_ID < 80000 ? 'annotation' : 'attribute', \DIRECTORY_SEPARATOR.'src/Entity'];
    295295
    yield ['NewXmlBundle', 'xml', '/config/doctrine'];
    296296
    }
    297297

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationEntity.php

    Lines changed: 6 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -16,20 +16,23 @@
    1616
    /**
    1717
    * @ORM\Entity
    1818
    */
    19+
    #[ORM\Entity]
    1920
    class AssociationEntity
    2021
    {
    2122
    /**
    2223
    * @var int
    2324
    * @ORM\Id @ORM\GeneratedValue
    2425
    * @ORM\Column(type="integer")
    2526
    */
    27+
    #[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')]
    2628
    private $id;
    2729

    2830
    /**
    2931
    * @ORM\ManyToOne(targetEntity="SingleIntIdEntity")
    3032
    *
    3133
    * @var \Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity
    3234
    */
    35+
    #[ORM\ManyToOne(targetEntity: SingleIntIdEntity::class)]
    3336
    public $single;
    3437

    3538
    /**
    @@ -41,5 +44,8 @@ class AssociationEntity
    4144
    *
    4245
    * @var \Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity
    4346
    */
    47+
    #[ORM\ManyToOne(targetEntity: CompositeIntIdEntity::class)]
    48+
    #[ORM\JoinColumn(name: 'composite_id1', referencedColumnName: 'id1')]
    49+
    #[ORM\JoinColumn(name: 'composite_id2', referencedColumnName: 'id2')]
    4450
    public $composite;
    4551
    }

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationEntity2.php

    Lines changed: 6 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -16,20 +16,23 @@
    1616
    /**
    1717
    * @ORM\Entity
    1818
    */
    19+
    #[ORM\Entity]
    1920
    class AssociationEntity2
    2021
    {
    2122
    /**
    2223
    * @var int
    2324
    * @ORM\Id @ORM\GeneratedValue
    2425
    * @ORM\Column(type="integer")
    2526
    */
    27+
    #[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')]
    2628
    private $id;
    2729

    2830
    /**
    2931
    * @ORM\ManyToOne(targetEntity="SingleIntIdNoToStringEntity")
    3032
    *
    3133
    * @var \Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity
    3234
    */
    35+
    #[ORM\ManyToOne(targetEntity: SingleIntIdNoToStringEntity::class)]
    3336
    public $single;
    3437

    3538
    /**
    @@ -41,5 +44,8 @@ class AssociationEntity2
    4144
    *
    4245
    * @var \Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity
    4346
    */
    47+
    #[ORM\ManyToOne(targetEntity: CompositeIntIdEntity::class)]
    48+
    #[ORM\JoinColumn(name: 'composite_id1', referencedColumnName: 'id1')]
    49+
    #[ORM\JoinColumn(name: 'composite_id2', referencedColumnName: 'id2')]
    4450
    public $composite;
    4551
    }

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AnnotationsBundle/Entity/Person.php

    Lines changed: 3 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -18,12 +18,15 @@
    1818
    /**
    1919
    * @Entity
    2020
    */
    21+
    #[Entity]
    2122
    class Person
    2223
    {
    2324
    /** @Id @Column(type="integer") */
    25+
    #[Id, Column(type: 'integer')]
    2426
    protected $id;
    2527

    2628
    /** @Column(type="string") */
    29+
    #[Column(type: 'string')]
    2730
    public $name;
    2831

    2932
    public function __construct($id, $name)

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AnnotationsOneLineBundle/Entity/Person.php

    Lines changed: 3 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -16,12 +16,15 @@
    1616
    use Doctrine\ORM\Mapping\Id;
    1717

    1818
    /** @Entity */
    19+
    #[Entity]
    1920
    class Person
    2021
    {
    2122
    /** @Id @Column(type="integer") */
    23+
    #[Id, Column(type: 'integer')]
    2224
    protected $id;
    2325

    2426
    /** @Column(type="string") */
    27+
    #[Column(type: 'string')]
    2528
    public $name;
    2629

    2730
    public function __construct($id, $name)

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AttributesBundle/AnnotatedEntity/Person.php

    Lines changed: 3 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -18,12 +18,15 @@
    1818
    /**
    1919
    * @Entity
    2020
    */
    21+
    #[Entity]
    2122
    class Person
    2223
    {
    2324
    /** @Id @Column(type="integer") */
    25+
    #[Id, Column(type: 'integer')]
    2426
    protected $id;
    2527

    2628
    /** @Column(type="string") */
    29+
    #[Column(type: 'string')]
    2730
    public $name;
    2831

    2932
    public function __construct($id, $name)

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/FullEmbeddableAnnotationsBundle/Entity/Address.php

    Lines changed: 4 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -13,21 +13,24 @@
    1313

    1414
    use Doctrine\ORM\Mapping\Column;
    1515
    use Doctrine\ORM\Mapping\Embeddable;
    16-
    use Doctrine\ORM\Mapping\Id;
    1716

    1817
    /**
    1918
    * @Embeddable
    2019
    */
    20+
    #[Embeddable]
    2121
    class Address
    2222
    {
    2323

    2424
    /** @Column(type="string") */
    25+
    #[Column(type: 'string')]
    2526
    public $street;
    2627

    2728
    /** @Column(type="string") */
    29+
    #[Column(type: 'string')]
    2830
    public $zipCode;
    2931

    3032
    /** @Column(type="string") */
    33+
    #[Column(type: 'string')]
    3134
    public $city;
    3235

    3336
    public function __construct($street, $zipCode, $city)

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/FullEmbeddableAttributesBundle/Entity/Address.php

    Lines changed: 0 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -13,7 +13,6 @@
    1313

    1414
    use Doctrine\ORM\Mapping\Column;
    1515
    use Doctrine\ORM\Mapping\Embeddable;
    16-
    use Doctrine\ORM\Mapping\Id;
    1716

    1817
    #[Embeddable]
    1918
    class Address

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/NewAnnotationsBundle/src/Entity/Person.php

    Lines changed: 3 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -18,12 +18,15 @@
    1818
    /**
    1919
    * @Entity
    2020
    */
    21+
    #[Entity]
    2122
    class Person
    2223
    {
    2324
    /** @Id @Column(type="integer") */
    25+
    #[Id, Column(type: 'integer')]
    2426
    protected $id;
    2527

    2628
    /** @Column(type="string") */
    29+
    #[Column(type: 'string')]
    2730
    public $name;
    2831

    2932
    public function __construct($id, $name)

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeIntIdEntity.php

    Lines changed: 4 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -16,15 +16,19 @@
    1616
    use Doctrine\ORM\Mapping\Id;
    1717

    1818
    /** @Entity */
    19+
    #[Entity]
    1920
    class CompositeIntIdEntity
    2021
    {
    2122
    /** @Id @Column(type="integer") */
    23+
    #[Id, Column(type: 'integer')]
    2224
    protected $id1;
    2325

    2426
    /** @Id @Column(type="integer") */
    27+
    #[Id, Column(type: 'integer')]
    2528
    protected $id2;
    2629

    2730
    /** @Column(type="string") */
    31+
    #[Column(type: 'string')]
    2832
    public $name;
    2933

    3034
    public function __construct($id1, $id2, $name)

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeObjectNoToStringIdEntity.php

    Lines changed: 7 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -9,6 +9,7 @@
    99
    *
    1010
    * @ORM\Entity
    1111
    */
    12+
    #[ORM\Entity]
    1213
    class CompositeObjectNoToStringIdEntity
    1314
    {
    1415
    /**
    @@ -18,6 +19,9 @@ class CompositeObjectNoToStringIdEntity
    1819
    * @ORM\ManyToOne(targetEntity="SingleIntIdNoToStringEntity", cascade={"persist"})
    1920
    * @ORM\JoinColumn(name="object_one_id")
    2021
    */
    22+
    #[ORM\Id]
    23+
    #[ORM\ManyToOne(targetEntity: SingleIntIdNoToStringEntity::class, cascade: ['persist'])]
    24+
    #[ORM\JoinColumn(name: 'object_one_id')]
    2125
    protected $objectOne;
    2226

    2327
    /**
    @@ -27,6 +31,9 @@ class CompositeObjectNoToStringIdEntity
    2731
    * @ORM\ManyToOne(targetEntity="SingleIntIdNoToStringEntity", cascade={"persist"})
    2832
    * @ORM\JoinColumn(name="object_two_id")
    2933
    */
    34+
    #[ORM\Id]
    35+
    #[ORM\ManyToOne(targetEntity: SingleIntIdNoToStringEntity::class, cascade: ['persist'])]
    36+
    #[ORM\JoinColumn(name: 'object_two_id')]
    3037
    protected $objectTwo;
    3138

    3239
    public function __construct(SingleIntIdNoToStringEntity $objectOne, SingleIntIdNoToStringEntity $objectTwo)

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeStringIdEntity.php

    Lines changed: 4 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -16,15 +16,19 @@
    1616
    use Doctrine\ORM\Mapping\Id;
    1717

    1818
    /** @Entity */
    19+
    #[Entity]
    1920
    class CompositeStringIdEntity
    2021
    {
    2122
    /** @Id @Column(type="string") */
    23+
    #[Id, Column(type: 'string')]
    2224
    protected $id1;
    2325

    2426
    /** @Id @Column(type="string") */
    27+
    #[Id, Column(type: 'string')]
    2528
    protected $id2;
    2629

    2730
    /** @Column(type="string") */
    31+
    #[Column(type: 'string')]
    2832
    public $name;
    2933

    3034
    public function __construct($id1, $id2, $name)

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoctrineLoaderEmbed.php

    Lines changed: 3 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -16,15 +16,18 @@
    1616
    /**
    1717
    * @ORM\Embeddable
    1818
    */
    19+
    #[ORM\Embeddable]
    1920
    class DoctrineLoaderEmbed
    2021
    {
    2122
    /**
    2223
    * @ORM\Column(length=25)
    2324
    */
    25+
    #[ORM\Column(length: 25)]
    2426
    public $embeddedMaxLength;
    2527

    2628
    /**
    2729
    * @ORM\Embedded(class=DoctrineLoaderNestedEmbed::class)
    2830
    */
    31+
    #[ORM\Embedded(class: DoctrineLoaderNestedEmbed::class)]
    2932
    public $nestedEmbedded;
    3033
    }

    0 commit comments

    Comments
     (0)
    0