Skip to content

Commit

Permalink
chore: support symfony 7 (#6009)
Browse files Browse the repository at this point in the history
* chore: symfony 7

* Add `$buildDir` to `CachePoolClearerCacheWarmer::warmUp()`

Symfony 7 adds a new parameter `$buildDir` to
`WarmableInterface::warmUp()`, so that the method signature of
`CachePoolClearerCacheWarmer::warmUp()` needs to be updated.

* more

---------

Co-authored-by: Tac Tacelosky <tacman@gmail.com>
Co-authored-by: Yannick Ihmels <yannick@ihmels.org>
  • Loading branch information
3 people authored Nov 30, 2023
1 parent 82df722 commit 49b412e
Show file tree
Hide file tree
Showing 23 changed files with 111 additions and 105 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ jobs:
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Update project dependencies
run: composer update --no-interaction --no-progress --ansi
run: |
composer update --no-interaction --no-progress --ansi
- name: Install PHPUnit
run: vendor/bin/simple-phpunit --version
- name: Cache PHPStan results
Expand Down Expand Up @@ -451,6 +452,7 @@ jobs:
- name: Update project dependencies
run: |
composer update --no-interaction --no-progress --ansi
composer require --dev doctrine/mongodb-odm-bundle
- name: Install PHPUnit
run: vendor/bin/simple-phpunit --version
- name: Clear test app cache
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
*.log
/.php-cs-fixer.php
/.php-cs-fixer.cache
/.phpunit.result.cache
.phpunit.result.cache
/.phpunit.cache/
/build/
/composer.lock
composer.lock
/composer.phar
/phpstan.neon
/phpunit.xml
Expand Down
73 changes: 37 additions & 36 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"psr/container": "^1.0 || ^2.0",
"symfony/deprecation-contracts": "^3.1",
"symfony/http-foundation": "^6.1",
"symfony/http-kernel": "^6.1",
"symfony/property-access": "^6.1",
"symfony/property-info": "^6.1",
"symfony/serializer": "^6.1",
"symfony/http-foundation": "^6.1 || ^7.0",
"symfony/http-kernel": "^6.1 || ^7.0",
"symfony/property-access": "^6.1 || ^7.0",
"symfony/property-info": "^6.1 || ^7.0",
"symfony/serializer": "^6.1 || ^7.0",
"symfony/translation-contracts": "^3.3",
"symfony/web-link": "^6.1",
"symfony/web-link": "^6.1 || ^7.0",
"willdurand/negotiation": "^3.0"
},
"require-dev": {
Expand All @@ -35,7 +35,6 @@
"doctrine/dbal": "^3.4.0",
"doctrine/doctrine-bundle": "^1.12 || ^2.0",
"doctrine/mongodb-odm": "^2.2",
"doctrine/mongodb-odm-bundle": "^4.0",
"doctrine/orm": "^2.14",
"elasticsearch/elasticsearch": "^7.11.0",
"friends-of-behat/mink-browserkit-driver": "^1.3.1",
Expand All @@ -56,35 +55,36 @@
"ramsey/uuid-doctrine": "^1.4 || ^2.0",
"soyuka/contexts": "v3.3.9",
"soyuka/stubs-mongodb": "^1.0",
"symfony/asset": "^6.1",
"symfony/browser-kit": "^6.1",
"symfony/cache": "^6.1",
"symfony/config": "^6.1",
"symfony/console": "^6.1",
"symfony/css-selector": "^6.1",
"symfony/dependency-injection": "^6.1.12",
"symfony/doctrine-bridge": "^6.1",
"symfony/dom-crawler": "^6.1",
"symfony/error-handler": "^6.1",
"symfony/event-dispatcher": "^6.1",
"symfony/expression-language": "^6.1",
"symfony/finder": "^6.1",
"symfony/form": "^6.1",
"symfony/framework-bundle": "^6.1",
"symfony/http-client": "^6.1",
"symfony/intl": "^6.1",
"symfony/asset": "^6.1 || ^7.0",
"symfony/browser-kit": "^6.1 || ^7.0",
"symfony/cache": "^6.1 || ^7.0",
"symfony/config": "^6.1 || ^7.0",
"symfony/console": "^6.1 || ^7.0",
"symfony/css-selector": "^6.1 || ^7.0",
"symfony/dependency-injection": "^6.1 || ^7.0.12",
"symfony/doctrine-bridge": "^6.1 || ^7.0",
"symfony/dom-crawler": "^6.1 || ^7.0",
"symfony/error-handler": "^6.1 || ^7.0",
"symfony/event-dispatcher": "^6.1 || ^7.0",
"symfony/expression-language": "^6.1 || ^7.0",
"symfony/finder": "^6.1 || ^7.0",
"symfony/form": "^6.1 || ^7.0",
"symfony/framework-bundle": "^6.1 || ^7.0",
"symfony/http-client": "^6.1 || ^7.0",
"symfony/intl": "^6.1 || ^7.0",
"symfony/maker-bundle": "^1.24",
"symfony/mercure-bundle": "*",
"symfony/messenger": "^6.1",
"symfony/phpunit-bridge": "^6.1",
"symfony/routing": "^6.1",
"symfony/security-bundle": "^6.1",
"symfony/security-core": "^6.1",
"symfony/twig-bundle": "^6.1",
"symfony/uid": "^6.1",
"symfony/validator": "^6.1",
"symfony/web-profiler-bundle": "^6.1",
"symfony/yaml": "^6.1",
"symfony/messenger": "^6.1 || ^7.0",
"symfony/phpunit-bridge": "^6.1 || ^7.0",
"symfony/routing": "^6.1 || ^7.0",
"symfony/security-bundle": "^6.1 || ^7.0",
"symfony/security-core": "^6.1 || ^7.0",
"symfony/stopwatch": "^6.1 || ^7.0",
"symfony/twig-bundle": "^6.1 || ^7.0",
"symfony/uid": "^6.1 || ^7.0",
"symfony/validator": "^6.1 || ^7.0",
"symfony/web-profiler-bundle": "^6.1 || ^7.0",
"symfony/yaml": "^6.1 || ^7.0",
"twig/twig": "^1.42.3 || ^2.12 || ^3.0",
"webonyx/graphql-php": "^14.0 || ^15.0"
},
Expand Down Expand Up @@ -135,15 +135,16 @@
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"phpstan/extension-installer": true
"phpstan/extension-installer": true,
"php-http/discovery": true
}
},
"extra": {
"branch-alias": {
"dev-main": "3.3.x-dev"
},
"symfony": {
"require": "^6.1"
"require": "^6.1 || ^7.0"
}
}
}
12 changes: 11 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ parameters:
- src/Symfony/Bundle/DependencyInjection/Configuration.php
# Templates for Maker
- src/Symfony/Maker/Resources/skeleton
# subtree split
- **vendor**
# Symfony 6 support
- src/OpenApi/Serializer/CacheableSupportsMethodInterface.php
- src/Serializer/CacheableSupportsMethodInterface.php
- tests/Hal/Serializer/ItemNormalizerTest.php
- tests/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactoryTest.php
earlyTerminatingMethodCalls:
PHPUnit\Framework\Constraint\Constraint:
- fail
Expand Down Expand Up @@ -70,7 +77,6 @@ parameters:
# Expected, due to optional interfaces
- '#Method Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface::denormalize\(\) invoked with (2|3|4) parameters, 1 required\.#'
- '#Method Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface::normalize\(\) invoked with (2|3|4) parameters, 1 required\.#'
- '#Method Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface::supportsNormalization\(\) invoked with 3 parameters, 1-2 required\.#'

# Expected, due to backward compatibility
-
Expand All @@ -85,3 +91,7 @@ parameters:
-
message: '#^Property .+ is unused.$#'
path: tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineDummy.php

# Backward compatibility
- '#Call to method hasCacheableSupportsMethod\(\) on an unknown class Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface\.#'
- '#Class Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface not found\.#'
2 changes: 1 addition & 1 deletion src/Elasticsearch/Serializer/DocumentNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(
*/
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
{
return self::FORMAT === $format && $this->decoratedNormalizer->supportsDenormalization($data, $type, $format, $context); // @phpstan-ignore-line symfony bc-layer
return self::FORMAT === $format && $this->decoratedNormalizer->supportsDenormalization($data, $type, $format, $context);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Elasticsearch/Serializer/ItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function supportsDenormalization(mixed $data, string $type, string $forma
throw new LogicException(sprintf('The decorated normalizer must be an instance of "%s".', DenormalizerInterface::class));
}

return DocumentNormalizer::FORMAT !== $format && $this->decorated->supportsDenormalization($data, $type, $format, $context); // @phpstan-ignore-line symfony bc-layer
return DocumentNormalizer::FORMAT !== $format && $this->decorated->supportsDenormalization($data, $type, $format, $context);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Symfony\Component\PropertyInfo\Extractor\SerializerExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;

/**
* @author Oskar Stark <oskarstark@googlemail.com>
Expand Down Expand Up @@ -81,7 +81,7 @@ public function testCreateMethodReturnsProperPropertyNameCollectionForObjectWith
new PropertyInfoExtractor([
new SerializerExtractor(
new ClassMetadataFactory(
new AnnotationLoader(
new AttributeLoader(
)
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(private readonly Psr6CacheClearer $poolClearer, priv
*
* @return string[]
*/
public function warmUp(string $cacheDir): array
public function warmUp(string $cacheDir, string $buildDir = null): array
{
foreach ($this->pools as $pool) {
if ($this->poolClearer->hasPool($pool)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Test/DoctrineMongoDbOdmFilterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function setUp(): void
self::bootKernel();

$this->manager = DoctrineMongoDbOdmTestCase::createTestDocumentManager();
$this->managerRegistry = self::$kernel->getContainer()->get('doctrine_mongodb');
$this->managerRegistry = self::$kernel->getContainer()->get('doctrine_mongodb'); // @phpstan-ignore-line
$this->repository = $this->manager->getRepository($this->resourceClass);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Elasticsearch/Serializer/ItemNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ public function testGetSupportedTypes(): void

// TODO: use prophecy when getSupportedTypes() will be added to the interface
$this->itemNormalizer = new ItemNormalizer(new class() implements NormalizerInterface {
public function normalize(mixed $object, string $format = null, array $context = [])
public function normalize(mixed $object, string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
{
return null;
}

public function supportsNormalization(mixed $data, string $format = null): bool
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
{
return true;
}
Expand Down
11 changes: 4 additions & 7 deletions tests/Fixtures/DummySequentiallyValidatedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ class DummySequentiallyValidatedEntity
{
/**
* @var string
*
* @Assert\Sequentially({
*
* @Assert\Length(min=1, max=32),
*
* @Assert\Regex(pattern="/^[a-z]$/")
* })
*/
#[Assert\Sequentially([
new Assert\Length(min: 1, max: 32),
new Assert\Regex(pattern: '/^[a-z]$/'),
])]
public $dummy;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(private readonly NormalizerInterface $documentationN
*
* @throws ExceptionInterface
*/
public function normalize($object, $format = null, array $context = [])
public function normalize($object, $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
{
$data = $this->documentationNormalizer->normalize($object, $format, $context);
if (!\is_array($data)) {
Expand All @@ -50,8 +50,13 @@ public function normalize($object, $format = null, array $context = [])
/**
* @param mixed|null $format
*/
public function supportsNormalization($data, $format = null): bool
public function supportsNormalization($data, $format = null, array $context = []): bool
{
return $this->documentationNormalizer->supportsNormalization($data, $format);
return $this->documentationNormalizer->supportsNormalization($data, $format, $context);
}

public function getSupportedTypes(?string $format): array
{
return [];
}
}
9 changes: 6 additions & 3 deletions tests/Fixtures/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,15 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
],
];

$cookie = ['cookie_secure' => true, 'cookie_samesite' => 'lax', 'handler_id' => 'session.handler.native_file'];
// This class is introduced in Symfony 6.4 just using it to use the new configuration and to avoid unnecessary deprecations
if (class_exists(PingWebhookMessageHandler::class)) {
$config = [
'secret' => 'dunglas.fr',
'validation' => ['enable_attributes' => true, 'email_validation_mode' => 'html5'],
'serializer' => ['enable_attributes' => true],
'test' => null,
'session' => ['cookie_secure' => true, 'cookie_samesite' => 'lax', 'handler_id' => 'session.handler.native_file'],
'session' => class_exists(SessionFactory::class) ? ['storage_factory_id' => 'session.storage.factory.mock_file'] + $cookie : ['storage_id' => 'session.storage.mock_file'] + $cookie,
'profiler' => [
'enabled' => true,
'collect' => false,
Expand Down Expand Up @@ -277,8 +278,10 @@ protected function build(ContainerBuilder $container): void
$container->addCompilerPass(new class() implements CompilerPassInterface {
public function process(ContainerBuilder $container): void
{
// Deprecated command triggering a Symfony depreciation
$container->removeDefinition(TailCursorDoctrineODMCommand::class);
if ($container->hasDefinition(TailCursorDoctrineODMCommand::class)) { // @phpstan-ignore-line
// Deprecated command triggering a Symfony depreciation
$container->removeDefinition(TailCursorDoctrineODMCommand::class); // @phpstan-ignore-line
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/app/config/routing_common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ _main:

controller:
resource: '@TestBundle/Controller/Common'
type: annotation
type: attribute

relation_embedded.custom_get:
path: '/relation_embedders/{id}/custom'
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/app/config/routing_mongodb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ _main:

controller:
resource: '@TestBundle/Controller/MongoDbOdm'
type: annotation
type: attribute

web_profiler_wdt:
resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/app/config/routing_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ _main:

controller:
resource: '@TestBundle/Controller/Orm'
type: annotation
type: attribute

web_profiler_wdt:
resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
Expand Down
2 changes: 1 addition & 1 deletion tests/GraphQl/Resolver/Stage/SerializeStageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function testApplyBadNormalizedData(): void
$normalizationContext = ['normalization' => true];
$this->serializerContextBuilderProphecy->create($resourceClass, $operation, $context, true)->shouldBeCalled()->willReturn($normalizationContext);

$this->normalizerProphecy->normalize(Argument::type(\stdClass::class), ItemNormalizer::FORMAT, $normalizationContext)->willReturn(new \stdClass());
$this->normalizerProphecy->normalize(Argument::type(\stdClass::class), ItemNormalizer::FORMAT, $normalizationContext)->willReturn(0);

$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Expected serialized data to be a nullable array.');
Expand Down
3 changes: 2 additions & 1 deletion tests/Hal/Serializer/ItemNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Symfony\Component\Serializer\Exception\LogicException;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
Expand Down Expand Up @@ -289,7 +290,7 @@ public function testMaxDepth(): void
$resourceClassResolverProphecy->reveal(),
null,
null,
new ClassMetadataFactory(new AnnotationLoader())
new ClassMetadataFactory(class_exists(AttributeLoader::class) ? new AttributeLoader() : new AnnotationLoader())
);
$serializer = new Serializer([$normalizer]);
$normalizer->setSerializer($serializer);
Expand Down
Loading

0 comments on commit 49b412e

Please sign in to comment.