Skip to content

Commit dd9d486

Browse files
achertovskyNyholm
andauthored
adding symfony8 to supported list (#1228)
* adding symfony8 to supported list * one more exclude, monolog bump * bump doctrine * doctrine annotations also * Revert "doctrine annotations also" This reverts commit aa26b81. * annotations 2.0 once more * opt-out from annotation if doctrine/orm >= 3 * fix: bridge * eliminate phpstan concenrns * trying to make validation tests pass * Revert "trying to make validation tests pass" This reverts commit 2553168. * do not skip tests * Revert "do not skip tests" This reverts commit d100da0. * monolog bump * Revert "Revert "trying to make validation tests pass"" This reverts commit b987e43. * Revert "Revert "Revert "trying to make validation tests pass""" This reverts commit ef4fb3a. * works for php8.4, sf8 * cq * cleanup * proper order is now, hmmm ... * reduce tests scope remove choice validation from tests as it was not consistent with other validators in version symfony/validator:7.3.* * cq * exclude phps prior to 8.4 from testing with sf8 * apply sorting on responses before comparing no need to expect same * do not test sf7 with 8.1 * exclude 7.2 lowest deps as issue with sorting in tests * sf8 one more exclude * fix CI config * handle parameters by name * revert index.md * fix cs and cleanup * collect coverage information from 2 jobs * fix cs --------- Co-authored-by: Tobias Nyholm <tobias.nyholm@gmail.com>
1 parent 1881475 commit dd9d486

6 files changed

Lines changed: 84 additions & 27 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ jobs:
3333
- php-version: '8.1'
3434
symfony-version: '7.4.*'
3535
include:
36+
- php-version: '8.4'
37+
symfony-version: '8.0.*'
38+
dependencies: 'lowest'
39+
- php-version: '8.4'
40+
symfony-version: '8.0.*'
41+
dependencies: 'highest'
42+
coverage: 'pcov'
3643
- php-version: '8.2'
3744
symfony-version: '5.4.*'
3845
dependencies: 'lowest'

composer.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
"phpdocumentor/reflection-docblock": "^5.2",
3939
"phpdocumentor/type-resolver": "^1.6.1",
4040
"psr/log": "^1.0 || ^2.0 || ^3.0",
41-
"symfony/config": "^5.4.46 || ^6.4.32 || ^7.0",
42-
"symfony/dependency-injection": "^5.4.48 || ^6.4.32 || ^7.0",
43-
"symfony/event-dispatcher": "^5.4.45 || ^6.4.32 || ^7.0",
44-
"symfony/expression-language": "^5.4.45 || ^6.4.32 || ^7.0",
45-
"symfony/framework-bundle": "^5.4.45 || ^6.4.32 || ^7.0",
46-
"symfony/http-foundation": "^5.4.50 || ^6.4.32 || ^7.0",
47-
"symfony/http-kernel": "^5.4.50 || ^6.4.32 || ^7.0",
48-
"symfony/options-resolver": "^5.4.45 || ^6.4.30 || ^7.0",
49-
"symfony/property-access": "^5.4.45 || ^6.4.32 || ^7.0",
41+
"symfony/config": "^5.4.46 || ^6.4.32 || ^7.0 || ^8.0",
42+
"symfony/dependency-injection": "^5.4.48 || ^6.4.32 || ^7.0 || ^8.0",
43+
"symfony/event-dispatcher": "^5.4.45 || ^6.4.32 || ^7.0 || ^8.0",
44+
"symfony/expression-language": "^5.4.45 || ^6.4.32 || ^7.0 || ^8.0",
45+
"symfony/framework-bundle": "^5.4.45 || ^6.4.32 || ^7.0 || ^8.0",
46+
"symfony/http-foundation": "^5.4.50 || ^6.4.32 || ^7.0 || ^8.0",
47+
"symfony/http-kernel": "^5.4.50 || ^6.4.32 || ^7.0 || ^8.0",
48+
"symfony/options-resolver": "^5.4.45 || ^6.4.30 || ^7.0 || ^8.0",
49+
"symfony/property-access": "^5.4.45 || ^6.4.32 || ^7.0 || ^8.0",
5050
"webonyx/graphql-php": "^15.24"
5151
},
5252
"suggest": {
@@ -56,8 +56,8 @@
5656
"symfony/translation": "If you want validation error messages to be translated."
5757
},
5858
"require-dev": {
59-
"doctrine/annotations": "^1.13",
60-
"doctrine/orm": "^2.5",
59+
"doctrine/annotations": "^1.14|^2.0",
60+
"doctrine/orm": "^2.20.9 || ^3.6",
6161
"monolog/monolog": "^2.8.0 || ^3.0",
6262
"php-cs-fixer/shim": "^3.93",
6363
"phpstan/extension-installer": "^1.0",
@@ -66,20 +66,20 @@
6666
"phpstan/phpstan-symfony": "^1.0",
6767
"phpunit/phpunit": "^10.5.63",
6868
"react/promise": "^2.5",
69-
"symfony/asset": "^5.4.45 || ^6.4.32 || ^7.0",
70-
"symfony/browser-kit": "^5.4.45 || ^6.4.32 || ^7.0",
71-
"symfony/console": "^5.4.47 || ^6.4.32 || ^7.0",
72-
"symfony/css-selector": "^5.4.45 || ^6.4.24 || ^7.0",
73-
"symfony/dom-crawler": "^5.4.48 || ^6.4.32 || ^7.0",
74-
"symfony/finder": "^5.4.45 || ^6.4.32 || ^7.0",
75-
"symfony/monolog-bundle": "^3.7",
69+
"symfony/asset": "^5.4.45 || ^6.4.32 || ^7.0 || ^8.0",
70+
"symfony/browser-kit": "^5.4.45 || ^6.4.32 || ^7.0 || ^8.0",
71+
"symfony/console": "^5.4.47 || ^6.4.32 || ^7.0 || ^8.0",
72+
"symfony/css-selector": "^5.4.45 || ^6.4.24 || ^7.0 || ^8.0",
73+
"symfony/dom-crawler": "^5.4.48 || ^6.4.32 || ^7.0 || ^8.0",
74+
"symfony/finder": "^5.4.45 || ^6.4.32 || ^7.0 || ^8.0",
75+
"symfony/monolog-bundle": "^3.7 || ^4.0",
7676
"symfony/phpunit-bridge": "^7.4.3",
77-
"symfony/process": "^5.4.47 || ^6.4.32 || ^7.0",
78-
"symfony/routing": "^5.4.48 || ^6.4.32 || ^7.0",
79-
"symfony/security-bundle": "^5.4.45 || ^6.4.32 || ^7.0",
80-
"symfony/validator": "^5.4.48 || ^6.4.31 || ^7.0",
81-
"symfony/var-dumper": "^5.4.48 || ^6.4.32 || ^7.0",
82-
"symfony/yaml": "^5.4.45 || ^6.4.30 || ^7.0",
77+
"symfony/process": "^5.4.47 || ^6.4.32 || ^7.0 || ^8.0",
78+
"symfony/routing": "^5.4.48 || ^6.4.32 || ^7.0 || ^8.0",
79+
"symfony/security-bundle": "^5.4.45 || ^6.4.32 || ^7.0 || ^8.0",
80+
"symfony/validator": "^5.4.48 || ^6.4.31 || ^7.0 || ^8.0",
81+
"symfony/var-dumper": "^5.4.48 || ^6.4.32 || ^7.0 || ^8.0",
82+
"symfony/yaml": "^5.4.45 || ^6.4.30 || ^7.0 || ^8.0",
8383
"twig/twig": "^2.10|^3.0"
8484
},
8585
"conflict": {

phpstan-baseline.neon

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,3 +590,22 @@ parameters:
590590
count: 1
591591
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
592592

593+
-
594+
message: "#^Call to function method_exists\\(\\) with '.*AnnotationRegistry' and 'registerLoader' will always evaluate to false\\.$#"
595+
count: 1
596+
path: src/Config/Parser/AnnotationParser.php
597+
598+
-
599+
message: "#^Call to an undefined static method Doctrine\\\\Common\\\\Annotations\\\\AnnotationRegistry\\:\\:registerLoader\\(\\)\\.$#"
600+
count: 1
601+
path: src/Config/Parser/AnnotationParser.php
602+
603+
-
604+
message: "#^Method Overblog\\\\GraphQLBundle\\\\Config\\\\Parser\\\\MetadataParser\\\\TypeGuesser\\\\DoctrineTypeGuesser\\:\\:getAnnotation\\(\\) has invalid return type Doctrine\\\\ORM\\\\Mapping\\\\Annotation\\.$#"
605+
count: 1
606+
path: src/Config/Parser/MetadataParser/TypeGuesser/DoctrineTypeGuesser.php
607+
608+
-
609+
message: "#^PHPDoc tag @var for variable \\$annotation contains unknown class Doctrine\\\\ORM\\\\Mapping\\\\Annotation\\.$#"
610+
count: 1
611+
path: src/Config/Parser/MetadataParser/TypeGuesser/DoctrineTypeGuesser.php

src/Config/Parser/MetadataParser/TypeGuesser/DoctrineTypeGuesser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public function getName(): string
3535

3636
public function supports(Reflector $reflector): bool
3737
{
38-
return $reflector instanceof ReflectionProperty;
38+
// If we are on doctrine/orm v2
39+
return class_exists(\Doctrine\ORM\Version::class) && $reflector instanceof ReflectionProperty;
3940
}
4041

4142
/**

src/Generator/TypeBuilder.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
use Overblog\GraphQLBundle\Generator\Converter\ExpressionConverter;
3333
use Overblog\GraphQLBundle\Generator\Exception\GeneratorException;
3434
use Overblog\GraphQLBundle\Validator\InputValidator;
35+
use ReflectionClass;
36+
use Symfony\Component\Validator\Constraints\Choice;
37+
use Symfony\Component\Validator\Constraints\Video;
3538

3639
use function array_map;
3740
use function class_exists;
@@ -81,6 +84,7 @@ final class TypeBuilder
8184
private string $type;
8285
private string $currentField;
8386
private string $gqlServices = '$'.TypeGenerator::GRAPHQL_SERVICES;
87+
private bool $isSymfony74Plus;
8488

8589
public function __construct(ExpressionConverter $expressionConverter, string $namespace)
8690
{
@@ -89,6 +93,7 @@ public function __construct(ExpressionConverter $expressionConverter, string $na
8993

9094
// Register additional converter in the php code generator
9195
Config::registerConverter($expressionConverter, ConverterInterface::TYPE_STRING);
96+
$this->isSymfony74Plus = class_exists(Video::class);
9297
}
9398

9499
/**
@@ -635,7 +640,32 @@ private function buildConstraints(array $constraints = [], bool $inClosure = tru
635640
}
636641

637642
if (is_array($args)) {
638-
if (isset($args[0]) && is_array($args[0])) {
643+
if ($this->isSymfony74Plus && isset($args[0]) && Choice::class === $fqcn) {
644+
// Handle Choice constraint in Symfony 7.4+
645+
$args = ['choices' => $args];
646+
}
647+
648+
/*
649+
* In Symfony 7.4+, we should not pass an array, but split up parameters in different arguments.
650+
*/
651+
if ($this->isSymfony74Plus && false === isset($args[0]) && [] !== $args) {
652+
$reflectionClass = new ReflectionClass($fqcn);
653+
$constructor = $reflectionClass->getConstructor();
654+
if (null === $constructor) {
655+
throw new GeneratorException("Constraint '$fqcn' doesn't have a constructor.");
656+
}
657+
$parameters = $constructor->getParameters();
658+
foreach ($parameters as $parameter) {
659+
$name = $parameter->getName();
660+
if (isset($args[$name])) {
661+
$instance->addArgument($args[$name]);
662+
} elseif ($parameter->isDefaultValueAvailable()) {
663+
$instance->addArgument($parameter->getDefaultValue());
664+
} else {
665+
throw new GeneratorException("Constraint '$fqcn' requires argument '$name'.");
666+
}
667+
}
668+
} elseif (isset($args[0]) && is_array($args[0])) {
639669
// Nested instance
640670
$instance->addArgument($this->buildConstraints($args, false));
641671
} elseif (isset($args['constraints'][0]) && is_array($args['constraints'][0])) {

tests/Config/Parser/TestMetadataParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static function isDoctrineAnnotationInstalled(): bool
9090

9191
public static function isDoctrineOrmInstalled(): bool
9292
{
93-
return class_exists(Column::class);
93+
return class_exists(Column::class) && class_exists(\Doctrine\ORM\Version::class);
9494
}
9595

9696
protected function expect(string $name, string $type, array $config = []): void

0 commit comments

Comments
 (0)