Skip to content

Commit

Permalink
Merge branch '2.12.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.12.x:
  Introduce __unserialize behaviour in docs (doctrine#9390)
  Adapt test logic to PHP and SQLite II (doctrine#9442)
  Use the identify generator strategy
  Added php 8.1 to CI
  Psalm 4.19.0, PHPStan 1.4.3 (doctrine#9438)
  Ignore PHPUnit result cache everywhere (doctrine#9425)
  • Loading branch information
derrabus committed Jan 30, 2022
2 parents 31b7d78 + e9e54d8 commit a5f5910
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 49 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"
dbal-version:
- "default"
postgres-version:
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"
dbal-version:
- "default"
mariadb-version:
Expand Down Expand Up @@ -191,7 +191,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"
dbal-version:
- "default"
mysql-version:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ vendor/
/tests/Doctrine/Performance/history.db
/.phpcs-cache
composer.lock
/.phpunit.result.cache
.phpunit.result.cache
/*.phpunit.xml
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
"doctrine/annotations": "^1.13",
"doctrine/coding-standard": "^9.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "1.4.1",
"phpstan/phpstan": "1.4.3",
"phpunit/phpunit": "^9.5",
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.6.2",
"symfony/cache": "^4.4 || ^5.4 || ^6.0",
"vimeo/psalm": "4.18.1"
"vimeo/psalm": "4.19.0"
},
"conflict": {
"doctrine/annotations": "<1.13 || >= 2.0"
Expand Down
13 changes: 9 additions & 4 deletions docs/en/reference/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ be any regular PHP class observing the following restrictions:
:doc:`do so safely <../cookbook/implementing-wakeup-or-clone>`.
- An entity class must not implement ``__wakeup`` or
:doc:`do so safely <../cookbook/implementing-wakeup-or-clone>`.
Also consider implementing
`Serializable <https://php.net/manual/en/class.serializable.php>`_
instead.
You can also consider implementing
`Serializable <https://php.net/manual/en/class.serializable.php>`_,
but be aware that it is deprecated since PHP 8.1. We do not recommend its usage.
- PHP 7.4 introduces :doc:`the new magic method <https://php.net/manual/en/language.oop5.magic.php#object.unserialize>`
``__unserialize``, which changes the execution priority between
``__wakeup`` and itself when used. This can cause unexpected behaviour in
an Entity.
- Any two entity classes in a class hierarchy that inherit
directly or indirectly from one another must not have a mapped
property with the same name. That is, if B inherits from A then B
Expand Down Expand Up @@ -162,7 +166,8 @@ possible for ``__sleep`` to return names of private properties in
parent classes. On the other hand it is not a solution for proxy
objects to implement ``Serializable`` because Serializable does not
work well with any potential cyclic object references (at least we
did not find a way yet, if you did, please contact us).
did not find a way yet, if you did, please contact us). The
``Serializable`` interface is also deprecated beginning with PHP 8.1.

The EntityManager
~~~~~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions lib/Doctrine/ORM/PersistentCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ public function offsetExists($offset): bool
/**
* {@inheritdoc}
*/
#[ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->get($offset);
Expand Down
73 changes: 56 additions & 17 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.18.1@dda05fa913f4dc6eb3386f2f7ce5a45d37a71bcb">
<files psalm-version="4.19.0@a2ad69ae4f5ab1f7d225a8dc4e2ec2d9415ed599">
<file src="lib/Doctrine/ORM/AbstractQuery.php">
<FalsableReturnStatement occurrences="1">
<code>! $filteredParameters-&gt;isEmpty() ? $filteredParameters-&gt;first() : null</code>
Expand Down Expand Up @@ -604,6 +604,9 @@
<code>$className</code>
<code>$this-&gt;namespace . '\\' . $className</code>
</LessSpecificReturnStatement>
<MethodSignatureMustProvideReturnType occurrences="1">
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
<MissingClosureParamType occurrences="2">
<code>$joinColumn</code>
<code>$joinColumn</code>
Expand All @@ -630,15 +633,14 @@
<code>$fieldName</code>
<code>$fieldName</code>
</ParamNameMismatch>
<PossiblyNullArgument occurrences="8">
<PossiblyNullArgument occurrences="7">
<code>$class</code>
<code>$className</code>
<code>$entityResult['entityClass']</code>
<code>$mapping['targetEntity']</code>
<code>$mapping['targetEntity']</code>
<code>$parentReflFields[$embeddedClass['declaredField']]</code>
<code>$parentReflFields[$mapping['declaredField']]</code>
<code>$queryMapping['resultClass']</code>
</PossiblyNullArgument>
<PossiblyNullPropertyFetch occurrences="2">
<code>$embeddable-&gt;reflClass-&gt;name</code>
Expand Down Expand Up @@ -871,7 +873,7 @@
<code>$indexXml-&gt;options</code>
<code>$uniqueXml-&gt;options</code>
</PossiblyInvalidPropertyFetch>
<RedundantCondition occurrences="19">
<RedundantCondition occurrences="17">
<code>isset($xmlRoot-&gt;cache)</code>
<code>isset($xmlRoot-&gt;embedded)</code>
<code>isset($xmlRoot-&gt;field)</code>
Expand All @@ -890,7 +892,7 @@
<code>isset($xmlRoot-&gt;{'sql-result-set-mappings'})</code>
<code>isset($xmlRoot-&gt;{'unique-constraints'})</code>
</RedundantCondition>
<UndefinedInterfaceMethod occurrences="34">
<UndefinedInterfaceMethod occurrences="32">
<code>addEntityListener</code>
<code>addLifecycleCallback</code>
<code>addSqlResultSetMapping</code>
Expand Down Expand Up @@ -1765,6 +1767,9 @@
<DocblockTypeContradiction occurrences="1">
<code>is_array($obj)</code>
</DocblockTypeContradiction>
<MethodSignatureMustProvideReturnType occurrences="1">
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
<RedundantConditionGivenDocblockType occurrences="1">
<code>is_object($obj)</code>
</RedundantConditionGivenDocblockType>
Expand Down Expand Up @@ -1958,22 +1963,46 @@
<ArgumentTypeCoercion occurrences="1">
<code>$this-&gt;parts</code>
</ArgumentTypeCoercion>
<MethodSignatureMustProvideReturnType occurrences="1">
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
<PossiblyInvalidCast occurrences="1">
<code>$this-&gt;parts[0]</code>
</PossiblyInvalidCast>
</file>
<file src="lib/Doctrine/ORM/Query/Expr/Comparison.php">
<MethodSignatureMustProvideReturnType occurrences="1">
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
</file>
<file src="lib/Doctrine/ORM/Query/Expr/Composite.php">
<MethodSignatureMustProvideReturnType occurrences="1">
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
<PossiblyInvalidCast occurrences="2">
<code>$part</code>
<code>$this-&gt;parts[0]</code>
</PossiblyInvalidCast>
</file>
<file src="lib/Doctrine/ORM/Query/Expr/From.php">
<MethodSignatureMustProvideReturnType occurrences="1">
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
</file>
<file src="lib/Doctrine/ORM/Query/Expr/Func.php">
<MethodSignatureMustProvideReturnType occurrences="1">
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
</file>
<file src="lib/Doctrine/ORM/Query/Expr/GroupBy.php">
<NonInvariantDocblockPropertyType occurrences="1">
<code>$parts</code>
</NonInvariantDocblockPropertyType>
</file>
<file src="lib/Doctrine/ORM/Query/Expr/Join.php">
<MethodSignatureMustProvideReturnType occurrences="1">
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
<PossiblyNullArgument occurrences="1">
<code>$this-&gt;conditionType</code>
</PossiblyNullArgument>
Expand All @@ -1983,6 +2012,16 @@
<code>$parts</code>
</NonInvariantDocblockPropertyType>
</file>
<file src="lib/Doctrine/ORM/Query/Expr/Math.php">
<MethodSignatureMustProvideReturnType occurrences="1">
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
</file>
<file src="lib/Doctrine/ORM/Query/Expr/OrderBy.php">
<MethodSignatureMustProvideReturnType occurrences="1">
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
</file>
<file src="lib/Doctrine/ORM/Query/Expr/Orx.php">
<NonInvariantDocblockPropertyType occurrences="2">
<code>$allowedClasses</code>
Expand All @@ -1996,6 +2035,9 @@
</NonInvariantDocblockPropertyType>
</file>
<file src="lib/Doctrine/ORM/Query/Filter/SQLFilter.php">
<MethodSignatureMustProvideReturnType occurrences="1">
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
<MissingClosureParamType occurrences="1">
<code>$value</code>
</MissingClosureParamType>
Expand Down Expand Up @@ -2230,9 +2272,9 @@
</PropertyNotSetInConstructor>
</file>
<file src="lib/Doctrine/ORM/Query/QueryExpressionVisitor.php">
<RedundantCondition occurrences="1">
<RedundantConditionGivenDocblockType occurrences="1">
<code>Comparison::EQ</code>
</RedundantCondition>
</RedundantConditionGivenDocblockType>
</file>
<file src="lib/Doctrine/ORM/Query/ResultSetMapping.php">
<PropertyTypeCoercion occurrences="3">
Expand All @@ -2242,21 +2284,15 @@
</PropertyTypeCoercion>
</file>
<file src="lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php">
<ArgumentTypeCoercion occurrences="5">
<code>$class</code>
<ArgumentTypeCoercion occurrences="4">
<code>$class</code>
<code>$class</code>
<code>$renameMode</code>
<code>$renameMode</code>
</ArgumentTypeCoercion>
<PossiblyNullPropertyFetch occurrences="1">
<code>$classMetadata-&gt;reflClass-&gt;name</code>
</PossiblyNullPropertyFetch>
<PossiblyNullReference occurrences="3">
<code>getShortName</code>
<code>getShortName</code>
<code>getShortName</code>
</PossiblyNullReference>
<MethodSignatureMustProvideReturnType occurrences="1">
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
</file>
<file src="lib/Doctrine/ORM/Query/SqlWalker.php">
<DocblockTypeContradiction occurrences="6">
Expand Down Expand Up @@ -2626,6 +2662,9 @@
<InvalidScalarArgument occurrences="1">
<code>$key</code>
</InvalidScalarArgument>
<MethodSignatureMustProvideReturnType occurrences="1">
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
<PossiblyFalseArgument occurrences="2">
<code>$spacePos</code>
<code>$spacePos</code>
Expand Down
18 changes: 0 additions & 18 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,6 @@
<file name="lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php"/>
</errorLevel>
</MissingDependency>
<NoInterfaceProperties>
<errorLevel type="suppress">
<!-- see https://github.com/vimeo/psalm/issues/7364 -->
<referencedClass name="BackedEnum"/>
</errorLevel>
</NoInterfaceProperties>
<ParadoxicalCondition>
<errorLevel type="suppress">
<!-- See https://github.com/vimeo/psalm/issues/3381 -->
<file name="lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php"/>
</errorLevel>
</ParadoxicalCondition>
<NullArgument>
<errorLevel type="suppress">
<!-- See https://github.com/vimeo/psalm/issues/5920 -->
<file name="lib/Doctrine/ORM/Mapping/Driver/AttributeReader.php"/>
</errorLevel>
</NullArgument>
<RedundantCastGivenDocblockType>
<errorLevel type="suppress">
<!-- Can be removed once the "getMaxResults" methods of those classes have native parameter types -->
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/ReadonlyProperties/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#[Entity, Table(name: 'author')]
class Author
{
#[Column, Id, GeneratedValue]
#[Column, Id, GeneratedValue(strategy: 'IDENTITY')]
private readonly int $id;

#[Column]
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/ReadonlyProperties/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#[Entity, Table(name: 'book')]
class Book
{
#[Column, Id, GeneratedValue]
#[Column, Id, GeneratedValue(strategy: 'IDENTITY')]
private readonly int $id;

#[Column]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#[Entity, Table(name: 'simple_book')]
class SimpleBook
{
#[Column, Id, GeneratedValue]
#[Column, Id, GeneratedValue(strategy: 'IDENTITY')]
private readonly int $id;

#[Column]
Expand Down
12 changes: 11 additions & 1 deletion tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,18 @@ public function testDateAdd(string $unit, int $amount, int $delta = 0): void
self::assertArrayHasKey('now', $result);
self::assertArrayHasKey('add', $result);

$now = new DateTimeImmutable($result['now']);
$inOneUnit = $now->modify(sprintf('+%d %s', $amount, $unit));
if (
$unit === 'month'
&& $inOneUnit->format('m') === $now->modify('+2 month')->format('m')
&& ! $this->_em->getConnection()->getDatabasePlatform() instanceof SqlitePlatform
) {
$inOneUnit = new DateTimeImmutable('last day of next month');
}

self::assertEqualsWithDelta(
(new DateTimeImmutable($result['now']))->modify(sprintf('+%d %s', $amount, $unit)),
$inOneUnit,
new DateTimeImmutable($result['add']),
$delta
);
Expand Down

0 comments on commit a5f5910

Please sign in to comment.