8000 Fix Doctrine deprecations by nicolas-grekas · Pull Request #50524 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix Doctrine deprecations #50524

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

Merged
merged 1 commit into from
Jun 2, 2023
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
1,237 changes: 1,237 additions & 0 deletions .github/deprecations-baseline.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
< F438 table class=" diff-table js-diff-table tab-size " data-tab-size="8" data-diff-anchor="diff-4761c5069b46ce96f49d74476da61f43ced3abc73d22254cd95a2be0e250a593" data-paste-markdown-skip> Original file line number Diff line number Diff line change Expand Up @@ -28,7 +28,7 @@ jobs:
services: postgres: image: postgres:9.6-alpine image: postgres:10.6-alpine ports: - 5432:5432 env: Expand Down
1 change: 1 addition & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:

# Create local composer packages for each patched components and reference them in composer.json files when cross-testing components
if [[ ! "${{ matrix.mode }}" = *-deps ]]; then
echo SYMFONY_DEPRECATIONS_HELPER="baselineFile=$(pwd)/.github/deprecations-baseline.json" >> $GITHUB_ENV
php .github/build-packages.php HEAD^ $SYMFONY_VERSION src/Symfony/Bridge/PhpUnit
else
echo SYMFONY_DEPRECATIONS_HELPER=weak >> $GITHUB_ENV
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bridge\Doctrine\Form\ChoiceList;

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

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

// Like above, but we just filter out empty strings.
$values = array_values(array_filter($values, function ($v) {
Expand All @@ -107,7 +108,7 @@ public function getEntitiesByIds(string $identifier, array $values)
unset($value);
}
} else {
$parameterType = Connection::PARAM_STR_ARRAY;
$parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY;
}
if (!$values) {
return [];
Expand Down
25 changes: 21 additions & 4 deletions src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
namespace Symfony\Bridge\Doctrine\Test;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Doctrine\ORM\ORMSetup;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\Persistence\Mapping\Driver\SymfonyFileLocator;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -53,7 +57,11 @@ public static function createTestEntityManager(Configuration $config = null)
'memory' => true,
];

return EntityManager::create($params, $config);
if (!(new \ReflectionMethod(EntityManager::class, '__construct'))->isPublic()) {
return EntityManager::create($params, $config);
}

return new EntityManager(DriverManager::getConnection($params, $config), $config);
}

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

$config = new Configuration();
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
$config->setEntityNamespaces(['SymfonyTestsDoctrine' => 'Symfony\Bridge\Doctrine\Tests\Fixtures']);
$config->setAutoGenerateProxyClasses(true);
$config->setProxyDir(sys_get_temp_dir());
$config->setProxyNamespace('SymfonyTests\Doctrine');
$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
if (\PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) {
$config->setMetadataDriverImpl(new AttributeDriver([__DIR__.'/../Tests/Fixtures' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'], true));
} else {
$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), null, true));
}
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}

return $config;
}
Expand All @@ -91,7 +106,9 @@ public static function createTestConfigurationWithXmlLoader()
new XmlDriver(
new SymfonyFileLocator(
[__DIR__.'/../Tests/Resources/orm' => 'Symfony\\Bridge\\Doctrine\\Tests\\Fixtures'], '.orm.xml'
)
),
'.orm.xml',
true
),
'Symfony\\Bridge\\Doctrine\\Tests\\Fixtures'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function testMappingTypeDetection()

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

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

public static function providerBundles()
{
yield ['AnnotationsBundle', 'annotation', '/Entity'];
yield ['AnnotationsOneLineBundle', 'annotation', '/Entity'];
yield ['FullEmbeddableAnnotationsBundle', 'annotation', '/Entity'];
yield ['AnnotationsBundle', \PHP_VERSION_ID < 80000 ? 'annotation' : 'attribute', '/Entity'];
yield ['AnnotationsOneLineBundle', \PHP_VERSION_ID < 80000 ? 'annotation' : 'attribute', '/Entity'];
yield ['FullEmbeddableAnnotationsBundle', \PHP_VERSION_ID < 80000 ? 'annotation' : 'attribute', '/Entity'];
if (\PHP_VERSION_ID >= 80000) {
yield ['AttributesBundle', 'attribute', '/Entity'];
yield ['FullEmbeddableAttributesBundle', 'attribute', '/Entity'];
Expand All @@ -291,7 +291,7 @@ public static function providerBundles()

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@
/**
* @ORM\Entity
*/
#[ORM\Entity]
class AssociationEntity
{
/**
* @var int
* @ORM\Id @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
#[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')]
private $id;

/**
* @ORM\ManyToOne(targetEntity="SingleIntIdEntity")
*
* @var \Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity
*/
#[ORM\ManyToOne(targetEntity: SingleIntIdEntity::class)]
public $single;

/**
Expand All @@ -41,5 +44,8 @@ class AssociationEntity
*
* @var \Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity
*/
#[ORM\ManyToOne(targetEntity: CompositeIntIdEntity::class)]
#[ORM\JoinColumn(name: 'composite_id1', referencedColumnName: 'id1')]
#[ORM\JoinColumn(name: 'composite_id2', referencedColumnName: 'id2')]
public $composite;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@
/**
* @ORM\Entity
*/
#[ORM\Entity]
class AssociationEntity2
{
/**
* @var int
* @ORM\Id @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
#[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')]
private $id;

/**
* @ORM\ManyToOne(targetEntity="SingleIntIdNoToStringEntity")
*
* @var \Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity
*/
#[ORM\ManyToOne(targetEntity: SingleIntIdNoToStringEntity::class)]
public $single;

/**
Expand All @@ -41,5 +44,8 @@ class AssociationEntity2
*
* @var \Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity
*/
#[ORM\ManyToOne(targetEntity: CompositeIntIdEntity::class)]
#[ORM\JoinColumn(name: 'composite_id1', referencedColumnName: 'id1')]
#[ORM\JoinColumn(name: 'composite_id2', referencedColumnName: 'id2')]
public $composite;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
/**
* @Entity
*/
#[Entity]
class Person
{
/** @Id @Column(type="integer") */
#[Id, Column(type: 'integer')]
protected $id;

/** @Column(type="string") */
#[Column(type: 'string')]
public $name;

public function __construct($id, $name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
use Doctrine\ORM\Mapping\Id;

/** @Entity */
#[Entity]
class Person
{
/** @Id @Column(type="integer") */
#[Id, Column(type: 'integer')]
protected $id;

/** @Column(type="string") */
#[Column(type: 'string')]
public $name;

public function __construct($id, $name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
/**
* @Entity
*/
#[Entity]
class Person
{
/** @Id @Column(type="integer") */
#[Id, Column(type: 'integer')]
protected $id;

/** @Column(type="string") */
#[Column(type: 'string')]
public $name;

public function __construct($id, $name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Embeddable;
use Doctrine\ORM\Mapping\Id;

/**
* @Embeddable
*/
#[Embeddable]
class Address
{

/** @Column(type="string") */
#[Column(type: 'string')]
public $street;

/** @Column(type="string") */
#[Column(type: 'string')]
public $zipCode;

/** @Column(type="string") */
#[Column(type: 'string')]
public $city;

public function __construct($street, $zipCode, $city)
Expand Down
10000
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Embeddable;
use Doctrine\ORM\Mapping\Id;

#[Embeddable]
class Address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
/**
* @Entity
*/
#[Entity]
class Person
{
/** @Id @Column(type="integer") */
#[Id, Column(type: 'integer')]
protected $id;

/** @Column(type="string") */
#[Column(type: 'string')]
public $name;

public function __construct($id, $name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
use Doctrine\ORM\Mapping\Id;

/** @Entity */
#[Entity]
class CompositeIntIdEntity
{
/** @Id @Column(type="integer") */
#[Id, Column(type: 'integer')]
protected $id1;

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

/** @Column(type="string") */
#[Column(type: 'string')]
public $name;

public function __construct($id1, $id2, $name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* @ORM\Entity
*/
#[ORM\Entity]
class CompositeObjectNoToStringIdEntity
{
/**
Expand All @@ -18,6 +19,9 @@ class CompositeObjectNoToStringIdEntity
* @ORM\ManyToOne(targetEntity="SingleIntIdNoToStringEntity", cascade={"persist"})
* @ORM\JoinColumn(name="object_one_id")
*/
#[ORM\Id]
#[ORM\ManyToOne(targetEntity: SingleIntIdNoToStringEntity::class, cascade: ['persist'])]
#[ORM\JoinColumn(name: 'object_one_id')]
protected $objectOne;

/**
Expand All @@ -27,6 +31,9 @@ class CompositeObjectNoToStringIdEntity
* @ORM\ManyToOne(targetEntity="SingleIntIdNoToStringEntity", cascade={"persist"})
* @ORM\JoinColumn(name="object_two_id")
*/
#[ORM\Id]
#[ORM\ManyToOne(targetEntity: SingleIntIdNoToStringEntity::class, cascade: ['persist'])]
#[ORM\JoinColumn(name: 'object_two_id')]
protected $objectTwo;

public function __construct(SingleIntIdNoToStringEntity $objectOne, SingleIntIdNoToStringEntity $objectTwo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
use Doctrine\ORM\Mapping\Id;

/** @Entity */
#[Entity]
class CompositeStringIdEntity
{
/** @Id @Column(type="string") */
#[Id, Column(type: 'string')]
protected $id1;

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

/** @Column(type="string") */
#[Column(type: 'string')]
public $name;

public function __construct($id1, $id2, $name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
/**
* @ORM\Embeddable
*/
#[ORM\Embeddable]
class DoctrineLoaderEmbed
{
/**
* @ORM\Column(length=25)
*/
#[ORM\Column(length: 25)]
public $embeddedMaxLength;

/**
* @ORM\Embedded(class=DoctrineLoaderNestedEmbed::class)
*/
#[ORM\Embedded(class: DoctrineLoaderNestedEmbed::class)]
public $nestedEmbedded;
}
Loading
0