diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ad3633e9..e4eb02e3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -164,6 +164,8 @@ jobs: include: - php-version: "8.3" update-packages: "composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctrine-types:^3 gedmo/doctrine-extensions:^3 -W" + - php-version: "8.4" + update-packages: "composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctrine-types:^3 gedmo/doctrine-extensions:^3 symfony/cache:^6.4 symfony/clock:^6.4 symfony/doctrine-bridge:^7.3 symfony/validator:^6.4 -W" steps: - name: "Checkout" diff --git a/.github/workflows/platform-test.yml b/.github/workflows/platform-test.yml index 38110353..f168cf8c 100644 --- a/.github/workflows/platform-test.yml +++ b/.github/workflows/platform-test.yml @@ -37,7 +37,7 @@ jobs: - php-version: "8.3" update-packages: doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctrine-types:^3 gedmo/doctrine-extensions:^3 - php-version: "8.4" - update-packages: doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctrine-types:^3 gedmo/doctrine-extensions:^3 + update-packages: doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctrine-types:^3 gedmo/doctrine-extensions:^3 symfony/cache:^6.4 symfony/clock:^6.4 symfony/doctrine-bridge:^7.3 symfony/validator:^6.4 steps: - name: "Checkout" diff --git a/compatibility/without-symfony-bridge-baseline.php b/compatibility/without-symfony-bridge-baseline.php new file mode 100644 index 00000000..24437da4 --- /dev/null +++ b/compatibility/without-symfony-bridge-baseline.php @@ -0,0 +1,14 @@ + but returns string\.$#' + identifier: return.type + count: 1 + path: src/Type/Doctrine/Descriptors/Symfony/DatePointTypeDescriptor.php + + - + message: '#^Parameter \#2 \$className of static method Doctrine\\DBAL\\Types\\Type\:\:addType\(\) expects class\-string\, string given\.$#' + identifier: argument.type + count: 1 + path: tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php diff --git a/phpstan.neon b/phpstan.neon index efbf455d..8d9a184b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,6 +5,7 @@ includes: - phpstan-baseline-deprecations.neon - phpstan-baseline-dbal-3.neon - compatibility/orm-3-baseline.php + - compatibility/without-symfony-bridge-baseline.php - vendor/phpstan/phpstan-strict-rules/rules.neon - vendor/phpstan/phpstan-deprecation-rules/rules.neon - vendor/phpstan/phpstan-phpunit/extension.neon diff --git a/src/Type/Doctrine/Descriptors/Symfony/DatePointTypeDescriptor.php b/src/Type/Doctrine/Descriptors/Symfony/DatePointTypeDescriptor.php new file mode 100644 index 00000000..8833d09e --- /dev/null +++ b/src/Type/Doctrine/Descriptors/Symfony/DatePointTypeDescriptor.php @@ -0,0 +1,35 @@ +objectManagerLoader, __DIR__ . '/../../../../tmp'), @@ -79,6 +85,7 @@ protected function getRule(): Rule new ReflectionDescriptor(CarbonType::class, $this->createReflectionProvider(), self::getContainer()), new ReflectionDescriptor(CustomType::class, $this->createReflectionProvider(), self::getContainer()), new ReflectionDescriptor(CustomNumericType::class, $this->createReflectionProvider(), self::getContainer()), + new DatePointTypeDescriptor(), ]), $this->createReflectionProvider(), true, @@ -180,6 +187,33 @@ public function testRule(?string $objectManagerLoader): void $this->analyse([__DIR__ . '/data/MyBrokenEntity.php'], $errors); } + + /** + * @dataProvider dataObjectManagerLoader + */ + public function testRuleSymfony(?string $objectManagerLoader): void + { + if (!InstalledVersions::isInstalled('symfony/doctrine-bridge')) { + self::markTestSkipped('symfony/doctrine-bridge'); + } + + $this->allowNullablePropertyForRequiredField = false; + $this->objectManagerLoader = $objectManagerLoader; + + $errors = [ + [ + 'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: database can contain Symfony\Component\Clock\DatePoint but property expects DateTime.', + 175, + ], + [ + 'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: property can contain DateTime but database expects Symfony\Component\Clock\DatePoint.', + 175, + ], + ]; + + $this->analyse([__DIR__ . '/data/MySymfonyBrokenEntity.php'], $errors); + } + /** * @dataProvider dataObjectManagerLoader */ diff --git a/tests/Rules/Doctrine/ORM/data/MyBrokenEntity.php b/tests/Rules/Doctrine/ORM/data/MyBrokenEntity.php index a2a9e3f7..e35c84a2 100644 --- a/tests/Rules/Doctrine/ORM/data/MyBrokenEntity.php +++ b/tests/Rules/Doctrine/ORM/data/MyBrokenEntity.php @@ -166,4 +166,5 @@ class MyBrokenEntity extends MyBrokenSuperclass * @var list */ private $validSimpleArray; + } diff --git a/tests/Rules/Doctrine/ORM/data/MySymfonyBrokenEntity.php b/tests/Rules/Doctrine/ORM/data/MySymfonyBrokenEntity.php new file mode 100644 index 00000000..2105761d --- /dev/null +++ b/tests/Rules/Doctrine/ORM/data/MySymfonyBrokenEntity.php @@ -0,0 +1,24 @@ +