• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 10315659289

09 Aug 2024 07:49AM UTC coverage: 7.841% (-0.006%) from 7.847%
10315659289

push

github

soyuka
style: cs fixes

70 of 529 new or added lines in 176 files covered. (13.23%)

160 existing lines in 58 files now uncovered.

12688 of 161818 relevant lines covered (7.84%)

26.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Elasticsearch/Tests/Serializer/DocumentNormalizerTest.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Elasticsearch\Tests\Serializer;
15

16
use ApiPlatform\Elasticsearch\Serializer\DocumentNormalizer;
17
use ApiPlatform\Elasticsearch\Tests\Fixtures\Foo;
18
use ApiPlatform\Metadata\ApiResource;
19
use ApiPlatform\Metadata\Get;
20
use ApiPlatform\Metadata\Operations;
21
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
22
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
23
use PHPUnit\Framework\TestCase;
24
use Prophecy\PhpUnit\ProphecyTrait;
25
use Symfony\Component\Serializer\Exception\LogicException;
26
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
27
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
28

29
final class DocumentNormalizerTest extends TestCase
30
{
31
    use ProphecyTrait;
32

33
    public function testConstruct(): void
34
    {
35
        $itemNormalizer = new DocumentNormalizer($this->prophesize(ResourceMetadataCollectionFactoryInterface::class)->reveal());
×
36

37
        self::assertInstanceOf(DenormalizerInterface::class, $itemNormalizer);
×
38
        self::assertInstanceOf(NormalizerInterface::class, $itemNormalizer);
×
39
    }
40

41
    public function testSupportsDenormalization(): void
42
    {
43
        $document = [
×
44
            '_index' => 'test',
×
45
            '_type' => '_doc',
×
46
            '_id' => '1',
×
47
            '_version' => 1,
×
48
            'found' => true,
×
49
            '_source' => [
×
50
                'id' => 1,
×
51
                'name' => 'Caroline',
×
52
                'bar' => 'Chaverot',
×
53
            ],
×
54
        ];
×
55

56
        $itemNormalizer = new DocumentNormalizer($this->prophesize(ResourceMetadataCollectionFactoryInterface::class)->reveal());
×
57

58
        self::assertTrue($itemNormalizer->supportsDenormalization($document, Foo::class, DocumentNormalizer::FORMAT));
×
59
        self::assertFalse($itemNormalizer->supportsDenormalization($document, Foo::class, 'text/coffee'));
×
60
    }
61

62
    public function testDenormalize(): void
63
    {
64
        $document = [
×
65
            '_index' => 'test',
×
66
            '_type' => '_doc',
×
67
            '_id' => '1',
×
68
            '_version' => 1,
×
69
            'found' => true,
×
70
            '_source' => [
×
71
                'name' => 'Caroline',
×
72
                'bar' => 'Chaverot',
×
73
            ],
×
74
        ];
×
75

76
        $resourceMetadataFactory = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class);
×
77
        $resourceMetadataFactory->create(Foo::class)->willReturn(new ResourceMetadataCollection(Foo::class, [(new ApiResource())->withOperations(new Operations([new Get()]))]));
×
78

79
        $normalizer = new DocumentNormalizer($resourceMetadataFactory->reveal());
×
80

81
        $expectedFoo = new Foo();
×
82
        $expectedFoo->setName('Caroline');
×
83
        $expectedFoo->setBar('Chaverot');
×
84

85
        self::assertEquals($expectedFoo, $normalizer->denormalize($document, Foo::class, DocumentNormalizer::FORMAT));
×
86
    }
87

88
    public function testSupportsNormalization(): void
89
    {
90
        $itemNormalizer = new DocumentNormalizer($this->prophesize(ResourceMetadataCollectionFactoryInterface::class)->reveal());
×
91

92
        self::assertTrue($itemNormalizer->supportsNormalization(new Foo(), DocumentNormalizer::FORMAT));
×
93
    }
94

95
    public function testNormalize(): void
96
    {
97
        $this->expectException(LogicException::class);
×
NEW
98
        $this->expectExceptionMessage(\sprintf('%s is a write-only format.', DocumentNormalizer::FORMAT));
×
99

100
        (new DocumentNormalizer($this->prophesize(ResourceMetadataCollectionFactoryInterface::class)->reveal()))->normalize(new Foo(), DocumentNormalizer::FORMAT);
×
101
    }
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc