Skip to content

Commit b4128fd

Browse files
bug #50524 Fix Doctrine deprecations (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- Fix Doctrine deprecations | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #50481 | License | MIT | Doc PR | - Commits ------- 6a3a4d7 Fix Doctrine deprecations
2 parents 6c9f21b + 6a3a4d7 commit b4128fd

File tree

67 files changed

+1720
-83
lines changed

Some content is hidden

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

67 files changed

+1720
-83
lines changed

.github/deprecations-baseline.json

Lines changed: 1237 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828

2929
services:
3030
postgres:
31-
image: postgres:9.6-alpine
31+
image: postgres:10.6-alpine
3232
ports:
3333
- 5432:5432
3434
env:

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ jobs:
8989
9090
# Create local composer packages for each patched components and reference them in composer.json files when cross-testing components
9191
if [[ ! "${{ matrix.mode }}" = *-deps ]]; then
92+
echo SYMFONY_DEPRECATIONS_HELPER="baselineFile=$(pwd)/.github/deprecations-baseline.json" >> $GITHUB_ENV
9293
php .github/build-packages.php HEAD^ $SYMFONY_VERSION src/Symfony/Bridge/PhpUnit
9394
else
9495
echo SYMFONY_DEPRECATIONS_HELPER=weak >> $GITHUB_ENV

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)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy