Skip to content

Commit

Permalink
Fix ConstraintViolationListNormalizer: Use NormalizerInterface instea…
Browse files Browse the repository at this point in the history
…d of ConstraintViolationListNormalizer final class; Fix tests
  • Loading branch information
rela589n committed Feb 20, 2024
1 parent cd6de21 commit e1452a6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
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
6 changes: 2 additions & 4 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,9 +21,9 @@
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)
{
}

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

0 comments on commit e1452a6

Please sign in to comment.