forked from api-platform/core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jsonld): prefix error @type with hydra:
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace ApiPlatform\Tests\JsonLd\Serializer; | ||
|
||
use ApiPlatform\JsonLd\ContextBuilder; | ||
use ApiPlatform\JsonLd\Serializer\ErrorNormalizer; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
final class ErrorNormalizerTest extends TestCase | ||
{ | ||
public function testAddHydraPrefix() | ||
{ | ||
$provider = $this->createMock(NormalizerInterface::class); | ||
$provider->method('normalize')->willReturn(['@type' => 'Error', 'title' => 'foo', 'description' => 'bar']); | ||
$errorNormalizer = new ErrorNormalizer($provider, ['hydra_prefix' => ContextBuilder::HYDRA_CONTEXT_HAS_PREFIX]); | ||
$res = $errorNormalizer->normalize(new \stdClass()); | ||
$this->assertEquals('hydra:Error', $res['@type']); | ||
$this->assertArrayHasKey('hydra:description', $res); | ||
$this->assertEquals($res['hydra:description'], $res['description']); | ||
$this->assertArrayHasKey('hydra:title', $res); | ||
$this->assertEquals($res['hydra:title'], $res['title']); | ||
} | ||
} |