Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ConstraintViolationListNormalizer, Fix tests #51

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading