Skip to content

[DoctrineBridge] Require ORM 2.15 #50576

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 8, 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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"doctrine/collections": "^1.0|^2.0",
"doctrine/data-fixtures": "^1.1",
"doctrine/dbal": "^2.13.1|^3.0",
"doctrine/orm": "^2.12",
"doctrine/orm": "^2.15",
"dragonmantank/cron-expression": "^3",
"egulias/email-validator": "^2.1.10|^3.1|^4",
"guzzlehttp/promises": "^1.4",
Expand Down Expand Up @@ -164,6 +164,7 @@
"async-aws/core": "<1.5",
"doctrine/annotations": "<1.13.1",
"doctrine/dbal": "<2.13.1",
"doctrine/orm": "<2.15",
"egulias/email-validator": "~3.0.0",
"masterminds/html5": "<2.6",
"phpdocumentor/reflection-docblock": "<5.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\Embedded;
use Doctrine\ORM\Mapping\MappingException as OrmMappingException;
use Doctrine\Persistence\Mapping\MappingException;
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
Expand Down Expand Up @@ -46,7 +45,7 @@ public function getProperties(string $class, array $context = []): ?array

$properties = array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());

if ($metadata instanceof ClassMetadataInfo && class_exists(Embedded::class) && $metadata->embeddedClasses) {
if ($metadata instanceof ClassMetadataInfo && $metadata->embeddedClasses) {
$properties = array_filter($properties, fn ($property) => !str_contains($property, '.'));

$properties = array_merge($properties, array_keys($metadata->embeddedClasses));
Expand Down Expand Up @@ -122,7 +121,7 @@ public function getTypes(string $class, string $property, array $context = []):
)];
}

if ($metadata instanceof ClassMetadataInfo && class_exists(Embedded::class) && isset($metadata->embeddedClasses[$property])) {
if ($metadata instanceof ClassMetadataInfo && isset($metadata->embeddedClasses[$property])) {
return [new Type(Type::BUILTIN_TYPE_OBJECT, false, $metadata->embeddedClasses[$property]['class'])];
}

Expand Down
7 changes: 1 addition & 6 deletions src/Symfony/Bridge/Doctrine/Tests/DoctrineTestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,14 @@ public static function createTestEntityManager(Configuration $config = null): En
];

$config ??= self::createTestConfiguration();

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

$eventManager = new EventManager();

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

public static function createTestConfiguration(): Configuration
{
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
$config = ORMSetup::createConfiguration(true);
$config->setEntityNamespaces(['SymfonyTestsDoctrine' => 'Symfony\Bridge\Doctrine\Tests\Fixtures']);
$config->setAutoGenerateProxyClasses(true);
$config->setProxyDir(sys_get_temp_dir());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\ORM\ORMSetup;
use PHPUnit\Framework\TestCase;
Expand All @@ -35,20 +34,16 @@
*/
class DoctrineExtractorTest extends TestCase
{
private function createExtractor()
private function createExtractor(): DoctrineExtractor
{
$config = ORMSetup::createConfiguration(true);
$config->setMetadataDriverImpl(new AttributeDriver([__DIR__.'/../Tests/Fixtures' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'], true));
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}

if (!(new \ReflectionMethod(EntityManager::class, '__construct'))->isPublic()) {
$entityManager = EntityManager::create(['driver' => 'pdo_sqlite'], $config);
} else {
$eventManager = new EventManager();
$entityManager = new EntityManager(DriverManager::getConnection(['driver' => 'pdo_sqlite'], $config, $eventManager), $config, $eventManager);
}
$eventManager = new EventManager();
$entityManager = new EntityManager(DriverManager::getConnection(['driver' => 'pdo_sqlite'], $config, $eventManager), $config, $eventManager);

if (!DBALType::hasType('foo')) {
DBALType::addType('foo', 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineFooType');
Expand Down Expand Up @@ -136,19 +131,16 @@ public function testExtractWithEmbedded()

public function testExtractEnum()
{
if (!property_exists(Column::class, 'enumType')) {
$this->markTestSkipped('The "enumType" requires doctrine/orm 2.11.');
}
$this->assertEquals([new Type(Type::BUILTIN_TYPE_OBJECT, false, EnumString::class)], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumString', []));
$this->assertEquals([new Type(Type::BUILTIN_TYPE_OBJECT, false, EnumInt::class)], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumInt', []));
$this->assertNull($this->createExtractor()->getTypes(DoctrineEnum::class, 'enumStringArray', []));
$this->assertEquals([new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, EnumInt::class))], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumIntArray', []));
$this->assertNull($this->createExtractor()->getTypes(DoctrineEnum::class, 'enumCustom', []));
}

public static function typesProvider()
public static function typesProvider(): array
{
$provider = [
return [
['id', [new Type(Type::BUILTIN_TYPE_INT)]],
['guid', [new Type(Type::BUILTIN_TYPE_STRING)]],
['bigint', [new Type(Type::BUILTIN_TYPE_STRING)]],
Expand Down Expand Up @@ -231,8 +223,6 @@ public static function typesProvider()
)]],
['json', null],
];

return $provider;
}

public function testGetPropertiesCatchException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bridge\Doctrine\Tests\Validator;

use Doctrine\ORM\Mapping\Column;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Tests\DoctrineTestHelper;
use Symfony\Bridge\Doctrine\Tests\Fixtures\BaseUser;
Expand Down Expand Up @@ -142,10 +141,6 @@ public function testLoadClassMetadata()

public function testExtractEnum()
{
if (!property_exists(Column::class, 'enumType')) {
$this->markTestSkipped('The "enumType" requires doctrine/orm 2.11.');
}

$validator = Validation::createValidatorBuilder()
->addMethodMapping('loadValidatorMetadata')
->enableAnnotationMapping(true)
Expand Down Expand Up @@ -195,7 +190,7 @@ public function testClassValidator(bool $expected, string $classValidatorRegexp
$this->assertSame($expected, $doctrineLoader->loadClassMetadata($classMetadata));
}

public static function regexpProvider()
public static function regexpProvider(): array
{
return [
[false, null],
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Doctrine/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
"doctrine/collections": "^1.0|^2.0",
"doctrine/data-fixtures": "^1.1",
"doctrine/dbal": "^2.13.1|^3.0",
"doctrine/orm": "^2.12",
"doctrine/orm": "^2.15",
"psr/log": "^1|^2|^3"
},
"conflict": {
"doctrine/annotations": "<1.13.1",
"doctrine/dbal": "<2.13.1",
"doctrine/lexer": "<1.1",
"doctrine/orm": "<2.12",
"doctrine/orm": "<2.15",
"symfony/cache": "<5.4",
"symfony/dependency-injection": "<6.2",
"symfony/form": "<5.4.21|>=6,<6.2.7",
Expand Down