|
21 | 21 | use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
|
22 | 22 | use ApiPlatform\Symfony\Bundle\Test\Constraint\ArraySubset;
|
23 | 23 | use ApiPlatform\Symfony\Bundle\Test\Constraint\MatchesJsonSchema;
|
| 24 | +use PHPUnit\Framework\Constraint\JsonMatches; |
24 | 25 | use PHPUnit\Framework\ExpectationFailedException;
|
25 | 26 | use Symfony\Bundle\FrameworkBundle\Test\BrowserKitAssertionsTrait;
|
26 | 27 | use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
@@ -71,14 +72,18 @@ public static function assertJsonContains(array|string $subset, bool $checkForOb
|
71 | 72 | */
|
72 | 73 | public static function assertJsonEquals(array|string $json, string $message = ''): void
|
73 | 74 | {
|
74 |
| - if (\is_string($json)) { |
75 |
| - $json = json_decode($json, true, 512, \JSON_THROW_ON_ERROR); |
76 |
| - } |
77 |
| - if (!\is_array($json)) { |
78 |
| - throw new \InvalidArgumentException('$json must be array or string (JSON array or JSON object)'); |
| 75 | + if (\is_array($json)) { |
| 76 | + $json = json_encode( |
| 77 | + $json, |
| 78 | + \JSON_UNESCAPED_UNICODE |
| 79 | + | \JSON_UNESCAPED_SLASHES |
| 80 | + | \JSON_PRESERVE_ZERO_FRACTION |
| 81 | + | \JSON_THROW_ON_ERROR); |
79 | 82 | }
|
80 | 83 |
|
81 |
| - static::assertEqualsCanonicalizing($json, self::getHttpResponse()->toArray(false), $message); |
| 84 | + $constraint = new JsonMatches($json); |
| 85 | + |
| 86 | + static::assertThat(self::getHttpResponse()->getContent(false), $constraint, $message); |
82 | 87 | }
|
83 | 88 |
|
84 | 89 | /**
|
|
0 commit comments