Skip to content

Commit

Permalink
Upgrade to Symfony 7 (#50)
Browse files Browse the repository at this point in the history
* Update ci.yaml

* Update composer.json

* Update composer.json

* Update ConstraintViolationListNormalizer.php

* Update DictionaryEnumNormalizer.php

* Update JsonSchemaErrorNormalizer.php

* Update JsonSchemaErrorNormalizer.php

* Update DictionaryEnumNormalizer.php

* Update ConstraintViolationListNormalizer.php

* Update DictionaryEnumNormalizer.php

* Fix ConstraintViolationListNormalizer: Use NormalizerInterface instead of ConstraintViolationListNormalizer final class; Fix tests (#51)

---------

Co-authored-by: Yevhen Sidelnyk <[email protected]>
  • Loading branch information
fre5h and rela589n authored Feb 20, 2024
1 parent 7c4b46b commit b498fae
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 59 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: CI

on:
pull_request:
workflow_dispatch: ~
push:
branches:
- 'main'
Expand All @@ -12,7 +13,7 @@ jobs:
name: "Composer Validate"
steps:
- name: 'Checkout Code'
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: 'Validate composer.json'
run: composer validate --no-check-all --strict --no-check-lock
Expand All @@ -23,7 +24,7 @@ jobs:
name: "Composer Install"
steps:
- name: 'Checkout Code'
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
Expand All @@ -44,7 +45,7 @@ jobs:
fail-fast: false
steps:
- name: 'Checkout Code'
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
Expand All @@ -69,7 +70,7 @@ jobs:
fail-fast: false
steps:
- name: 'Checkout Code'
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
Expand All @@ -96,10 +97,10 @@ jobs:
php-version:
- '8.2'
symfony-version:
- '6.2'
- '7.0'
steps:
- name: 'Checkout Code'
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
Expand All @@ -124,7 +125,7 @@ jobs:
fail-fast: false
steps:
- name: 'Checkout Code'
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/vendor/
.phpunit.result.cache
composer.lock
18 changes: 13 additions & 5 deletions Serializer/Normalizer/ConstraintViolationListNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

namespace StfalconStudio\ApiBundle\Serializer\Normalizer;

use Symfony\Component\Serializer\Debug\TraceableNormalizer;
use Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer as SymfonyConstraintViolationListNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Validator\ConstraintViolationListInterface;

Expand All @@ -23,20 +21,30 @@
class ConstraintViolationListNormalizer implements NormalizerInterface
{
/**
* @param SymfonyConstraintViolationListNormalizer|TraceableNormalizer $symfonyConstraintViolationListNormalizer
* @param NormalizerInterface $symfonyConstraintViolationListNormalizer
*/
public function __construct(private readonly SymfonyConstraintViolationListNormalizer|TraceableNormalizer $symfonyConstraintViolationListNormalizer)
public function __construct(private readonly NormalizerInterface $symfonyConstraintViolationListNormalizer)
{
}

/**
* {@inheritdoc}
*/
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof ConstraintViolationListInterface;
}

/**
* {@inheritdoc}
*/
public function getSupportedTypes(?string $format): array
{
return [
ConstraintViolationListInterface::class => true,
];
}

/**
* Clear the "detail" field from prefixed property paths.
*
Expand Down
17 changes: 12 additions & 5 deletions Serializer/Normalizer/DictionaryEnumNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,23 @@ class DictionaryEnumNormalizer implements NormalizerInterface
use TranslatorTrait;

/**
* @param mixed $data
* @param string|null $format
*
* @return bool
* {@inheritdoc}
*/
public function supportsNormalization(mixed $data, string $format = null): bool
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof DictionaryEnumInterface;
}

/**
* {@inheritdoc}
*/
public function getSupportedTypes(?string $format): array
{
return [
DictionaryEnumInterface::class => true,
];
}

/**
* @param DictionaryEnumInterface $object
* @param string|null $format
Expand Down
12 changes: 11 additions & 1 deletion Serializer/Normalizer/JsonSchemaErrorNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@ class JsonSchemaErrorNormalizer implements NormalizerInterface
/**
* {@inheritdoc}
*/
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof JsonSchemaValidator;
}

/**
* {@inheritdoc}
*/
public function getSupportedTypes(?string $format): array
{
return [
JsonSchemaValidator::class => true,
];
}

/**
* @param JsonSchemaValidator|object $object
* @param string|null $format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Doctrine\ODM\MongoDB\LockException;
use Doctrine\ORM\OptimisticLockException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Sentry\ClientInterface;
Expand Down Expand Up @@ -278,15 +279,15 @@ public function testOnKernelExceptionOnPaymentRequired(): void
self::assertInstanceOf(HttpException::class, $exceptionEvent->getThrowable());
}

public function resourceNotFoundExceptionMessageDataProvider(): array
public static function resourceNotFoundExceptionMessageDataProvider(): array
{
return [
['"App\\Entity\\Event\\Event\" object not found by \"Symfony\\Bridge\\Doctrine\\ArgumentResolver\\EntityValueResolver\". The expression \"repository.findClosedEventById(id)\" returned null.'],
['"App\\Entity\\Event\\Event" object not found by "Symfony\\Bridge\\Doctrine\\ArgumentResolver\\EntityValueResolver".'],
];
}

/** @dataProvider resourceNotFoundExceptionMessageDataProvider */
#[DataProvider('resourceNotFoundExceptionMessageDataProvider')]
public function testOnKernelExceptionWhenResourceNotFoundCausedByMapEntityAttribute(string $exceptionMessage): void
{
$httpException = new NotFoundHttpException($exceptionMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use StfalconStudio\ApiBundle\Serializer\Normalizer\ConstraintViolationListNormalizer;
use Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer as SymfonyConstraintViolationListNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface as SymfonyConstraintViolationListNormalizer;
use Symfony\Component\Validator\ConstraintViolationListInterface;

final class ConstraintViolationListNormalizerTest extends TestCase
Expand Down Expand Up @@ -61,20 +61,20 @@ public function testNormalize(string $originDetail, string $resultDetail): void
public static function dataProviderForTestNormalize(): iterable
{
yield [
'origin_detail' => 'field1: Error description.',
'result_detail' => 'Error description.',
'originDetail' => 'field1: Error description.',
'resultDetail' => 'Error description.',
];
yield [
'origin_detail' => "field1: Error description 1.\nfield2: Error description 2.",
'result_detail' => "Error description 1.\nError description 2.",
'originDetail' => "field1: Error description 1.\nfield2: Error description 2.",
'resultDetail' => "Error description 1.\nError description 2.",
];
yield [
'origin_detail' => 'Error description.',
'result_detail' => 'Error description.',
'originDetail' => 'Error description.',
'resultDetail' => 'Error description.',
];
yield [
'origin_detail' => "field1: Error :description 1.\nfield2: Error :description 2.",
'result_detail' => "Error :description 1.\nError :description 2.",
'originDetail' => "field1: Error :description 1.\nfield2: Error :description 2.",
'resultDetail' => "Error :description 1.\nError :description 2.",
];
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Validator/JsonSchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function testInvalidJsonSchemaException(): void
2 => [$dummyJsonSchema, 'object']
};
})
->will(self::onConsecutiveCalls($violations, $normalizedJsonSchema))
->willReturn($violations, $normalizedJsonSchema)
;

$this->expectException(InvalidJsonSchemaException::class);
Expand Down
58 changes: 29 additions & 29 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,46 @@
"ircmaxell/password-compat": "^v1.0.4",
"justinrainbow/json-schema": "^5.2.12",
"predis/predis": "^v1.1.10",
"sentry/sentry-symfony": "^4.8.0",
"symfony/config": "^6.1",
"symfony/dependency-injection": "^6.2",
"symfony/flex": "^2.2",
"symfony/http-kernel": "^6.2",
"symfony/http-foundation": "^6.2",
"symfony/framework-bundle": "^6.2",
"symfony/serializer": "^6.2",
"symfony/translation": "^6.2",
"symfony/validator": "^6.2"
"sentry/sentry-symfony": "^4.13.0",
"symfony/config": "^7.0",
"symfony/dependency-injection": "^7.0",
"symfony/flex": "^2.4",
"symfony/http-kernel": "^7.0",
"symfony/http-foundation": "^7.0",
"symfony/framework-bundle": "^7.0",
"symfony/serializer": "^7.0",
"symfony/translation": "^7.0",
"symfony/validator": "^7.0"
},
"require-dev": {
"doctrine/common": "^3.4",
"doctrine/mongodb-odm": "^2.5",
"doctrine/orm": "^2.15",
"doctrine/mongodb-odm": "^2.6",
"doctrine/orm": "^2.18",
"escapestudios/symfony2-coding-standard": "^3.13",
"gesdinet/jwt-refresh-token-bundle": "^v1.1.1",
"jetbrains/phpstorm-attributes": "^1.0",
"lexik/jwt-authentication-bundle": "^v2.19",
"phpstan/phpstan": "^1.10.15",
"lexik/jwt-authentication-bundle": "^v2.20",
"phpstan/phpstan": "^1.10.58",
"phpstan/phpstan-deprecation-rules": "^1.1.1",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-symfony": "^1.3",
"phpunit/phpunit": "^10.1",
"phpunit/phpunit": "^11.0",
"slam/phpstan-extensions": "^6.0",
"symfony/asset": "^6.2",
"symfony/console": "^6.2",
"symfony/dotenv": "^6.2",
"symfony/event-dispatcher": "^6.2",
"symfony/filesystem": "^6.2",
"symfony/form": "^6.2",
"symfony/http-client": "^6.2",
"symfony/messenger": "^6.2",
"symfony/routing": "^6.2",
"symfony/security-bundle": "^6.2",
"symfony/security-core": "^6.2",
"symfony/security-csrf": "^6.2",
"symfony/workflow": "^6.2",
"twig/twig": "^v3.6"
"symfony/asset": "^7.0",
"symfony/console": "^7.0",
"symfony/dotenv": "^7.0",
"symfony/event-dispatcher": "^7.0",
"symfony/filesystem": "^7.0",
"symfony/form": "^7.0",
"symfony/http-client": "^7.0",
"symfony/messenger": "^7.0",
"symfony/routing": "^7.0",
"symfony/security-bundle": "^7.0",
"symfony/security-core": "^7.0",
"symfony/security-csrf": "^7.0",
"symfony/workflow": "^7.0",
"twig/twig": "^v3.8"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit b498fae

Please sign in to comment.