Skip to content

Commit

Permalink
PHP8 Support (#8303)
Browse files Browse the repository at this point in the history
* Update doctrine/dbal to 2.12 for PHP 8 support.

* Change Query\Parser::match to Query\Parser::matchToken including DQL functions.

* Fix phpunit constraint to 9.4, adjust @group usage to workaround PHPUnit bug.

* Fix PHPUnit API related changes.

* Add PHP 8 support for EntityGenerator namespace detection.

* Use new assertEqualsWithDetla for QueryDqlFunctionTest with date comparisons

* Replace ReflectionParameter::getClass usage with non-deprecated ::getType instead.

* Revert "Change Query\Parser::match to Query\Parser::matchToken including DQL functions."

This reverts commit 2790704.

* More matchToken => match reverts

* Housekeeping: phpcs

* Housekeeping: phpcs

* Housekeeping: phpcs

* Housekeeping: phpcs

* Add PHP 8 testrunner, update composer.json and small fix in OrmFunctionalTestCase for new PHPUnit behvaior

* Update doctrine/coding-standard to 8.x

* Update rule names for doctrine/coding-standard v8.0

* Update to Psalm 4.

* Not failOnWarning anymore.

* Fix phpcs

* fix phpcs

* remove 7.2 for now until we can support in DBAL.

* Relax doctrine/dbal requirement and add 7.2 CI support again.
  • Loading branch information
beberlei committed Nov 15, 2020
1 parent 51bc596 commit 3d46e07
Show file tree
Hide file tree
Showing 36 changed files with 61 additions and 70 deletions.
1 change: 1 addition & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
deps:
- "normal"
include:
Expand Down
1 change: 0 additions & 1 deletion ci/github/phpunit/mysqli.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
>
<php>
<var name="db_driver" value="mysqli"/>
Expand Down
1 change: 0 additions & 1 deletion ci/github/phpunit/pdo_mysql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
>
<php>
<var name="db_driver" value="pdo_mysql"/>
Expand Down
1 change: 0 additions & 1 deletion ci/github/phpunit/pdo_pgsql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
>
<php>
<var name="db_driver" value="pdo_pgsql"/>
Expand Down
1 change: 0 additions & 1 deletion ci/github/phpunit/sqlite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
>
<php>
<!-- necessary change for some CLI/console output test assertions -->
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"sort-packages": true
},
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"ext-pdo": "*",
"composer/package-versions-deprecated": "^1.8",
"doctrine/annotations": "^1.11.1",
Expand All @@ -32,9 +32,9 @@
"symfony/console": "^3.0|^4.0|^5.0"
},
"require-dev": {
"doctrine/coding-standard": "^6.0",
"doctrine/coding-standard": "^8.0",
"phpstan/phpstan": "^0.12.18",
"phpunit/phpunit": "^8.0",
"phpunit/phpunit": "^8.5|^9.4",
"symfony/yaml": "^3.4|^4.0|^5.0",
"vimeo/psalm": "4.1.1"
},
Expand Down
5 changes: 5 additions & 0 deletions lib/Doctrine/ORM/Tools/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use ReflectionClass;
use const E_USER_DEPRECATED;
use const PHP_VERSION_ID;
use function str_replace;
use function trigger_error;
use function var_export;
Expand Down Expand Up @@ -819,6 +820,8 @@ function ($type, $variable) use ($maxParamTypeLength) {
/**
* @todo this won't work if there is a namespace in brackets and a class outside of it.
*
* @psalm-suppress UndefinedConstant
*
* @param string $src
*
* @return void
Expand All @@ -842,6 +845,8 @@ protected function parseTokensInEntityFile($src)
if ($inNamespace) {
if (in_array($token[0], [T_NS_SEPARATOR, T_STRING], true)) {
$lastSeenNamespace .= $token[1];
} elseif (PHP_VERSION_ID >= 80000 && ($token[0] === T_NAME_QUALIFIED || $token[0] === T_NAME_FULLY_QUALIFIED)) {
$lastSeenNamespace .= $token[1];
} elseif (is_string($token) && in_array($token, [';', '{'], true)) {
$inNamespace = false;
}
Expand Down
12 changes: 6 additions & 6 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<exclude-pattern>*/tests/Doctrine/Tests/Proxies/__CG__/*</exclude-pattern>

<rule ref="Doctrine">
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint"/>
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException"/>
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
Expand All @@ -37,7 +37,7 @@
<exclude-pattern>lib/Doctrine/ORM/Tools/ToolEvents.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification">
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification">
<exclude-pattern>lib/Doctrine/ORM/Annotation/*</exclude-pattern>
</rule>

Expand Down Expand Up @@ -109,27 +109,27 @@
<exclude-pattern>lib/Doctrine/ORM/EntityManagerInterface.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingPropertyTypeHint">
<rule name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingAnyTypeHint">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedProperty">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification">
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements.WriteOnlyProperty">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification">
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification">
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function setUp() : void
}

/**
* @group 6759
* @group GH-6759
*/
public function testInverseSideOneToOneLoadedAfterDqlQuery(): void
{
Expand Down
6 changes: 2 additions & 4 deletions tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ public function testDateAdd(string $unit, int $amount, int $delta = 0) : void
self::assertEqualsWithDelta(
(new \DateTimeImmutable($result['now']))->modify(sprintf('+%d %s', $amount, $unit)),
new \DateTimeImmutable($result['add']),
$delta,
''
$delta
);
}

Expand Down Expand Up @@ -342,8 +341,7 @@ public function testDateSub(string $unit, int $amount, int $delta = 0) : void
self::assertEqualsWithDelta(
(new \DateTimeImmutable($result['now']))->modify(sprintf('-%d %s', $amount, $unit)),
new \DateTimeImmutable($result['sub']),
$delta,
''
$delta
);
}

Expand Down
1 change: 0 additions & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ protected function setUp() : void
$this->_em->getClassMetadata(DDC144Operand::class),
]
);

}

/**
Expand Down
7 changes: 4 additions & 3 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3123Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Doctrine\ORM\Events;
use Doctrine\ORM\UnitOfWork;
use Doctrine\Tests\Models\CMS\CmsUser;
use ReflectionClass;
use ReflectionObject;

/**
* @group DDC-3123
Expand Down Expand Up @@ -38,8 +38,9 @@ public function testIssue()
->expects($this->once())
->method(Events::postFlush)
->will($this->returnCallback(function () use ($uow, $test) {
$class = new ReflectionClass(UnitOfWork::class);
$property = $class->getProperty('extraUpdates');
$reflection = new ReflectionObject($uow);
$property = $reflection->getProperty('extraUpdates');

$property->setAccessible(true);
$test->assertEmpty(
$property->getValue($uow),
Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3303Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ protected function setUp() : void
}

/**
* @group 4097
* @group 4277
* @group 5867
* @group GH-4097
* @group GH-4277
* @group GH-5867
*
* When using an embedded field in an inheritance, private properties should also be inherited.
*/
Expand Down
3 changes: 2 additions & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ protected function setUp() : void
/**
* @group DDC-3597
*/
public function testSaveImageEntity() {
public function testSaveImageEntity(): void
{
$imageEntity = new DDC3597Image('foobar');
$imageEntity->setFormat('JPG');
$imageEntity->setSize(123);
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH2947Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Doctrine\Tests\OrmFunctionalTestCase;

/**
* @group 2947
* @group GH-2947
*/
class GH2947Test extends OrmFunctionalTestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH5562Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function setUp() : void
}

/**
* @group 5562
* @group GH-5562
*/
public function testCacheShouldBeUpdatedWhenAssociationChanges()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Doctrine\Tests\OrmFunctionalTestCase;

/**
* @group 5804
* @group GH-5804
*/
final class GH5804Test extends OrmFunctionalTestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH5887Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Doctrine\Tests\OrmFunctionalTestCase;

/**
* @group 5887
* @group GH-5887
*/
class GH5887Test extends OrmFunctionalTestCase
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH6029Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function setUp() : void
* Verifies that when wrong entity is persisted via relationship field, the error message does not correctly state
* the expected class name.
*
* @group 6029
* @group GH-6029
*/
public function testManyToManyAssociation() : void
{
Expand All @@ -55,7 +55,7 @@ public function testManyToManyAssociation() : void
* Verifies that when wrong entity is persisted via relationship field, the error message does not correctly state
* the expected class name.
*
* @group 6029
* @group GH-6029
*/
public function testOneToManyAssociation() : void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function setUp() : void
* of using objects as discriminators (which makes things a bit
* more dynamic as you can see on the mapping of `GH6141Person`)
*
* @group 6141
* @group GH-6141
*/
public function testEnumDiscriminatorsShouldBeConvertedToString()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function setUp() : void
}

/**
* @group 6362
* @group GH-6362
*
* SELECT a as base, b, c, d
* FROM Start a
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH6402Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Doctrine\Tests\OrmFunctionalTestCase;

/**
* @group 6402
* @group GH-6402
*/
class GH6402Test extends OrmFunctionalTestCase
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH6531Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function setUp() : void
}

/**
* @group 6531
* @group GH-6531
*/
public function testSimpleDerivedIdentity() : void
{
Expand All @@ -41,7 +41,7 @@ public function testSimpleDerivedIdentity() : void
}

/**
* @group 6531
* @group GH-6531
*/
public function testDynamicAttributes() : void
{
Expand All @@ -58,7 +58,7 @@ public function testDynamicAttributes() : void
}

/**
* @group 6531
* @group GH-6531
*/
public function testJoinTableWithMetadata() : void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH6682Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
final class GH6682Test extends OrmFunctionalTestCase
{
/**
* @group 6682
* @group GH-6682
*/
public function testIssue() : void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH6699Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Doctrine\Tests\OrmFunctionalTestCase;

/**
* @group 6699
* @group GH-6699
*/
final class GH6699Test extends OrmFunctionalTestCase
{
Expand Down
10 changes: 5 additions & 5 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH6740Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function setUp() : void
}

/**
* @group 6740
* @group GH-6740
*/
public function testCollectionFilteringLteOperator() : void
{
Expand All @@ -63,7 +63,7 @@ public function testCollectionFilteringLteOperator() : void
}

/**
* @group 6740
* @group GH-6740
*/
public function testCollectionFilteringLtOperator() : void
{
Expand All @@ -74,7 +74,7 @@ public function testCollectionFilteringLtOperator() : void
}

/**
* @group 6740
* @group GH-6740
*/
public function testCollectionFilteringGteOperator() : void
{
Expand All @@ -85,7 +85,7 @@ public function testCollectionFilteringGteOperator() : void
}

/**
* @group 6740
* @group GH-6740
*/
public function testCollectionFilteringGtOperator() : void
{
Expand All @@ -96,7 +96,7 @@ public function testCollectionFilteringGtOperator() : void
}

/**
* @group 6740
* @group GH-6740
*/
public function testCollectionFilteringEqualsOperator() : void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH6937Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Doctrine\Tests\OrmFunctionalTestCase;

/**
* @group 6937
* @group GH-6937
*/
final class GH6937Test extends OrmFunctionalTestCase
{
Expand Down
Loading

0 comments on commit 3d46e07

Please sign in to comment.