mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Compare commits
62 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a541b8b3a | ||
|
|
9fb9cc46e4 | ||
|
|
c322c71cd4 | ||
|
|
3c733a2fee | ||
|
|
5984ad586a | ||
|
|
ee2c3a506b | ||
|
|
781ed30926 | ||
|
|
04694a9f7b | ||
|
|
257c5094c4 | ||
|
|
66e0e92816 | ||
|
|
5b2060e25f | ||
|
|
64444dcfd5 | ||
|
|
eb2cd5375c | ||
|
|
de7140e105 | ||
|
|
39e35fc06c | ||
|
|
7f061c3870 | ||
|
|
74495711fb | ||
|
|
97a7cb8d2f | ||
|
|
85d66de9df | ||
|
|
1b98be31ce | ||
|
|
61f2752a80 | ||
|
|
f3371e1773 | ||
|
|
6476894dc4 | ||
|
|
e0052390e1 | ||
|
|
8c6419e0e0 | ||
|
|
6f5ce1aca2 | ||
|
|
98e7a53b42 | ||
|
|
3aaaf37dfb | ||
|
|
154a4652ee | ||
|
|
ae7489ff19 | ||
|
|
0f32569a7a | ||
|
|
d99f74c704 | ||
|
|
62ca8424d8 | ||
|
|
3f2209a571 | ||
|
|
1ee01f4473 | ||
|
|
8a9ed138a8 | ||
|
|
e714b1a2fc | ||
|
|
ec0bf05853 | ||
|
|
dc58aa3ea1 | ||
|
|
23b74e4f8b | ||
|
|
d2b699e6f5 | ||
|
|
0338d69324 | ||
|
|
2c01dac173 | ||
|
|
137ecb491a | ||
|
|
f38ee09082 | ||
|
|
6ab858a5c5 | ||
|
|
3dca27ce0d | ||
|
|
e19704e1f8 | ||
|
|
41ea59ac66 | ||
|
|
e605e6d569 | ||
|
|
9437675d3b | ||
|
|
63409d638c | ||
|
|
9b9160b206 | ||
|
|
528b8837e1 | ||
|
|
4fb044d5f6 | ||
|
|
2a953c5e2b | ||
|
|
abc6a40ccb | ||
|
|
73e68f3c7d | ||
|
|
73777d0bd4 | ||
|
|
e89b58a13f | ||
|
|
2b94ec18b9 | ||
|
|
2a662149f4 |
@@ -12,38 +12,39 @@
|
||||
"upcoming": true
|
||||
},
|
||||
{
|
||||
"name": "3.5",
|
||||
"branchName": "3.5.x",
|
||||
"slug": "3.5",
|
||||
"name": "3.6",
|
||||
"branchName": "3.6.x",
|
||||
"slug": "3.6",
|
||||
"upcoming": true
|
||||
},
|
||||
{
|
||||
"name": "3.4",
|
||||
"branchName": "3.4.x",
|
||||
"slug": "3.4",
|
||||
"name": "3.5",
|
||||
"branchName": "3.5.x",
|
||||
"slug": "3.5",
|
||||
"current": true
|
||||
},
|
||||
{
|
||||
"name": "3.4",
|
||||
"slug": "3.4",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "3.3",
|
||||
"branchName": "3.3.x",
|
||||
"slug": "3.3",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "3.2",
|
||||
"branchName": "3.2.x",
|
||||
"slug": "3.2",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "3.1",
|
||||
"branchName": "3.1.x",
|
||||
"slug": "3.1",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "3.0",
|
||||
"branchName": "3.0.x",
|
||||
"slug": "3.0",
|
||||
"maintained": false
|
||||
},
|
||||
@@ -61,61 +62,51 @@
|
||||
},
|
||||
{
|
||||
"name": "2.19",
|
||||
"branchName": "2.19.x",
|
||||
"slug": "2.19",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "2.18",
|
||||
"branchName": "2.18.x",
|
||||
"slug": "2.18",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "2.17",
|
||||
"branchName": "2.17.x",
|
||||
"slug": "2.17",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "2.16",
|
||||
"branchName": "2.16.x",
|
||||
"slug": "2.16",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "2.15",
|
||||
"branchName": "2.15.x",
|
||||
"slug": "2.15",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "2.14",
|
||||
"branchName": "2.14.x",
|
||||
"slug": "2.14",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "2.13",
|
||||
"branchName": "2.13.x",
|
||||
"slug": "2.13",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "2.12",
|
||||
"branchName": "2.12.x",
|
||||
"slug": "2.12",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "2.11",
|
||||
"branchName": "2.11.x",
|
||||
"slug": "2.11",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "2.10",
|
||||
"branchName": "2.10.x",
|
||||
"slug": "2.10",
|
||||
"maintained": false
|
||||
}
|
||||
|
||||
2
.github/workflows/continuous-integration.yml
vendored
2
.github/workflows/continuous-integration.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: "Continuous Integration"
|
||||
name: "CI"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
19
README.md
19
README.md
@@ -1,7 +1,7 @@
|
||||
| [4.0.x][4.0] | [3.5.x][3.5] | [3.4.x][3.4] | [2.21.x][2.21] | [2.20.x][2.20] |
|
||||
| [4.0.x][4.0] | [3.6.x][3.6] | [3.5.x][3.5] | [2.21.x][2.21] | [2.20.x][2.20] |
|
||||
|:------------------------------------------------------:|:------------------------------------------------------:|:------------------------------------------------------:|:--------------------------------------------------------:|:--------------------------------------------------------:|
|
||||
| [![Build status][4.0 image]][4.0] | [![Build status][3.5 image]][3.5] | [![Build status][3.4 image]][3.4] | [![Build status][2.21 image]][2.21] | [![Build status][2.20 image]][2.20] |
|
||||
| [![Coverage Status][4.0 coverage image]][4.0 coverage] | [![Coverage Status][3.5 coverage image]][3.5 coverage] | [![Coverage Status][3.4 coverage image]][3.4 coverage] | [![Coverage Status][2.21 coverage image]][2.21 coverage] | [![Coverage Status][2.20 coverage image]][2.20 coverage] |
|
||||
| [![Build status][4.0 image]][4.0 workflow] | [![Build status][3.6 image]][3.6 workflow] | [![Build status][3.5 image]][3.5 workflow] | [![Build status][2.21 image]][2.21 workflow] | [![Build status][2.20 image]][2.20 workflow] |
|
||||
| [![Coverage Status][4.0 coverage image]][4.0 coverage] | [![Coverage Status][3.6 coverage image]][3.6 coverage] | [![Coverage Status][3.5 coverage image]][3.5 coverage] | [![Coverage Status][2.21 coverage image]][2.21 coverage] | [![Coverage Status][2.20 coverage image]][2.20 coverage] |
|
||||
|
||||
Doctrine ORM is an object-relational mapper for PHP 8.1+ that provides transparent persistence
|
||||
for PHP objects. It sits on top of a powerful database abstraction layer (DBAL). One of its key features
|
||||
@@ -18,21 +18,26 @@ without requiring unnecessary code duplication.
|
||||
|
||||
[4.0 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0.x
|
||||
[4.0]: https://github.com/doctrine/orm/tree/4.0.x
|
||||
[4.0 workflow]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml?query=branch%3A4.0.x
|
||||
[4.0 coverage image]: https://codecov.io/gh/doctrine/orm/branch/4.0.x/graph/badge.svg
|
||||
[4.0 coverage]: https://codecov.io/gh/doctrine/orm/branch/4.0.x
|
||||
[3.6 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.6.x
|
||||
[3.6]: https://github.com/doctrine/orm/tree/3.6.x
|
||||
[3.6 workflow]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml?query=branch%3A3.6.x
|
||||
[3.6 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.6.x/graph/badge.svg
|
||||
[3.6 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.6.x
|
||||
[3.5 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.5.x
|
||||
[3.5]: https://github.com/doctrine/orm/tree/3.5.x
|
||||
[3.5 workflow]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml?query=branch%3A3.5.x
|
||||
[3.5 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.5.x/graph/badge.svg
|
||||
[3.5 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.5.x
|
||||
[3.4 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.4.x
|
||||
[3.4]: https://github.com/doctrine/orm/tree/3.4.x
|
||||
[3.4 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.4.x/graph/badge.svg
|
||||
[3.4 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.4.x
|
||||
[2.21 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.21.x
|
||||
[2.21]: https://github.com/doctrine/orm/tree/2.21.x
|
||||
[2.21 workflow]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml?query=branch%3A2.21.x
|
||||
[2.21 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.21.x/graph/badge.svg
|
||||
[2.21 coverage]: https://codecov.io/gh/doctrine/orm/branch/2.21.x
|
||||
[2.20 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.20.x
|
||||
[2.20]: https://github.com/doctrine/orm/tree/2.20.x
|
||||
[2.20 workflow]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml?query=branch%3A2.20.x
|
||||
[2.20 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.20.x/graph/badge.svg
|
||||
[2.20 coverage]: https://codecov.io/gh/doctrine/orm/branch/2.20.x
|
||||
|
||||
@@ -69,6 +69,8 @@ that implements `ArrayAccess`.
|
||||
Use the new `Doctrine\ORM\Mapping\PropertyAccessors\PropertyAccessor` API and access
|
||||
through `Doctrine\ORM\Mapping\ClassMetadata::$propertyAccessors` instead.
|
||||
|
||||
Companion accessor methods are deprecated as well.
|
||||
|
||||
# Upgrade to 3.3
|
||||
|
||||
## Deprecate `DatabaseDriver`
|
||||
|
||||
@@ -46,17 +46,18 @@ entities:
|
||||
#[Entity]
|
||||
class Article
|
||||
{
|
||||
const STATUS_VISIBLE = 'visible';
|
||||
const STATUS_INVISIBLE = 'invisible';
|
||||
public const STATUS_VISIBLE = 'visible';
|
||||
public const STATUS_INVISIBLE = 'invisible';
|
||||
|
||||
#[Column(type: "string")]
|
||||
private $status;
|
||||
|
||||
public function setStatus($status)
|
||||
public function setStatus(string $status): void
|
||||
{
|
||||
if (!in_array($status, array(self::STATUS_VISIBLE, self::STATUS_INVISIBLE))) {
|
||||
if (!in_array($status, [self::STATUS_VISIBLE, self::STATUS_INVISIBLE], true)) {
|
||||
throw new \InvalidArgumentException("Invalid status");
|
||||
}
|
||||
|
||||
$this->status = $status;
|
||||
}
|
||||
}
|
||||
@@ -92,37 +93,33 @@ For example for the previous enum type:
|
||||
|
||||
class EnumVisibilityType extends Type
|
||||
{
|
||||
const ENUM_VISIBILITY = 'enumvisibility';
|
||||
const STATUS_VISIBLE = 'visible';
|
||||
const STATUS_INVISIBLE = 'invisible';
|
||||
private const ENUM_VISIBILITY = 'enumvisibility';
|
||||
private const STATUS_VISIBLE = 'visible';
|
||||
private const STATUS_INVISIBLE = 'invisible';
|
||||
|
||||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
|
||||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
|
||||
{
|
||||
return "ENUM('visible', 'invisible')";
|
||||
}
|
||||
|
||||
public function convertToPHPValue($value, AbstractPlatform $platform)
|
||||
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function convertToDatabaseValue($value, AbstractPlatform $platform)
|
||||
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): string
|
||||
{
|
||||
if (!in_array($value, array(self::STATUS_VISIBLE, self::STATUS_INVISIBLE))) {
|
||||
if (!in_array($value, [self::STATUS_VISIBLE, self::STATUS_INVISIBLE], true)) {
|
||||
throw new \InvalidArgumentException("Invalid status");
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return self::ENUM_VISIBILITY;
|
||||
}
|
||||
|
||||
public function requiresSQLCommentHint(AbstractPlatform $platform)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
You can register this type with ``Type::addType('enumvisibility', 'MyProject\DBAL\EnumVisibilityType');``.
|
||||
@@ -151,37 +148,33 @@ You can generalize this approach easily to create a base class for enums:
|
||||
abstract class EnumType extends Type
|
||||
{
|
||||
protected $name;
|
||||
protected $values = array();
|
||||
protected $values = [];
|
||||
|
||||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
|
||||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
|
||||
{
|
||||
$values = array_map(function($val) { return "'".$val."'"; }, $this->values);
|
||||
$values = array_map(fn($val) => "'".$val."'", $this->values);
|
||||
|
||||
return "ENUM(".implode(", ", $values).")";
|
||||
}
|
||||
|
||||
public function convertToPHPValue($value, AbstractPlatform $platform)
|
||||
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function convertToDatabaseValue($value, AbstractPlatform $platform)
|
||||
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): mixed
|
||||
{
|
||||
if (!in_array($value, $this->values)) {
|
||||
if (!in_array($value, $this->values, true)) {
|
||||
throw new \InvalidArgumentException("Invalid '".$this->name."' value.");
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function requiresSQLCommentHint(AbstractPlatform $platform)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
With this base class you can define an enum as easily as:
|
||||
@@ -194,5 +187,5 @@ With this base class you can define an enum as easily as:
|
||||
class EnumVisibilityType extends EnumType
|
||||
{
|
||||
protected $name = 'enumvisibility';
|
||||
protected $values = array('visible', 'invisible');
|
||||
protected $values = ['visible', 'invisible'];
|
||||
}
|
||||
|
||||
@@ -1333,51 +1333,45 @@ parameters:
|
||||
path: src/Mapping/Driver/AttributeDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:\:getReferencedColumnNames\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\DBAL\\\\Schema\\\\ForeignKeyConstraint'' and ''getReferencedColumn…'' will always evaluate to true\.$#'
|
||||
identifier: function.alreadyNarrowedType
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:\:getReferencedTableName\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\DBAL\\\\Schema\\\\ForeignKeyConstraint'' and ''getReferencedTableN…'' will always evaluate to true\.$#'
|
||||
identifier: function.alreadyNarrowedType
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:\:getReferencingColumnNames\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\DBAL\\\\Schema\\\\ForeignKeyConstraint'' and ''getReferencingColum…'' will always evaluate to true\.$#'
|
||||
identifier: function.alreadyNarrowedType
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\Index\:\:getIndexedColumns\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\DBAL\\\\Schema\\\\Index'' and ''getIndexedColumns'' will always evaluate to true\.$#'
|
||||
identifier: function.alreadyNarrowedType
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\Table\:\:getPrimaryKeyConstraint\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\DBAL\\\\Schema\\\\Table'' and ''getPrimaryKeyConstr…'' will always evaluate to true\.$#'
|
||||
identifier: function.alreadyNarrowedType
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to method getColumnName\(\) on an unknown class Doctrine\\DBAL\\Schema\\Index\\IndexedColumn\.$#'
|
||||
identifier: class.notFound
|
||||
message: '#^Call to function method_exists\(\) with Doctrine\\DBAL\\Schema\\Index and ''getType'' will always evaluate to true\.$#'
|
||||
identifier: function.alreadyNarrowedType
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to method getColumnNames\(\) on an unknown class Doctrine\\DBAL\\Schema\\PrimaryKeyConstraint\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to method toString\(\) on an unknown class Doctrine\\DBAL\\Schema\\Name\\UnqualifiedName\.$#'
|
||||
identifier: class.notFound
|
||||
count: 5
|
||||
message: '#^Call to function method_exists\(\) with Doctrine\\DBAL\\Schema\\Table and ''getPrimaryKeyConstr…'' will always evaluate to true\.$#'
|
||||
identifier: function.alreadyNarrowedType
|
||||
count: 2
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
@@ -1386,18 +1380,6 @@ parameters:
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Class Doctrine\\DBAL\\Schema\\Index\\IndexType not found\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Class Doctrine\\DBAL\\Schema\\PrimaryKeyConstraint not found\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Instanceof between Doctrine\\ORM\\Mapping\\ClassMetadata\<T of object\> and Doctrine\\ORM\\Mapping\\ClassMetadata will always evaluate to true\.$#'
|
||||
identifier: instanceof.alwaysTrue
|
||||
@@ -1434,30 +1416,12 @@ parameters:
|
||||
count: 2
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$array of function sort contains unresolvable type\.$#'
|
||||
identifier: argument.unresolvableType
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$columnName of method Doctrine\\ORM\\Mapping\\Driver\\DatabaseDriver\:\:getFieldNameForColumn\(\) expects string, string\|false given\.$#'
|
||||
identifier: argument.type
|
||||
count: 4
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \$indexedColumn of anonymous function has invalid type Doctrine\\DBAL\\Schema\\Index\\IndexedColumn\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \$name of anonymous function has invalid type Doctrine\\DBAL\\Schema\\Name\\UnqualifiedName\.$#'
|
||||
identifier: class.notFound
|
||||
count: 5
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\ORM\\Mapping\\Driver\\SimplifiedXmlDriver\:\:__construct\(\) has parameter \$fileExtension with no type specified\.$#'
|
||||
identifier: missingType.parameter
|
||||
@@ -2022,6 +1986,12 @@ parameters:
|
||||
count: 1
|
||||
path: src/Persisters/Collection/OneToManyPersister.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$columns of method Doctrine\\DBAL\\Platforms\\AbstractPlatform\:\:getColumnDeclarationListSQL\(\) expects list\<array\{name\: string, type\: Doctrine\\DBAL\\Types\\Type, default\: mixed, notnull\?\: bool, autoincrement\: bool, columnDefinition\: non\-empty\-string\|null, comment\: string, charset\?\: non\-empty\-string\|null, \.\.\.\}\>, array\<string, array\{name\: string, notnull\: true, type\: Doctrine\\DBAL\\Types\\Type\}\> given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Persisters/Collection/OneToManyPersister.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\ORM\\Persisters\\Entity\\AbstractEntityInheritancePersister\:\:getSelectColumnSQL\(\) has parameter \$class with generic class Doctrine\\ORM\\Mapping\\ClassMetadata but does not specify its types\: T$#'
|
||||
identifier: missingType.generics
|
||||
@@ -2610,6 +2580,12 @@ parameters:
|
||||
count: 1
|
||||
path: src/Query/Exec/MultiTableDeleteExecutor.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$columns of method Doctrine\\DBAL\\Platforms\\AbstractPlatform\:\:getColumnDeclarationListSQL\(\) expects list\<array\{name\: string, type\: Doctrine\\DBAL\\Types\\Type, default\: mixed, notnull\?\: bool, autoincrement\: bool, columnDefinition\: non\-empty\-string\|null, comment\: string, charset\?\: non\-empty\-string\|null, \.\.\.\}\>, array\<string, array\{name\: string, notnull\: true, type\: Doctrine\\DBAL\\Types\\Type\}\> given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Query/Exec/MultiTableDeleteExecutor.php
|
||||
|
||||
-
|
||||
message: '#^Argument of an invalid type list\<string\>\|string supplied for foreach, only iterables are supported\.$#'
|
||||
identifier: foreach.nonIterable
|
||||
@@ -2622,6 +2598,12 @@ parameters:
|
||||
count: 1
|
||||
path: src/Query/Exec/MultiTableUpdateExecutor.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$columns of method Doctrine\\DBAL\\Platforms\\AbstractPlatform\:\:getColumnDeclarationListSQL\(\) expects list\<array\{name\: string, type\: Doctrine\\DBAL\\Types\\Type, default\: mixed, notnull\?\: bool, autoincrement\: bool, columnDefinition\: non\-empty\-string\|null, comment\: string, charset\?\: non\-empty\-string\|null, \.\.\.\}\>, array\<string, array\{name\: string, notnull\: true, type\: Doctrine\\DBAL\\Types\\Type\}\> given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Query/Exec/MultiTableUpdateExecutor.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#3 \$types of method Doctrine\\DBAL\\Connection\:\:executeStatement\(\) expects array\<int\<0, max\>\|string, Doctrine\\DBAL\\ArrayParameterType\|Doctrine\\DBAL\\ParameterType\|Doctrine\\DBAL\\Types\\Type\|string\>, list\<Doctrine\\DBAL\\ArrayParameterType\|Doctrine\\DBAL\\ParameterType\|Doctrine\\DBAL\\Types\\Type\|int\|string\> given\.$#'
|
||||
identifier: argument.type
|
||||
@@ -3121,32 +3103,71 @@ parameters:
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:\:getReferencedColumnNames\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
message: '''
|
||||
#^Call to deprecated method getColumns\(\) of class Doctrine\\DBAL\\Schema\\Index\:
|
||||
Use \{@see getIndexedColumns\(\)\} instead\.$#
|
||||
'''
|
||||
identifier: method.deprecated
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:\:getReferencedTableName\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
message: '''
|
||||
#^Call to deprecated method getForeignColumns\(\) of class Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:
|
||||
Use \{@see getReferencedColumnNames\(\)\} instead\.
|
||||
|
||||
Returns the names of the referenced table columns
|
||||
the foreign key constraint is associated with\.$#
|
||||
'''
|
||||
identifier: method.deprecated
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:\:getReferencingColumnNames\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
message: '''
|
||||
#^Call to deprecated method getForeignTableName\(\) of class Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:
|
||||
Use \{@see getReferencedTableName\(\)\} instead\.
|
||||
|
||||
Returns the name of the referenced table
|
||||
the foreign key constraint is associated with\.$#
|
||||
'''
|
||||
identifier: method.deprecated
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\Index\:\:getIndexedColumns\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
message: '''
|
||||
#^Call to deprecated method getLocalColumns\(\) of class Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:
|
||||
Use \{@see getReferencingColumnNames\(\)\} instead\.$#
|
||||
'''
|
||||
identifier: method.deprecated
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\Table\:\:dropForeignKey\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
message: '''
|
||||
#^Call to deprecated method getPrimaryKey\(\) of class Doctrine\\DBAL\\Schema\\Table\:
|
||||
Use \{@see getPrimaryKeyConstraint\(\)\} instead\.$#
|
||||
'''
|
||||
identifier: method.deprecated
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '''
|
||||
#^Call to deprecated method removeForeignKey\(\) of class Doctrine\\DBAL\\Schema\\Table\:
|
||||
Use \{@link dropForeignKey\(\)\} instead\.$#
|
||||
'''
|
||||
identifier: method.deprecated
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '''
|
||||
#^Call to deprecated method setPrimaryKey\(\) of class Doctrine\\DBAL\\Schema\\Table\:
|
||||
Use \{@see addPrimaryKeyConstraint\(\)\} instead\.$#
|
||||
'''
|
||||
identifier: method.deprecated
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
@@ -3157,32 +3178,14 @@ parameters:
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to method getColumnName\(\) on an unknown class Doctrine\\DBAL\\Schema\\Index\\IndexedColumn\.$#'
|
||||
identifier: class.notFound
|
||||
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\DBAL\\\\Schema\\\\Index'' and ''getIndexedColumns'' will always evaluate to true\.$#'
|
||||
identifier: function.alreadyNarrowedType
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to method getColumnNames\(\) on an unknown class Doctrine\\DBAL\\Schema\\PrimaryKeyConstraint\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to method toString\(\) on an unknown class Doctrine\\DBAL\\Schema\\Name\\UnqualifiedName\.$#'
|
||||
identifier: class.notFound
|
||||
count: 3
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Class Doctrine\\DBAL\\Schema\\PrimaryKeyConstraint not found\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\DBAL\\Schema\\AbstractSchemaManager\<Doctrine\\DBAL\\Platforms\\AbstractPlatform\>\:\:createComparator\(\) invoked with 1 parameter, 0 required\.$#'
|
||||
identifier: arguments.count
|
||||
message: '#^Call to function method_exists\(\) with Doctrine\\DBAL\\Schema\\Table and ''getPrimaryKeyConstr…'' will always evaluate to true\.$#'
|
||||
identifier: function.alreadyNarrowedType
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
@@ -3289,15 +3292,51 @@ parameters:
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \$indexedColumn of anonymous function has invalid type Doctrine\\DBAL\\Schema\\Index\\IndexedColumn\.$#'
|
||||
identifier: class.notFound
|
||||
message: '#^Parameter \#1 \$columnNames of method Doctrine\\DBAL\\Schema\\Table\:\:addIndex\(\) expects non\-empty\-list\<string\>, list\<string\> given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \$name of anonymous function has invalid type Doctrine\\DBAL\\Schema\\Name\\UnqualifiedName\.$#'
|
||||
identifier: class.notFound
|
||||
count: 3
|
||||
message: '#^Parameter \#1 \$columnNames of method Doctrine\\DBAL\\Schema\\Table\:\:addUniqueIndex\(\) expects non\-empty\-list\<string\>, array\<string\> given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$columnNames of method Doctrine\\DBAL\\Schema\\Table\:\:setPrimaryKey\(\) expects non\-empty\-list\<string\>, array\<string\> given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$value of static method Doctrine\\DBAL\\Schema\\Name\\Identifier\:\:unquoted\(\) expects non\-empty\-string, string given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$columnNames of class Doctrine\\DBAL\\Schema\\PrimaryKeyConstraint constructor expects non\-empty\-list\<Doctrine\\DBAL\\Schema\\Name\\UnqualifiedName\>, list\<Doctrine\\DBAL\\Schema\\Name\\UnqualifiedName\> given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$columns of class Doctrine\\DBAL\\Schema\\Index constructor expects non\-empty\-list\<string\>, list\<string\> given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$localColumnNames of method Doctrine\\DBAL\\Schema\\Table\:\:addForeignKeyConstraint\(\) expects non\-empty\-list\<string\>, list\<string\> given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#3 \$foreignColumnNames of method Doctrine\\DBAL\\Schema\\Table\:\:addForeignKeyConstraint\(\) expects non\-empty\-list\<string\>, list\<string\> given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
|
||||
@@ -34,8 +34,58 @@ parameters:
|
||||
message: '~^Call to an undefined method Doctrine\\DBAL\\Schema\\Table::addPrimaryKeyConstraint\(\)\.$~'
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '~^Call to an undefined method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint::get.*\.$~'
|
||||
identifier: method.notFound
|
||||
|
||||
-
|
||||
message: '~createComparator~'
|
||||
identifier: arguments.count
|
||||
|
||||
-
|
||||
message: '~UnqualifiedName~'
|
||||
identifier: class.notFound
|
||||
|
||||
-
|
||||
message: '~IndexedColumn~'
|
||||
identifier: class.notFound
|
||||
|
||||
-
|
||||
message: '~PrimaryKeyConstraint~'
|
||||
identifier: class.notFound
|
||||
|
||||
-
|
||||
message: '~IndexType~'
|
||||
identifier: class.notFound
|
||||
|
||||
-
|
||||
message: '~dropForeignKey~'
|
||||
identifier: method.notFound
|
||||
|
||||
-
|
||||
message: '~getIndexedColumns~'
|
||||
identifier: method.notFound
|
||||
|
||||
-
|
||||
message: '~getPrimaryKeyConstraint~'
|
||||
identifier: method.notFound
|
||||
|
||||
-
|
||||
message: '~PrimaryKeyConstraint~'
|
||||
identifier: class.notFound
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '~^Call to method toString.*UnqualifiedName\.$~'
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
- '~^Class Doctrine\\DBAL\\Platforms\\SQLitePlatform not found\.$~'
|
||||
|
||||
-
|
||||
message: '~sort~'
|
||||
identifier: argument.unresolvableType
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
# To be removed in 4.0
|
||||
-
|
||||
message: '#Negated boolean expression is always false\.#'
|
||||
|
||||
12
phpstan.neon
12
phpstan.neon
@@ -20,18 +20,6 @@ parameters:
|
||||
message: '~^Method Doctrine\\ORM\\Persisters\\Entity\\BasicEntityPersister\:\:getArrayBindingType\(\) never returns .* so it can be removed from the return type\.$~'
|
||||
path: src/Persisters/Entity/BasicEntityPersister.php
|
||||
|
||||
-
|
||||
message: '~^Call to static method unquoted\(\) on an unknown class Doctrine\\DBAL\\Schema\\Name\\Identifier\.$~'
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '~^Instantiated class Doctrine\\DBAL\\Schema\\Name\\UnqualifiedName not found\.$~'
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '~^Call to an undefined method Doctrine\\DBAL\\Schema\\Table::addPrimaryKeyConstraint\(\)\.$~'
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
# Compatibility with DBAL 3
|
||||
# See https://github.com/doctrine/dbal/pull/3480
|
||||
-
|
||||
|
||||
@@ -652,17 +652,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
|
||||
public function isNativeLazyObjectsEnabled(): bool
|
||||
{
|
||||
$nativeLazyObjects = $this->attributes['nativeLazyObjects'] ?? false;
|
||||
|
||||
if (! $nativeLazyObjects && PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Not enabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0.',
|
||||
);
|
||||
}
|
||||
|
||||
return $nativeLazyObjects;
|
||||
return $this->attributes['nativeLazyObjects'] ?? false;
|
||||
}
|
||||
|
||||
public function enableNativeLazyObjects(bool $nativeLazyObjects): void
|
||||
|
||||
@@ -400,13 +400,9 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
public DiscriminatorColumnMapping|null $discriminatorColumn = null;
|
||||
|
||||
/**
|
||||
* READ-ONLY: The primary table definition. The definition is an array with the
|
||||
* following entries:
|
||||
* READ-ONLY: The primary table definition.
|
||||
*
|
||||
* name => <tableName>
|
||||
* schema => <schemaName>
|
||||
* indexes => array
|
||||
* uniqueConstraints => array
|
||||
* "quoted" indicates whether the table name is quoted (with backticks) or not
|
||||
*
|
||||
* @var mixed[]
|
||||
* @phpstan-var array{
|
||||
@@ -544,6 +540,8 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
/**
|
||||
* The ReflectionProperty instances of the mapped class.
|
||||
*
|
||||
* @deprecated Use $propertyAccessors instead.
|
||||
*
|
||||
* @var LegacyReflectionFields|array<string, ReflectionProperty>
|
||||
*/
|
||||
public LegacyReflectionFields|array $reflFields = [];
|
||||
@@ -573,6 +571,8 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
/**
|
||||
* Gets the ReflectionProperties of the mapped class.
|
||||
*
|
||||
* @deprecated Use getPropertyAccessors() instead.
|
||||
*
|
||||
* @return LegacyReflectionFields|ReflectionProperty[] An array of ReflectionProperty instances.
|
||||
* @phpstan-return LegacyReflectionFields|array<string, ReflectionProperty>
|
||||
*/
|
||||
@@ -593,6 +593,8 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
|
||||
/**
|
||||
* Gets a ReflectionProperty for a specific field of the mapped class.
|
||||
*
|
||||
* @deprecated Use getPropertyAccessor() instead.
|
||||
*/
|
||||
public function getReflectionProperty(string $name): ReflectionProperty|null
|
||||
{
|
||||
@@ -604,7 +606,11 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
return $this->propertyAccessors[$name] ?? null;
|
||||
}
|
||||
|
||||
/** @throws BadMethodCallException If the class has a composite identifier. */
|
||||
/**
|
||||
* @deprecated Use getPropertyAccessor() instead.
|
||||
*
|
||||
* @throws BadMethodCallException If the class has a composite identifier.
|
||||
*/
|
||||
public function getSingleIdReflectionProperty(): ReflectionProperty|null
|
||||
{
|
||||
if ($this->isIdentifierComposite) {
|
||||
@@ -818,7 +824,8 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
public function wakeupReflection(ReflectionService $reflService): void
|
||||
{
|
||||
// Restore ReflectionClass and properties
|
||||
$this->reflClass = $reflService->getClass($this->name);
|
||||
$this->reflClass = $reflService->getClass($this->name);
|
||||
/** @phpstan-ignore property.deprecated */
|
||||
$this->reflFields = new LegacyReflectionFields($this, $reflService);
|
||||
$this->instantiator = $this->instantiator ?: new Instantiator();
|
||||
|
||||
|
||||
@@ -10,8 +10,11 @@ use Doctrine\ORM\Internal\SQLResultCasing;
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
use function assert;
|
||||
use function explode;
|
||||
use function implode;
|
||||
use function is_numeric;
|
||||
use function preg_replace;
|
||||
use function sprintf;
|
||||
use function substr;
|
||||
|
||||
/**
|
||||
@@ -38,7 +41,13 @@ class DefaultQuoteStrategy implements QuoteStrategy
|
||||
$tableName = $class->table['name'];
|
||||
|
||||
if (! empty($class->table['schema'])) {
|
||||
$tableName = $class->table['schema'] . '.' . $class->table['name'];
|
||||
return isset($class->table['quoted'])
|
||||
? sprintf(
|
||||
'%s.%s',
|
||||
$platform->quoteSingleIdentifier($class->table['schema']),
|
||||
$platform->quoteSingleIdentifier($tableName),
|
||||
)
|
||||
: $class->table['schema'] . '.' . $class->table['name'];
|
||||
}
|
||||
|
||||
return isset($class->table['quoted'])
|
||||
@@ -52,7 +61,10 @@ class DefaultQuoteStrategy implements QuoteStrategy
|
||||
public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform): string
|
||||
{
|
||||
return isset($definition['quoted'])
|
||||
? $platform->quoteSingleIdentifier($definition['sequenceName'])
|
||||
? implode('.', array_map(
|
||||
static fn (string $part) => $platform->quoteSingleIdentifier($part),
|
||||
explode('.', $definition['sequenceName']),
|
||||
))
|
||||
: $definition['sequenceName'];
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ trait JoinColumnProperties
|
||||
public readonly string|null $referencedColumnName = null,
|
||||
public readonly bool $deferrable = false,
|
||||
public readonly bool $unique = false,
|
||||
public readonly bool $nullable = true,
|
||||
public readonly bool|null $nullable = null,
|
||||
public readonly mixed $onDelete = null,
|
||||
public readonly string|null $columnDefinition = null,
|
||||
public readonly string|null $fieldName = null,
|
||||
|
||||
@@ -127,6 +127,8 @@ final class ManyToManyOwningSideMapping extends ToManyOwningSideMapping implemen
|
||||
$mapping->joinTableColumns = [];
|
||||
|
||||
foreach ($mapping->joinTable->joinColumns as $joinColumn) {
|
||||
$joinColumn->nullable = false;
|
||||
|
||||
if (empty($joinColumn->referencedColumnName)) {
|
||||
$joinColumn->referencedColumnName = $namingStrategy->referenceColumnName();
|
||||
}
|
||||
@@ -150,6 +152,8 @@ final class ManyToManyOwningSideMapping extends ToManyOwningSideMapping implemen
|
||||
}
|
||||
|
||||
foreach ($mapping->joinTable->inverseJoinColumns as $inverseJoinColumn) {
|
||||
$inverseJoinColumn->nullable = false;
|
||||
|
||||
if (empty($inverseJoinColumn->referencedColumnName)) {
|
||||
$inverseJoinColumn->referencedColumnName = $namingStrategy->referenceColumnName();
|
||||
}
|
||||
|
||||
@@ -130,6 +130,12 @@ abstract class ToOneOwningSideMapping extends OwningSideMapping implements ToOne
|
||||
$uniqueConstraintColumns = [];
|
||||
|
||||
foreach ($mapping->joinColumns as $joinColumn) {
|
||||
if ($mapping->id) {
|
||||
$joinColumn->nullable = false;
|
||||
} elseif ($joinColumn->nullable === null) {
|
||||
$joinColumn->nullable = true;
|
||||
}
|
||||
|
||||
if ($mapping->isOneToOne() && ! $isInheritanceTypeSingleTable) {
|
||||
if (count($mapping->joinColumns) === 1) {
|
||||
if (empty($mapping->id)) {
|
||||
|
||||
@@ -153,12 +153,6 @@ class BasicEntityPersister implements EntityPersister
|
||||
*/
|
||||
protected array $quotedColumns = [];
|
||||
|
||||
/**
|
||||
* The INSERT SQL statement used for entities handled by this persister.
|
||||
* This SQL is only generated once per request, if at all.
|
||||
*/
|
||||
private string|null $insertSql = null;
|
||||
|
||||
/**
|
||||
* The quote strategy.
|
||||
*/
|
||||
@@ -273,8 +267,8 @@ class BasicEntityPersister implements EntityPersister
|
||||
$this->assignDefaultVersionAndUpsertableValues($entity, $id);
|
||||
}
|
||||
|
||||
// Unset this queued insert, so that the prepareUpdateData() method knows right away
|
||||
// (for the next entity already) that the current entity has been written to the database
|
||||
// Unset this queued insert, so that the prepareUpdateData() method (called via prepareInsertData() method)
|
||||
// knows right away (for the next entity already) that the current entity has been written to the database
|
||||
// and no extra updates need to be scheduled to refer to it.
|
||||
//
|
||||
// In \Doctrine\ORM\UnitOfWork::executeInserts(), the UoW already removed entities
|
||||
@@ -693,11 +687,11 @@ class BasicEntityPersister implements EntityPersister
|
||||
$targetColumn = $joinColumn->referencedColumnName;
|
||||
$quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform);
|
||||
|
||||
$this->quotedColumns[$sourceColumn] = $quotedColumn;
|
||||
$this->columnTypes[$sourceColumn] = PersisterHelper::getTypeOfColumn($targetColumn, $targetClass, $this->em);
|
||||
$result[$owningTable][$sourceColumn] = $newValId
|
||||
? $newValId[$targetClass->getFieldForColumn($targetColumn)]
|
||||
: null;
|
||||
$this->quotedColumns[$sourceColumn] = $quotedColumn;
|
||||
$this->columnTypes[$sourceColumn] = PersisterHelper::getTypeOfColumn($targetColumn, $targetClass, $this->em);
|
||||
|
||||
$newValue = $newValId ? $newValId[$targetClass->getFieldForColumn($targetColumn)] : null;
|
||||
$result[$owningTable][$sourceColumn] = $newValue instanceof BackedEnum ? $newValue->value : $newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1418,22 +1412,17 @@ class BasicEntityPersister implements EntityPersister
|
||||
|
||||
public function getInsertSQL(): string
|
||||
{
|
||||
if ($this->insertSql !== null) {
|
||||
return $this->insertSql;
|
||||
}
|
||||
|
||||
$columns = $this->getInsertColumnList();
|
||||
$tableName = $this->quoteStrategy->getTableName($this->class, $this->platform);
|
||||
|
||||
if (empty($columns)) {
|
||||
$identityColumn = $this->quoteStrategy->getColumnName($this->class->identifier[0], $this->class, $this->platform);
|
||||
$this->insertSql = $this->platform->getEmptyIdentityInsertSQL($tableName, $identityColumn);
|
||||
if ($columns === []) {
|
||||
$identityColumn = $this->quoteStrategy->getColumnName($this->class->identifier[0], $this->class, $this->platform);
|
||||
|
||||
return $this->insertSql;
|
||||
return $this->platform->getEmptyIdentityInsertSQL($tableName, $identityColumn);
|
||||
}
|
||||
|
||||
$values = [];
|
||||
$columns = array_unique($columns);
|
||||
$placeholders = [];
|
||||
$columns = array_unique($columns);
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$placeholder = '?';
|
||||
@@ -1447,15 +1436,13 @@ class BasicEntityPersister implements EntityPersister
|
||||
$placeholder = $type->convertToDatabaseValueSQL('?', $this->platform);
|
||||
}
|
||||
|
||||
$values[] = $placeholder;
|
||||
$placeholders[] = $placeholder;
|
||||
}
|
||||
|
||||
$columns = implode(', ', $columns);
|
||||
$values = implode(', ', $values);
|
||||
$columns = implode(', ', $columns);
|
||||
$placeholders = implode(', ', $placeholders);
|
||||
|
||||
$this->insertSql = sprintf('INSERT INTO %s (%s) VALUES (%s)', $tableName, $columns, $values);
|
||||
|
||||
return $this->insertSql;
|
||||
return sprintf('INSERT INTO %s (%s) VALUES (%s)', $tableName, $columns, $placeholders);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1964,6 +1951,7 @@ class BasicEntityPersister implements EntityPersister
|
||||
ParameterType::STRING => ArrayParameterType::STRING,
|
||||
ParameterType::INTEGER => ArrayParameterType::INTEGER,
|
||||
ParameterType::ASCII => ArrayParameterType::ASCII,
|
||||
ParameterType::BINARY => ArrayParameterType::BINARY,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
// Execute all inserts. For each entity:
|
||||
// 1) Insert on root table
|
||||
// 2) Insert on sub tables
|
||||
foreach ($this->queuedInserts as $entity) {
|
||||
foreach ($this->queuedInserts as $key => $entity) {
|
||||
$insertData = $this->prepareInsertData($entity);
|
||||
|
||||
// Execute insert on root table
|
||||
@@ -179,9 +179,16 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
if ($this->class->requiresFetchAfterChange) {
|
||||
$this->assignDefaultVersionAndUpsertableValues($entity, $id);
|
||||
}
|
||||
}
|
||||
|
||||
$this->queuedInserts = [];
|
||||
// Unset this queued insert, so that the prepareUpdateData() method (called via prepareInsertData() method)
|
||||
// knows right away (for the next entity already) that the current entity has been written to the database
|
||||
// and no extra updates need to be scheduled to refer to it.
|
||||
//
|
||||
// In \Doctrine\ORM\UnitOfWork::executeInserts(), the UoW already removed entities
|
||||
// from its own list (\Doctrine\ORM\UnitOfWork::$entityInsertions) right after they
|
||||
// were given to our addInsert() method.
|
||||
unset($this->queuedInserts[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(object $entity): void
|
||||
|
||||
@@ -152,7 +152,23 @@ EOPHP;
|
||||
string|null $proxyNs = null,
|
||||
bool|int $autoGenerate = self::AUTOGENERATE_NEVER,
|
||||
) {
|
||||
if (PHP_VERSION_ID >= 80400 && func_num_args() > 1) {
|
||||
if (! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Not enabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0.',
|
||||
);
|
||||
}
|
||||
|
||||
if (! $proxyDir) {
|
||||
throw ORMInvalidArgumentException::proxyDirectoryRequired();
|
||||
}
|
||||
|
||||
if (! $proxyNs) {
|
||||
throw ORMInvalidArgumentException::proxyNamespaceRequired();
|
||||
}
|
||||
} elseif (PHP_VERSION_ID >= 80400 && func_num_args() > 1) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
@@ -161,14 +177,6 @@ EOPHP;
|
||||
);
|
||||
}
|
||||
|
||||
if (! $proxyDir && ! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
throw ORMInvalidArgumentException::proxyDirectoryRequired();
|
||||
}
|
||||
|
||||
if (! $proxyNs && ! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
throw ORMInvalidArgumentException::proxyNamespaceRequired();
|
||||
}
|
||||
|
||||
if (is_int($autoGenerate) ? $autoGenerate < 0 || $autoGenerate > 4 : ! is_bool($autoGenerate)) {
|
||||
throw ORMInvalidArgumentException::invalidAutoGenerateMode($autoGenerate);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ EOT);
|
||||
$this->formatField('Embedded class?', $metadata->isEmbeddedClass),
|
||||
$this->formatField('Parent classes', $metadata->parentClasses),
|
||||
$this->formatField('Sub classes', $metadata->subClasses),
|
||||
$this->formatField('Embedded classes', $metadata->subClasses),
|
||||
$this->formatField('Embedded classes', $metadata->embeddedClasses),
|
||||
$this->formatField('Identifier', $metadata->identifier),
|
||||
$this->formatField('Inheritance type', $metadata->inheritanceType),
|
||||
$this->formatField('Discriminator column', $metadata->discriminatorColumn),
|
||||
|
||||
@@ -153,7 +153,7 @@ class SchemaValidator
|
||||
$ce[] = 'The field ' . $class->name . '#' . $fieldName . ' is on the inverse side of a ' .
|
||||
'bi-directional relationship, but the specified mappedBy association on the target-entity ' .
|
||||
$assoc->targetEntity . '#' . $assoc->mappedBy . ' does not contain the required ' .
|
||||
"'inversedBy=\"" . $fieldName . "\"' attribute.";
|
||||
"'inversedBy: \"" . $fieldName . "\"' attribute.";
|
||||
} elseif ($targetMetadata->associationMappings[$assoc->mappedBy]->inversedBy !== $fieldName) {
|
||||
$ce[] = 'The mappings ' . $class->name . '#' . $fieldName . ' and ' .
|
||||
$assoc->targetEntity . '#' . $assoc->mappedBy . ' are ' .
|
||||
@@ -174,7 +174,7 @@ class SchemaValidator
|
||||
$ce[] = 'The field ' . $class->name . '#' . $fieldName . ' is on the owning side of a ' .
|
||||
'bi-directional relationship, but the specified inversedBy association on the target-entity ' .
|
||||
$assoc->targetEntity . '#' . $assoc->inversedBy . ' does not contain the required ' .
|
||||
"'mappedBy=\"" . $fieldName . "\"' attribute.";
|
||||
"'mappedBy: \"" . $fieldName . "\"' attribute.";
|
||||
} elseif ($targetMetadata->associationMappings[$assoc->inversedBy]->mappedBy !== $fieldName) {
|
||||
$ce[] = 'The mappings ' . $class->name . '#' . $fieldName . ' and ' .
|
||||
$assoc->targetEntity . '#' . $assoc->inversedBy . ' are ' .
|
||||
|
||||
@@ -934,7 +934,9 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
$this->entityStates[$oid] = self::STATE_MANAGED;
|
||||
|
||||
$this->scheduleForInsert($entity);
|
||||
if (! isset($this->entityInsertions[$oid])) {
|
||||
$this->scheduleForInsert($entity);
|
||||
}
|
||||
}
|
||||
|
||||
/** @param mixed[] $idValue */
|
||||
|
||||
85
tests/Doctrine/Tests/ORM/Functional/Ticket/GH12063.php
Normal file
85
tests/Doctrine/Tests/ORM/Functional/Ticket/GH12063.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\ORM\Mapping\Column;
|
||||
use Doctrine\ORM\Mapping\Entity;
|
||||
use Doctrine\ORM\Mapping\GeneratedValue;
|
||||
use Doctrine\ORM\Mapping\Id;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
|
||||
class GH12063 extends OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->createSchemaForModels(GH12063Association::class, GH12063Entity::class);
|
||||
}
|
||||
|
||||
public function testLoadedAssociationWithBackedEnum(): void
|
||||
{
|
||||
$association = new GH12063Association();
|
||||
$association->code = GH12063Code::One;
|
||||
|
||||
$this->_em->persist($association);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$entity = new GH12063Entity();
|
||||
$entity->association = $this->_em->find(GH12063Association::class, GH12063Code::One);
|
||||
|
||||
$this->_em->persist($entity);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertNotNull($entity->id);
|
||||
}
|
||||
|
||||
public function testProxyAssociationWithBackedEnum(): void
|
||||
{
|
||||
$association = new GH12063Association();
|
||||
$association->code = GH12063Code::Two;
|
||||
|
||||
$this->_em->persist($association);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$entity = new GH12063Entity();
|
||||
$entity->association = $this->_em->getReference(GH12063Association::class, GH12063Code::Two);
|
||||
|
||||
$this->_em->persist($entity);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertNotNull($entity->id);
|
||||
}
|
||||
}
|
||||
|
||||
enum GH12063Code: string
|
||||
{
|
||||
case One = 'one';
|
||||
case Two = 'two';
|
||||
}
|
||||
|
||||
#[Entity]
|
||||
class GH12063Association
|
||||
{
|
||||
#[Id]
|
||||
#[Column]
|
||||
public GH12063Code $code;
|
||||
}
|
||||
|
||||
#[Entity]
|
||||
class GH12063Entity
|
||||
{
|
||||
#[Id]
|
||||
#[Column]
|
||||
#[GeneratedValue]
|
||||
public int|null $id = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'code')]
|
||||
public GH12063Association $association;
|
||||
}
|
||||
48
tests/Tests/Models/BinaryPrimaryKey/BinaryId.php
Normal file
48
tests/Tests/Models/BinaryPrimaryKey/BinaryId.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\Models\BinaryPrimaryKey;
|
||||
|
||||
use LogicException;
|
||||
|
||||
use function bin2hex;
|
||||
use function hex2bin;
|
||||
use function random_bytes;
|
||||
|
||||
class BinaryId
|
||||
{
|
||||
public const LENGTH = 6;
|
||||
|
||||
private string $hexId;
|
||||
|
||||
private function __construct(string $data)
|
||||
{
|
||||
$this->hexId = $data;
|
||||
}
|
||||
|
||||
public static function new(): self
|
||||
{
|
||||
return new self(bin2hex(random_bytes(self::LENGTH)));
|
||||
}
|
||||
|
||||
public static function fromBytes(string $value): self
|
||||
{
|
||||
return new self(bin2hex($value));
|
||||
}
|
||||
|
||||
public function getBytes(): string
|
||||
{
|
||||
$binary = hex2bin($this->hexId);
|
||||
if ($binary === false) {
|
||||
throw new LogicException('Cannot convert hex to binary: ' . $this->hexId);
|
||||
}
|
||||
|
||||
return $binary;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->getBytes();
|
||||
}
|
||||
}
|
||||
66
tests/Tests/Models/BinaryPrimaryKey/BinaryIdType.php
Normal file
66
tests/Tests/Models/BinaryPrimaryKey/BinaryIdType.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\Models\BinaryPrimaryKey;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\Mocks\CompatibilityType;
|
||||
use LogicException;
|
||||
|
||||
final class BinaryIdType extends Type
|
||||
{
|
||||
use CompatibilityType;
|
||||
|
||||
public const NAME = 'binary_id';
|
||||
|
||||
public function convertToPHPValue(
|
||||
mixed $value,
|
||||
AbstractPlatform $platform,
|
||||
): BinaryId|null {
|
||||
if ($value === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($value instanceof BinaryId) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return BinaryId::fromBytes($value);
|
||||
}
|
||||
|
||||
public function convertToDatabaseValue(
|
||||
mixed $value,
|
||||
AbstractPlatform $platform,
|
||||
): string|null {
|
||||
if ($value === null) {
|
||||
return null;
|
||||
} elseif ($value instanceof BinaryId) {
|
||||
return $value->getBytes();
|
||||
} else {
|
||||
throw new LogicException('Unexpected value: ' . $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function getSQLDeclaration(
|
||||
array $column,
|
||||
AbstractPlatform $platform,
|
||||
): string {
|
||||
return $platform->getBinaryTypeDeclarationSQL([
|
||||
'length' => BinaryId::LENGTH,
|
||||
'fixed' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
private function doGetBindingType(): ParameterType|int
|
||||
{
|
||||
return ParameterType::BINARY;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return self::NAME;
|
||||
}
|
||||
}
|
||||
73
tests/Tests/Models/BinaryPrimaryKey/Category.php
Normal file
73
tests/Tests/Models/BinaryPrimaryKey/Category.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\Models\BinaryPrimaryKey;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ReadableCollection;
|
||||
use Doctrine\ORM\Mapping\Column;
|
||||
use Doctrine\ORM\Mapping\Entity;
|
||||
use Doctrine\ORM\Mapping\Id;
|
||||
use Doctrine\ORM\Mapping\ManyToOne;
|
||||
use Doctrine\ORM\Mapping\OneToMany;
|
||||
|
||||
#[Entity]
|
||||
class Category
|
||||
{
|
||||
#[Id]
|
||||
#[Column(type: BinaryIdType::NAME, nullable: false)]
|
||||
private BinaryId $id;
|
||||
|
||||
#[Column]
|
||||
private string $name;
|
||||
|
||||
#[ManyToOne(targetEntity: self::class, inversedBy: 'children')]
|
||||
private self|null $parent;
|
||||
|
||||
/** @var Collection<int, Category> */
|
||||
#[OneToMany(targetEntity: self::class, mappedBy: 'parent')]
|
||||
private Collection $children;
|
||||
|
||||
public function __construct(
|
||||
string $name,
|
||||
self|null $parent = null,
|
||||
) {
|
||||
$this->id = BinaryId::new();
|
||||
$this->name = $name;
|
||||
$this->parent = $parent;
|
||||
$this->children = new ArrayCollection();
|
||||
|
||||
$parent?->addChild($this);
|
||||
}
|
||||
|
||||
public function getId(): BinaryId
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getParent(): self|null
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/** @return ReadableCollection<int, Category> */
|
||||
public function getChildren(): ReadableCollection
|
||||
{
|
||||
return $this->children;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public function addChild(self $category): void
|
||||
{
|
||||
if (! $this->children->contains($category)) {
|
||||
$this->children->add($category);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,19 +229,4 @@ class ConfigurationTest extends TestCase
|
||||
|
||||
$this->configuration->enableNativeLazyObjects(false);
|
||||
}
|
||||
|
||||
#[RequiresPhp('<8.4')]
|
||||
public function testNotEnablingNativeLazyObjectIsFineOnPhpLowerThan84(): void
|
||||
{
|
||||
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
|
||||
self::assertFalse($this->configuration->isNativeLazyObjectsEnabled());
|
||||
}
|
||||
|
||||
#[RequiresPhp('8.4')]
|
||||
#[WithoutErrorHandler]
|
||||
public function testNotEnablingNativeLazyObjectIsDeprecatedOnPhp84(): void
|
||||
{
|
||||
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
|
||||
self::assertFalse($this->configuration->isNativeLazyObjectsEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
93
tests/Tests/ORM/Functional/PrePersistEventTest.php
Normal file
93
tests/Tests/ORM/Functional/PrePersistEventTest.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\ORM\Event\PrePersistEventArgs;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\ORM\Mapping\Column;
|
||||
use Doctrine\ORM\Mapping\Entity;
|
||||
use Doctrine\ORM\Mapping\GeneratedValue;
|
||||
use Doctrine\ORM\Mapping\Id;
|
||||
use Doctrine\ORM\Mapping\ManyToOne;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
|
||||
use function uniqid;
|
||||
|
||||
class PrePersistEventTest extends OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->createSchemaForModels(
|
||||
EntityWithUnmappedEntity::class,
|
||||
EntityWithCascadeAssociation::class,
|
||||
);
|
||||
}
|
||||
|
||||
public function testCallingPersistInPrePersistHook(): void
|
||||
{
|
||||
$entityWithUnmapped = new EntityWithUnmappedEntity();
|
||||
$entityWithCascade = new EntityWithCascadeAssociation();
|
||||
|
||||
$entityWithUnmapped->unmapped = $entityWithCascade;
|
||||
$entityWithCascade->cascaded = $entityWithUnmapped;
|
||||
|
||||
$this->_em->getEventManager()->addEventListener(Events::prePersist, new PrePersistUnmappedPersistListener());
|
||||
$this->_em->persist($entityWithUnmapped);
|
||||
|
||||
$this->assertTrue($this->_em->getUnitOfWork()->isScheduledForInsert($entityWithCascade));
|
||||
$this->assertTrue($this->_em->getUnitOfWork()->isScheduledForInsert($entityWithUnmapped));
|
||||
}
|
||||
}
|
||||
|
||||
class PrePersistUnmappedPersistListener
|
||||
{
|
||||
public function prePersist(PrePersistEventArgs $args): void
|
||||
{
|
||||
$object = $args->getObject();
|
||||
|
||||
if ($object instanceof EntityWithUnmappedEntity) {
|
||||
$uow = $args->getObjectManager()->getUnitOfWork();
|
||||
|
||||
if ($object->unmapped && ! $uow->isInIdentityMap($object->unmapped) && ! $uow->isScheduledForInsert($object->unmapped)) {
|
||||
$args->getObjectManager()->persist($object->unmapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[Entity]
|
||||
class EntityWithUnmappedEntity
|
||||
{
|
||||
#[Id]
|
||||
#[Column(type: 'string', length: 255)]
|
||||
#[GeneratedValue(strategy: 'NONE')]
|
||||
public string $id;
|
||||
|
||||
public EntityWithCascadeAssociation|null $unmapped = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->id = uniqid(self::class, true);
|
||||
}
|
||||
}
|
||||
|
||||
#[Entity]
|
||||
class EntityWithCascadeAssociation
|
||||
{
|
||||
#[Id]
|
||||
#[Column(type: 'string', length: 255)]
|
||||
#[GeneratedValue(strategy: 'NONE')]
|
||||
public string $id;
|
||||
|
||||
#[ManyToOne(targetEntity: EntityWithUnmappedEntity::class, cascade: ['persist'])]
|
||||
public EntityWithUnmappedEntity|null $cascaded = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->id = uniqid(self::class, true);
|
||||
}
|
||||
}
|
||||
167
tests/Tests/ORM/Functional/SecondLevelCacheCountQueriesTest.php
Normal file
167
tests/Tests/ORM/Functional/SecondLevelCacheCountQueriesTest.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\Tests\Models\Cache\Country;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use ReflectionProperty;
|
||||
|
||||
use function array_diff;
|
||||
use function array_filter;
|
||||
use function file_exists;
|
||||
use function rmdir;
|
||||
use function scandir;
|
||||
use function strpos;
|
||||
use function sys_get_temp_dir;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
/** @phpstan-type SupportedCacheUsage 0|ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE|ClassMetadata::CACHE_USAGE_READ_WRITE */
|
||||
#[Group('DDC-2183')]
|
||||
class SecondLevelCacheCountQueriesTest extends SecondLevelCacheFunctionalTestCase
|
||||
{
|
||||
/** @var string */
|
||||
private $tmpDir;
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if ($this->tmpDir !== null && file_exists($this->tmpDir)) {
|
||||
foreach (array_diff(scandir($this->tmpDir), ['.', '..']) as $f) {
|
||||
rmdir($this->tmpDir . DIRECTORY_SEPARATOR . $f);
|
||||
}
|
||||
|
||||
rmdir($this->tmpDir);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/** @param SupportedCacheUsage $cacheUsage */
|
||||
private function setupCountryModel(int $cacheUsage): void
|
||||
{
|
||||
$metadata = $this->_em->getClassMetaData(Country::class);
|
||||
|
||||
if ($cacheUsage === 0) {
|
||||
$metadataCacheReflection = new ReflectionProperty(ClassMetadata::class, 'cache');
|
||||
$metadataCacheReflection->setAccessible(true);
|
||||
$metadataCacheReflection->setValue($metadata, null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($cacheUsage === ClassMetadata::CACHE_USAGE_READ_WRITE) {
|
||||
$this->tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . self::class;
|
||||
$this->secondLevelCacheFactory->setFileLockRegionDirectory($this->tmpDir);
|
||||
}
|
||||
|
||||
$metadata->enableCache(['usage' => $cacheUsage]);
|
||||
}
|
||||
|
||||
private function loadFixturesCountriesWithoutPostInsertIdentifier(): void
|
||||
{
|
||||
$metadata = $this->_em->getClassMetaData(Country::class);
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
|
||||
$c1 = new Country('Brazil');
|
||||
$c1->setId(10);
|
||||
$c2 = new Country('Germany');
|
||||
$c2->setId(20);
|
||||
|
||||
$this->countries[] = $c1;
|
||||
$this->countries[] = $c2;
|
||||
|
||||
$this->_em->persist($c1);
|
||||
$this->_em->persist($c2);
|
||||
$this->_em->flush();
|
||||
}
|
||||
|
||||
/** @param 'INSERT'|'UPDATE'|'DELETE' $type */
|
||||
private function assertQueryCountByType(string $type, int $expectedCount): void
|
||||
{
|
||||
$queries = array_filter($this->getQueryLog()->queries, static function (array $entry) use ($type): bool {
|
||||
return strpos($entry['sql'], $type) === 0;
|
||||
});
|
||||
|
||||
self::assertCount($expectedCount, $queries);
|
||||
}
|
||||
|
||||
/** @param SupportedCacheUsage $cacheUsage */
|
||||
#[DataProvider('cacheUsageProvider')]
|
||||
public function testInsertWithPostInsertIdentifier(int $cacheUsage): void
|
||||
{
|
||||
$this->setupCountryModel($cacheUsage);
|
||||
|
||||
self::assertQueryCountByType('INSERT', 0);
|
||||
|
||||
$this->loadFixturesCountries();
|
||||
|
||||
self::assertCount(2, $this->countries);
|
||||
self::assertQueryCountByType('INSERT', 2);
|
||||
}
|
||||
|
||||
/** @param SupportedCacheUsage $cacheUsage */
|
||||
#[DataProvider('cacheUsageProvider')]
|
||||
public function testInsertWithoutPostInsertIdentifier(int $cacheUsage): void
|
||||
{
|
||||
$this->setupCountryModel($cacheUsage);
|
||||
|
||||
self::assertQueryCountByType('INSERT', 0);
|
||||
|
||||
$this->loadFixturesCountriesWithoutPostInsertIdentifier();
|
||||
|
||||
self::assertCount(2, $this->countries);
|
||||
self::assertQueryCountByType('INSERT', 2);
|
||||
}
|
||||
|
||||
/** @param SupportedCacheUsage $cacheUsage */
|
||||
#[DataProvider('cacheUsageProvider')]
|
||||
public function testDelete(int $cacheUsage): void
|
||||
{
|
||||
$this->setupCountryModel($cacheUsage);
|
||||
$this->loadFixturesCountries();
|
||||
|
||||
$c1 = $this->_em->find(Country::class, $this->countries[0]->getId());
|
||||
$c2 = $this->_em->find(Country::class, $this->countries[1]->getId());
|
||||
|
||||
$this->_em->remove($c1);
|
||||
$this->_em->remove($c2);
|
||||
$this->_em->flush();
|
||||
|
||||
self::assertQueryCountByType('DELETE', 2);
|
||||
}
|
||||
|
||||
/** @param SupportedCacheUsage $cacheUsage */
|
||||
#[DataProvider('cacheUsageProvider')]
|
||||
public function testUpdate(int $cacheUsage): void
|
||||
{
|
||||
$this->setupCountryModel($cacheUsage);
|
||||
$this->loadFixturesCountries();
|
||||
|
||||
$c1 = $this->_em->find(Country::class, $this->countries[0]->getId());
|
||||
$c2 = $this->_em->find(Country::class, $this->countries[1]->getId());
|
||||
|
||||
$c1->setName('Czech Republic');
|
||||
$c2->setName('Hungary');
|
||||
|
||||
$this->_em->persist($c1);
|
||||
$this->_em->persist($c2);
|
||||
$this->_em->flush();
|
||||
|
||||
self::assertQueryCountByType('UPDATE', 2);
|
||||
}
|
||||
|
||||
/** @return list<array{SupportedCacheUsage}> */
|
||||
public static function cacheUsageProvider(): array
|
||||
{
|
||||
return [
|
||||
[0],
|
||||
[ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE],
|
||||
[ClassMetadata::CACHE_USAGE_READ_WRITE],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,6 @@ use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* This class makes tests on the correct use of a database schema when entities are stored
|
||||
*/
|
||||
@@ -30,32 +28,7 @@ class DDC2825Test extends OrmFunctionalTestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[DataProvider('getTestedClasses')]
|
||||
public function testClassSchemaMappingsValidity(string $className, string $expectedSchemaName, string $expectedTableName): void
|
||||
{
|
||||
$classMetadata = $this->_em->getClassMetadata($className);
|
||||
$platform = $this->_em->getConnection()->getDatabasePlatform();
|
||||
$quotedTableName = $this->_em->getConfiguration()->getQuoteStrategy()->getTableName($classMetadata, $platform);
|
||||
|
||||
// Check if table name and schema properties are defined in the class metadata
|
||||
self::assertEquals($expectedTableName, $classMetadata->table['name']);
|
||||
self::assertEquals($expectedSchemaName, $classMetadata->table['schema']);
|
||||
|
||||
if ($this->_em->getConnection()->getDatabasePlatform()->supportsSchemas()) {
|
||||
$fullTableName = sprintf('%s.%s', $expectedSchemaName, $expectedTableName);
|
||||
} else {
|
||||
$fullTableName = sprintf('%s__%s', $expectedSchemaName, $expectedTableName);
|
||||
}
|
||||
|
||||
self::assertEquals($fullTableName, $quotedTableName);
|
||||
|
||||
// Checks sequence name validity
|
||||
self::assertEquals(
|
||||
$fullTableName . '_' . $classMetadata->getSingleIdentifierColumnName() . '_seq',
|
||||
$classMetadata->getSequenceName($platform),
|
||||
);
|
||||
}
|
||||
|
||||
/** @param class-string $className */
|
||||
#[DataProvider('getTestedClasses')]
|
||||
public function testPersistenceOfEntityWithSchemaMapping(string $className): void
|
||||
{
|
||||
@@ -68,17 +41,14 @@ class DDC2825Test extends OrmFunctionalTestCase
|
||||
self::assertCount(1, $this->_em->getRepository($className)->findAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider
|
||||
*
|
||||
* @return string[][]
|
||||
*/
|
||||
/** @return list<array{class-string}> */
|
||||
public static function getTestedClasses(): array
|
||||
{
|
||||
return [
|
||||
[ExplicitSchemaAndTable::class, 'explicit_schema', 'explicit_table'],
|
||||
[SchemaAndTableInTableName::class, 'implicit_schema', 'implicit_table'],
|
||||
[DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName::class, 'myschema', 'order'],
|
||||
[ExplicitSchemaAndTable::class],
|
||||
[SchemaAndTableInTableName::class],
|
||||
[DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName::class],
|
||||
[File::class],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -93,3 +63,13 @@ class DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName
|
||||
#[ORM\Column(type: 'integer')]
|
||||
public $id;
|
||||
}
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: '`file`', schema: 'yourschema')]
|
||||
class File
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column]
|
||||
#[ORM\GeneratedValue]
|
||||
public int $id;
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ declare(strict_types=1);
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
||||
use Doctrine\DBAL\Schema\Index;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
|
||||
use function method_exists;
|
||||
use function reset;
|
||||
|
||||
class GH11982Test extends OrmFunctionalTestCase
|
||||
@@ -29,6 +31,38 @@ class GH11982Test extends OrmFunctionalTestCase
|
||||
self::markTestSkipped('This test does not work on psql.');
|
||||
}
|
||||
|
||||
if (! method_exists(Index::class, 'getIndexedColumns')) {
|
||||
self::markTestSkipped('This test requires doctrine/dbal >=4.3');
|
||||
}
|
||||
|
||||
$indexes = $this->createSchemaManager()
|
||||
->introspectTable('GH11982ColumnIndex')
|
||||
->getIndexes();
|
||||
|
||||
self::assertCount(3, $indexes); // primary + 2 custom indexes
|
||||
self::assertArrayHasKey('class_idx', $indexes);
|
||||
|
||||
unset($indexes['primary']);
|
||||
unset($indexes['class_idx']);
|
||||
$unnamedIndexColumns = reset($indexes)->getIndexedColumns();
|
||||
self::assertCount(1, $unnamedIndexColumns);
|
||||
self::assertEquals(
|
||||
'indexTrue',
|
||||
$unnamedIndexColumns[0]->getColumnName()->toString(),
|
||||
);
|
||||
}
|
||||
|
||||
#[Group('GH-11982')]
|
||||
public function testSchemaLegacyDbal(): void
|
||||
{
|
||||
if ($this->_em->getConnection()->getDatabasePlatform() instanceof PostgreSQLPlatform) {
|
||||
self::markTestSkipped('This test does not work on psql.');
|
||||
}
|
||||
|
||||
if (method_exists(Index::class, 'getIndexedColumns')) {
|
||||
self::markTestSkipped('This test requires doctrine/dbal <4.3');
|
||||
}
|
||||
|
||||
$indexes = $this->createSchemaManager()
|
||||
->introspectTable('GH11982ColumnIndex')
|
||||
->getIndexes();
|
||||
@@ -48,7 +82,7 @@ class GH11982Test extends OrmFunctionalTestCase
|
||||
#[ORM\Index(
|
||||
name: 'class_idx',
|
||||
fields: ['classIndex'],
|
||||
flags: ['test'],
|
||||
flags: ['fulltext'],
|
||||
options: ['test'],
|
||||
)]
|
||||
class GH11982ColumnIndex
|
||||
|
||||
@@ -66,7 +66,7 @@ class AttributeDriverTest extends MappingDriverTestCase
|
||||
'name' => 'assoz_id',
|
||||
'referencedColumnName' => 'assoz_id',
|
||||
'unique' => false,
|
||||
'nullable' => true,
|
||||
'nullable' => null,
|
||||
'onDelete' => null,
|
||||
'columnDefinition' => null,
|
||||
]),
|
||||
@@ -80,7 +80,7 @@ class AttributeDriverTest extends MappingDriverTestCase
|
||||
'name' => 'inverse_assoz_id',
|
||||
'referencedColumnName' => 'inverse_assoz_id',
|
||||
'unique' => false,
|
||||
'nullable' => true,
|
||||
'nullable' => null,
|
||||
'onDelete' => null,
|
||||
'columnDefinition' => null,
|
||||
]),
|
||||
|
||||
@@ -364,7 +364,7 @@ class ClassMetadataBuilderTest extends OrmTestCase
|
||||
[
|
||||
'name' => 'group_id',
|
||||
'referencedColumnName' => 'id',
|
||||
'nullable' => true,
|
||||
'nullable' => false,
|
||||
'unique' => false,
|
||||
'onDelete' => 'CASCADE',
|
||||
'columnDefinition' => null,
|
||||
@@ -469,7 +469,7 @@ class ClassMetadataBuilderTest extends OrmTestCase
|
||||
[
|
||||
'name' => 'group_id',
|
||||
'referencedColumnName' => 'id',
|
||||
'nullable' => true,
|
||||
'nullable' => false,
|
||||
'unique' => false,
|
||||
'onDelete' => 'CASCADE',
|
||||
'columnDefinition' => null,
|
||||
@@ -539,7 +539,7 @@ class ClassMetadataBuilderTest extends OrmTestCase
|
||||
[
|
||||
'name' => 'group_id',
|
||||
'referencedColumnName' => 'id',
|
||||
'nullable' => true,
|
||||
'nullable' => false,
|
||||
'unique' => false,
|
||||
'onDelete' => 'CASCADE',
|
||||
'columnDefinition' => null,
|
||||
@@ -551,7 +551,7 @@ class ClassMetadataBuilderTest extends OrmTestCase
|
||||
[
|
||||
'name' => 'user_id',
|
||||
'referencedColumnName' => 'id',
|
||||
'nullable' => true,
|
||||
'nullable' => false,
|
||||
'unique' => false,
|
||||
'onDelete' => null,
|
||||
'columnDefinition' => null,
|
||||
@@ -742,7 +742,7 @@ class ClassMetadataBuilderTest extends OrmTestCase
|
||||
0 => [
|
||||
'name' => 'group_id',
|
||||
'referencedColumnName' => 'id',
|
||||
'nullable' => true,
|
||||
'nullable' => false,
|
||||
'unique' => false,
|
||||
'onDelete' => 'CASCADE',
|
||||
'columnDefinition' => null,
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Doctrine\Tests\ORM\Mapping;
|
||||
|
||||
use ArrayObject;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
|
||||
use Doctrine\ORM\Events;
|
||||
@@ -51,6 +52,7 @@ use Doctrine\Tests\ORM\Mapping\TypedFieldMapper\CustomIntAsStringTypedFieldMappe
|
||||
use Doctrine\Tests\OrmTestCase;
|
||||
use DoctrineGlobalArticle;
|
||||
use LogicException;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group as TestGroup;
|
||||
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
|
||||
use ReflectionClass;
|
||||
@@ -970,6 +972,47 @@ class ClassMetadataTest extends OrmTestCase
|
||||
);
|
||||
}
|
||||
|
||||
#[DataProvider('fullTableNameProvider')]
|
||||
public function testGetSequenceName(
|
||||
string $expectedSequenceName,
|
||||
string $fullTableName,
|
||||
): void {
|
||||
$cm = new ClassMetadata(self::class);
|
||||
$cm->setIdentifier(['id']);
|
||||
$cm->setPrimaryTable(['name' => $fullTableName]);
|
||||
|
||||
$platform = $this->createStub(AbstractPlatform::class);
|
||||
|
||||
self::assertSame(
|
||||
$expectedSequenceName,
|
||||
$cm->getSequenceName($platform),
|
||||
);
|
||||
}
|
||||
|
||||
/** @return iterable<string, array{string, string}> */
|
||||
public static function fullTableNameProvider(): iterable
|
||||
{
|
||||
yield 'quoted table name with schema' => [
|
||||
'custom.reserved_id_seq',
|
||||
'custom.`reserved`',
|
||||
];
|
||||
|
||||
yield 'unquoted table name with schema' => [
|
||||
'custom.non_reserved_id_seq',
|
||||
'custom.non_reserved',
|
||||
];
|
||||
|
||||
yield 'quoted table name without schema' => [
|
||||
'reserved_id_seq',
|
||||
'`reserved`',
|
||||
];
|
||||
|
||||
yield 'unquoted table name without schema' => [
|
||||
'non_reserved_id_seq',
|
||||
'non_reserved',
|
||||
];
|
||||
}
|
||||
|
||||
#[TestGroup('DDC-2700')]
|
||||
public function testIsIdentifierMappedSuperClass(): void
|
||||
{
|
||||
|
||||
@@ -6,13 +6,16 @@ namespace Doctrine\Tests\ORM\Mapping;
|
||||
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Schema\Name\UnquotedIdentifierFolding;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
|
||||
use Doctrine\Tests\Models\NonPublicSchemaJoins\User as NonPublicSchemaUser;
|
||||
use Doctrine\Tests\OrmTestCase;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
|
||||
use function assert;
|
||||
use function enum_exists;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Doctrine\Tests\ORM\Mapping\DefaultQuoteStrategyTest
|
||||
@@ -34,4 +37,48 @@ class DefaultQuoteStrategyTest extends OrmTestCase
|
||||
$strategy->getJoinTableName($metadata->associationMappings['readers'], $metadata, $platform),
|
||||
);
|
||||
}
|
||||
|
||||
#[DataProvider('fullTableNameProvider')]
|
||||
public function testGetTableName(string $expectedFullTableName, string $tableName): void
|
||||
{
|
||||
$classMetadata = new ClassMetadata(self::class);
|
||||
$classMetadata->setPrimaryTable(['name' => $tableName]);
|
||||
|
||||
$platform = $this->createStub(AbstractPlatform::class);
|
||||
$platform->method('quoteSingleIdentifier')
|
||||
->willReturnCallback(
|
||||
static fn (string $identifier): string => sprintf('✌️%s✌️', $identifier),
|
||||
);
|
||||
|
||||
$quotedTableName = (new DefaultQuoteStrategy())->getTableName(
|
||||
$classMetadata,
|
||||
$platform,
|
||||
);
|
||||
|
||||
self::assertSame($expectedFullTableName, $quotedTableName);
|
||||
}
|
||||
|
||||
/** @return iterable<string, array{string, string}> */
|
||||
public static function fullTableNameProvider(): iterable
|
||||
{
|
||||
yield 'quoted table name with schema' => [
|
||||
'✌️custom✌️.✌️reserved✌️',
|
||||
'custom.`reserved`',
|
||||
];
|
||||
|
||||
yield 'unquoted table name with schema' => [
|
||||
'custom.non_reserved',
|
||||
'custom.non_reserved',
|
||||
];
|
||||
|
||||
yield 'quoted table name without schema' => [
|
||||
'✌️reserved✌️',
|
||||
'`reserved`',
|
||||
];
|
||||
|
||||
yield 'unquoted table name without schema' => [
|
||||
'non_reserved',
|
||||
'non_reserved',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Mapping;
|
||||
|
||||
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
|
||||
use Doctrine\ORM\Mapping\JoinTableMapping;
|
||||
use Doctrine\ORM\Mapping\ManyToManyOwningSideMapping;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use function assert;
|
||||
@@ -35,4 +37,57 @@ final class ManyToManyOwningSideMappingTest extends TestCase
|
||||
self::assertSame(['foo' => 'bar'], $resurrectedMapping->relationToSourceKeyColumns);
|
||||
self::assertSame(['bar' => 'baz'], $resurrectedMapping->relationToTargetKeyColumns);
|
||||
}
|
||||
|
||||
#[DataProvider('mappingsProvider')]
|
||||
public function testNullableDefaults(bool $expectedValue, ManyToManyOwningSideMapping $mapping): void
|
||||
{
|
||||
foreach ($mapping->joinTable->joinColumns as $joinColumn) {
|
||||
self::assertSame($expectedValue, $joinColumn->nullable);
|
||||
}
|
||||
}
|
||||
|
||||
/** @return iterable<string, array{bool, ManyToManyOwningSideMapping}> */
|
||||
public static function mappingsProvider(): iterable
|
||||
{
|
||||
$namingStrategy = new DefaultNamingStrategy();
|
||||
|
||||
yield 'defaults to false' => [
|
||||
false,
|
||||
ManyToManyOwningSideMapping::fromMappingArrayAndNamingStrategy([
|
||||
'fieldName' => 'foo',
|
||||
'sourceEntity' => self::class,
|
||||
'targetEntity' => self::class,
|
||||
'isOwningSide' => true,
|
||||
'joinTable' => [
|
||||
'name' => 'bar',
|
||||
'joinColumns' => [
|
||||
['name' => 'bar_id', 'referencedColumnName' => 'id'],
|
||||
],
|
||||
'inverseJoinColumns' => [
|
||||
['name' => 'foo_id', 'referencedColumnName' => 'id'],
|
||||
],
|
||||
],
|
||||
], $namingStrategy),
|
||||
];
|
||||
|
||||
yield 'explicitly marked as nullable' => [
|
||||
false, // user's intent is ignored at the ORM level
|
||||
ManyToManyOwningSideMapping::fromMappingArrayAndNamingStrategy([
|
||||
'fieldName' => 'foo',
|
||||
'sourceEntity' => self::class,
|
||||
'targetEntity' => self::class,
|
||||
'isOwningSide' => true,
|
||||
'joinTable' => [
|
||||
'name' => 'bar',
|
||||
'joinColumns' => [
|
||||
['name' => 'bar_id', 'referencedColumnName' => 'id', 'nullable' => true],
|
||||
],
|
||||
'inverseJoinColumns' => [
|
||||
['name' => 'foo_id', 'referencedColumnName' => 'id', 'nullable' => true],
|
||||
],
|
||||
],
|
||||
'id' => true,
|
||||
], $namingStrategy),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Mapping;
|
||||
|
||||
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
|
||||
use Doctrine\ORM\Mapping\JoinColumnMapping;
|
||||
use Doctrine\ORM\Mapping\ManyToOneAssociationMapping;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use function assert;
|
||||
@@ -35,4 +37,60 @@ final class ManyToOneAssociationMappingTest extends TestCase
|
||||
self::assertSame(['foo' => 'bar'], $resurrectedMapping->sourceToTargetKeyColumns);
|
||||
self::assertSame(['bar' => 'foo'], $resurrectedMapping->targetToSourceKeyColumns);
|
||||
}
|
||||
|
||||
#[DataProvider('mappingsProvider')]
|
||||
public function testNullableDefaults(bool $expectedValue, ManyToOneAssociationMapping $mapping): void
|
||||
{
|
||||
foreach ($mapping->joinColumns as $joinColumn) {
|
||||
self::assertSame($expectedValue, $joinColumn->nullable);
|
||||
}
|
||||
}
|
||||
|
||||
/** @return iterable<string, array{bool, ManyToOneAssociationMapping}> */
|
||||
public static function mappingsProvider(): iterable
|
||||
{
|
||||
$namingStrategy = new DefaultNamingStrategy();
|
||||
|
||||
yield 'not part of the identifier' => [
|
||||
true,
|
||||
ManyToOneAssociationMapping::fromMappingArrayAndName([
|
||||
'fieldName' => 'foo',
|
||||
'sourceEntity' => self::class,
|
||||
'targetEntity' => self::class,
|
||||
'isOwningSide' => true,
|
||||
'joinColumns' => [
|
||||
['name' => 'foo_id', 'referencedColumnName' => 'id'],
|
||||
],
|
||||
'id' => false,
|
||||
], $namingStrategy, self::class, null, false),
|
||||
];
|
||||
|
||||
yield 'part of the identifier' => [
|
||||
false,
|
||||
ManyToOneAssociationMapping::fromMappingArrayAndName([
|
||||
'fieldName' => 'foo',
|
||||
'sourceEntity' => self::class,
|
||||
'targetEntity' => self::class,
|
||||
'isOwningSide' => true,
|
||||
'joinColumns' => [
|
||||
['name' => 'foo_id', 'referencedColumnName' => 'id'],
|
||||
],
|
||||
'id' => true,
|
||||
], $namingStrategy, self::class, null, false),
|
||||
];
|
||||
|
||||
yield 'part of the identifier, but explicitly marked as nullable' => [
|
||||
false, // user's intent is ignored at the ORM level
|
||||
ManyToOneAssociationMapping::fromMappingArrayAndName([
|
||||
'fieldName' => 'foo',
|
||||
'sourceEntity' => self::class,
|
||||
'targetEntity' => self::class,
|
||||
'isOwningSide' => true,
|
||||
'joinColumns' => [
|
||||
['name' => 'foo_id', 'referencedColumnName' => 'id', 'nullable' => true],
|
||||
],
|
||||
'id' => true,
|
||||
], $namingStrategy, self::class, null, false),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Mapping;
|
||||
|
||||
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
|
||||
use Doctrine\ORM\Mapping\JoinColumnMapping;
|
||||
use Doctrine\ORM\Mapping\OneToOneOwningSideMapping;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use function assert;
|
||||
@@ -35,4 +37,60 @@ final class OneToOneOwningSideMappingTest extends TestCase
|
||||
self::assertSame(['foo' => 'bar'], $resurrectedMapping->sourceToTargetKeyColumns);
|
||||
self::assertSame(['bar' => 'foo'], $resurrectedMapping->targetToSourceKeyColumns);
|
||||
}
|
||||
|
||||
#[DataProvider('mappingsProvider')]
|
||||
public function testNullableDefaults(bool $expectedValue, OneToOneOwningSideMapping $mapping): void
|
||||
{
|
||||
foreach ($mapping->joinColumns as $joinColumn) {
|
||||
self::assertSame($expectedValue, $joinColumn->nullable);
|
||||
}
|
||||
}
|
||||
|
||||
/** @return iterable<string, array{bool, OneToOneOwningSideMapping}> */
|
||||
public static function mappingsProvider(): iterable
|
||||
{
|
||||
$namingStrategy = new DefaultNamingStrategy();
|
||||
|
||||
yield 'not part of the identifier' => [
|
||||
true,
|
||||
OneToOneOwningSideMapping::fromMappingArrayAndName([
|
||||
'fieldName' => 'foo',
|
||||
'sourceEntity' => self::class,
|
||||
'targetEntity' => self::class,
|
||||
'isOwningSide' => true,
|
||||
'joinColumns' => [
|
||||
['name' => 'foo_id', 'referencedColumnName' => 'id'],
|
||||
],
|
||||
'id' => false,
|
||||
], $namingStrategy, self::class, null, false),
|
||||
];
|
||||
|
||||
yield 'part of the identifier' => [
|
||||
false,
|
||||
OneToOneOwningSideMapping::fromMappingArrayAndName([
|
||||
'fieldName' => 'foo',
|
||||
'sourceEntity' => self::class,
|
||||
'targetEntity' => self::class,
|
||||
'isOwningSide' => true,
|
||||
'joinColumns' => [
|
||||
['name' => 'foo_id', 'referencedColumnName' => 'id'],
|
||||
],
|
||||
'id' => true,
|
||||
], $namingStrategy, self::class, null, false),
|
||||
];
|
||||
|
||||
yield 'part of the identifier, but explicitly marked as nullable' => [
|
||||
false, // user's intent ignored at the ORM level
|
||||
OneToOneOwningSideMapping::fromMappingArrayAndName([
|
||||
'fieldName' => 'foo',
|
||||
'sourceEntity' => self::class,
|
||||
'targetEntity' => self::class,
|
||||
'isOwningSide' => true,
|
||||
'joinColumns' => [
|
||||
['name' => 'foo_id', 'referencedColumnName' => 'id', 'nullable' => true],
|
||||
],
|
||||
'id' => true,
|
||||
], $namingStrategy, self::class, null, false),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
85
tests/Tests/ORM/Persisters/BinaryIdPersisterTest.php
Normal file
85
tests/Tests/ORM/Persisters/BinaryIdPersisterTest.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Persisters;
|
||||
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
use Doctrine\DBAL\Types\Type as DbalType;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\ORMSetup;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Doctrine\ORM\Tools\SchemaValidator;
|
||||
use Doctrine\Tests\Mocks\EntityManagerMock;
|
||||
use Doctrine\Tests\Models\BinaryPrimaryKey\BinaryIdType;
|
||||
use Doctrine\Tests\Models\BinaryPrimaryKey\Category;
|
||||
use Doctrine\Tests\OrmTestCase;
|
||||
|
||||
final class BinaryIdPersisterTest extends OrmTestCase
|
||||
{
|
||||
private EntityManager|null $entityManager = null;
|
||||
|
||||
public function testOneToManyWithEagerFetchMode(): void
|
||||
{
|
||||
$entityManager = $this->createEntityManager();
|
||||
|
||||
$this->createDummyBlogData($entityManager, 3);
|
||||
|
||||
$categories = $entityManager->createQueryBuilder()
|
||||
->select('category')
|
||||
->from(Category::class, 'category')
|
||||
->getQuery()
|
||||
->setFetchMode(Category::class, 'children', ClassMetadata::FETCH_EAGER)
|
||||
->getResult();
|
||||
|
||||
self::assertCount(3, $categories);
|
||||
}
|
||||
|
||||
private function createDummyBlogData(
|
||||
EntityManager $entityManager,
|
||||
int $categoryCount = 1,
|
||||
int $categoryParentsCount = 0,
|
||||
): void {
|
||||
for ($h = 0; $h < $categoryCount; $h++) {
|
||||
$categoryParent = null;
|
||||
|
||||
for ($i = 0; $i < $categoryParentsCount; $i++) {
|
||||
$categoryParent = new Category('CategoryParent#' . $i, $categoryParent);
|
||||
$entityManager->persist($categoryParent);
|
||||
}
|
||||
|
||||
$category = new Category('Category#' . $h, $categoryParent);
|
||||
$entityManager->persist($category);
|
||||
}
|
||||
|
||||
$entityManager->flush();
|
||||
$entityManager->clear();
|
||||
}
|
||||
|
||||
private function createEntityManager(): EntityManager
|
||||
{
|
||||
if ($this->entityManager !== null) {
|
||||
return $this->entityManager;
|
||||
}
|
||||
|
||||
$config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/../../Models/BinaryPrimaryKey'], isDevMode: true);
|
||||
|
||||
if (! DbalType::hasType(BinaryIdType::NAME)) {
|
||||
DbalType::addType(BinaryIdType::NAME, BinaryIdType::class);
|
||||
}
|
||||
|
||||
$connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true], $config);
|
||||
$entityManager = new EntityManagerMock($connection, $config);
|
||||
|
||||
$schemaTool = new SchemaTool($entityManager);
|
||||
$schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata());
|
||||
|
||||
$schemaValidator = new SchemaValidator($entityManager);
|
||||
$schemaValidator->validateMapping();
|
||||
|
||||
$this->entityManager = $entityManager;
|
||||
|
||||
return $entityManager;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ namespace Doctrine\Tests\ORM\Proxy;
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
|
||||
use Doctrine\ORM\EntityNotFoundException;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Persisters\Entity\BasicEntityPersister;
|
||||
@@ -21,6 +22,7 @@ use Doctrine\Tests\Models\ECommerce\ECommerceFeature;
|
||||
use Doctrine\Tests\OrmTestCase;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhp;
|
||||
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
use stdClass;
|
||||
@@ -34,10 +36,10 @@ use function sys_get_temp_dir;
|
||||
*/
|
||||
class ProxyFactoryTest extends OrmTestCase
|
||||
{
|
||||
use VerifyDeprecations;
|
||||
|
||||
private UnitOfWorkMock $uowMock;
|
||||
|
||||
private EntityManagerMock $emMock;
|
||||
|
||||
private ProxyFactory $proxyFactory;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -243,6 +245,37 @@ class ProxyFactoryTest extends OrmTestCase
|
||||
|
||||
self::assertTrue($reflection->isUninitializedLazyObject($proxy));
|
||||
}
|
||||
|
||||
#[RequiresPhp('8.4')]
|
||||
#[WithoutErrorHandler]
|
||||
public function testProxyFactoryTriggersDeprecationWhenNativeLazyObjectsAreDisabled(): void
|
||||
{
|
||||
$this->emMock->getConfiguration()->enableNativeLazyObjects(false);
|
||||
|
||||
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
|
||||
|
||||
$this->proxyFactory = new ProxyFactory(
|
||||
$this->emMock,
|
||||
sys_get_temp_dir(),
|
||||
'Proxies',
|
||||
ProxyFactory::AUTOGENERATE_ALWAYS,
|
||||
);
|
||||
}
|
||||
|
||||
#[RequiresPhp('< 8.4')]
|
||||
public function testProxyFactoryDoesNotTriggerDeprecationWhenNativeLazyObjectsAreDisabled(): void
|
||||
{
|
||||
$this->emMock->getConfiguration()->enableNativeLazyObjects(false);
|
||||
|
||||
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
|
||||
|
||||
$this->proxyFactory = new ProxyFactory(
|
||||
$this->emMock,
|
||||
sys_get_temp_dir(),
|
||||
'Proxies',
|
||||
ProxyFactory::AUTOGENERATE_ALWAYS,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractClass
|
||||
|
||||
@@ -452,6 +452,8 @@ class SelectSqlGenerationTest extends OrmTestCase
|
||||
|
||||
public function testSupportsTrimFunction(): void
|
||||
{
|
||||
$this->entityManager = $this->createTestEntityManagerWithPlatform(new MySQLPlatform());
|
||||
|
||||
$this->assertSqlGeneration(
|
||||
"SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE TRIM(TRAILING ' ' FROM u.name) = 'someone'",
|
||||
"SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE TRIM(TRAILING ' ' FROM c0_.name) = 'someone'",
|
||||
@@ -461,6 +463,8 @@ class SelectSqlGenerationTest extends OrmTestCase
|
||||
#[Group('DDC-2668')]
|
||||
public function testSupportsTrimLeadingZeroString(): void
|
||||
{
|
||||
$this->entityManager = $this->createTestEntityManagerWithPlatform(new MySQLPlatform());
|
||||
|
||||
$this->assertSqlGeneration(
|
||||
"SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE TRIM(TRAILING '0' FROM u.name) != ''",
|
||||
"SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE TRIM(TRAILING '0' FROM c0_.name) <> ''",
|
||||
@@ -584,6 +588,8 @@ class SelectSqlGenerationTest extends OrmTestCase
|
||||
#[Group('DDC-1802')]
|
||||
public function testSupportsNotInExpressionForModFunction(): void
|
||||
{
|
||||
$this->entityManager = $this->createTestEntityManagerWithPlatform(new MySQLPlatform());
|
||||
|
||||
$this->assertSqlGeneration(
|
||||
'SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE MOD(u.id, 5) NOT IN(1,3,4)',
|
||||
'SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE MOD(c0_.id, 5) NOT IN (1, 3, 4)',
|
||||
@@ -1925,6 +1931,8 @@ SQL,
|
||||
#[Group('DDC-2268')]
|
||||
public function testCaseThenFunction(): void
|
||||
{
|
||||
$this->entityManager = $this->createTestEntityManagerWithPlatform(new PostgreSQLPlatform());
|
||||
|
||||
$this->assertSqlGeneration(
|
||||
'SELECT CASE WHEN LENGTH(u.name) <> 0 THEN CONCAT(u.id, u.name) ELSE u.id END AS name FROM Doctrine\Tests\Models\CMS\CmsUser u',
|
||||
'SELECT CASE WHEN LENGTH(c0_.name) <> 0 THEN c0_.id || c0_.name ELSE c0_.id END AS sclr_0 FROM cms_users c0_',
|
||||
|
||||
@@ -135,7 +135,7 @@ class SchemaValidatorTest extends OrmTestCase
|
||||
[
|
||||
'The field Doctrine\Tests\ORM\Tools\DDC3274One#two is on the inverse side of a bi-directional ' .
|
||||
'relationship, but the specified mappedBy association on the target-entity ' .
|
||||
"Doctrine\Tests\ORM\Tools\DDC3274Two#one does not contain the required 'inversedBy=\"two\"' attribute.",
|
||||
"Doctrine\Tests\ORM\Tools\DDC3274Two#one does not contain the required 'inversedBy: \"two\"' attribute.",
|
||||
],
|
||||
$ce,
|
||||
);
|
||||
@@ -151,7 +151,7 @@ class SchemaValidatorTest extends OrmTestCase
|
||||
[
|
||||
'The field Doctrine\Tests\ORM\Tools\Issue9536Owner#one is on the owning side of a bi-directional ' .
|
||||
'relationship, but the specified inversedBy association on the target-entity ' .
|
||||
"Doctrine\Tests\ORM\Tools\Issue9536Target#two does not contain the required 'mappedBy=\"one\"' " .
|
||||
"Doctrine\Tests\ORM\Tools\Issue9536Target#two does not contain the required 'mappedBy: \"one\"' " .
|
||||
'attribute.',
|
||||
],
|
||||
$ce,
|
||||
|
||||
@@ -8,9 +8,7 @@ use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Driver;
|
||||
use Doctrine\DBAL\Driver\Result;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Schema\AbstractSchemaManager;
|
||||
use Doctrine\DBAL\Schema\Name\UnquotedIdentifierFolding;
|
||||
use Doctrine\DBAL\Schema\SchemaConfig;
|
||||
use Doctrine\DBAL\Platforms\SQLitePlatform;
|
||||
use Doctrine\ORM\Cache\CacheConfiguration;
|
||||
use Doctrine\ORM\Cache\CacheFactory;
|
||||
use Doctrine\ORM\Cache\DefaultCacheFactory;
|
||||
@@ -22,11 +20,14 @@ use PHPUnit\Framework\TestCase;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
|
||||
use function enum_exists;
|
||||
use function class_exists;
|
||||
use function method_exists;
|
||||
use function realpath;
|
||||
use function sprintf;
|
||||
|
||||
// DBAL 3 compatibility
|
||||
class_exists('Doctrine\\DBAL\\Platforms\\SqlitePlatform');
|
||||
|
||||
/**
|
||||
* Base testcase class for all ORM testcases.
|
||||
*/
|
||||
@@ -71,9 +72,7 @@ abstract class OrmTestCase extends TestCase
|
||||
*/
|
||||
protected function getTestEntityManager(): EntityManagerMock
|
||||
{
|
||||
return $this->buildTestEntityManagerWithPlatform(
|
||||
$this->createConnectionMock($this->createPlatformMock()),
|
||||
);
|
||||
return $this->createTestEntityManagerWithPlatform(new SQLitePlatform());
|
||||
}
|
||||
|
||||
protected function createTestEntityManagerWithConnection(Connection $connection): EntityManagerMock
|
||||
@@ -153,24 +152,6 @@ abstract class OrmTestCase extends TestCase
|
||||
return $connection;
|
||||
}
|
||||
|
||||
private function createPlatformMock(): AbstractPlatform
|
||||
{
|
||||
$schemaManager = $this->createMock(AbstractSchemaManager::class);
|
||||
$schemaManager->method('createSchemaConfig')
|
||||
->willReturn(new SchemaConfig());
|
||||
|
||||
$platform = $this->getMockBuilder(AbstractPlatform::class)
|
||||
->setConstructorArgs(enum_exists(UnquotedIdentifierFolding::class) ? [UnquotedIdentifierFolding::UPPER] : [])
|
||||
->onlyMethods(['supportsIdentityColumns', 'createSchemaManager'])
|
||||
->getMockForAbstractClass();
|
||||
$platform->method('supportsIdentityColumns')
|
||||
->willReturn(true);
|
||||
$platform->method('createSchemaManager')
|
||||
->willReturn($schemaManager);
|
||||
|
||||
return $platform;
|
||||
}
|
||||
|
||||
private function createDriverMock(AbstractPlatform $platform): Driver
|
||||
{
|
||||
$result = $this->createMock(Result::class);
|
||||
|
||||
Reference in New Issue
Block a user