Passed
Push — feature/initial-implementation ( 77fab8...e556a2 )
by Fike
01:48
created

NormalizerTest::normalizationDataProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
c 0
b 0
f 0
rs 8.8571
cc 1
eloc 22
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\Test\Suite\Functional\Mapping;
6
7
use AmaTeam\ElasticSearch\Mapping\Mapping;
8
use AmaTeam\ElasticSearch\Mapping\Normalizer;
9
use AmaTeam\ElasticSearch\Mapping\TypeEnum;
10
use Codeception\Test\Unit;
11
use DateTime;
12
use PHPUnit\Framework\Assert;
13
14
class NormalizerTest extends Unit
15
{
16
    public function normalizationDataProvider(): array
17
    {
18
        $variants = [];
19
        $variants[] = [
20
            (new Mapping())
21
                ->setType(TypeEnum::BOOLEAN)
22
                ->setFormat(DateTime::ISO8601),
23
            ['type' => 'boolean']
24
        ];
25
        $variants[] = [
26
            (new Mapping())
27
                ->setType(TypeEnum::BOOLEAN)
28
                ->setFormat(DateTime::ISO8601)
29
                ->setDocValues(true)
30
                ->setStore(true),
31
            ['type' => 'boolean', 'store' => true, 'doc_values' => true]
32
        ];
33
        $variants[] = [
34
            (new Mapping())
35
                ->setType(TypeEnum::OBJECT)
36
                ->setProperties(['value' => (new Mapping())->setType(TypeEnum::BOOLEAN)]),
37
            [
38
                'type' => 'object',
39
                'properties' => [
40
                    'value' => [
41
                        'type' => 'boolean'
42
                    ]
43
                ]
44
            ]
45
        ];
46
        return $variants;
47
    }
48
49
    /**
50
     * @param Mapping $mapping
51
     * @param array $expectation
52
     *
53
     * @test
54
     * @dataProvider normalizationDataProvider
55
     */
56
    public function shouldNormalizeToExpectedStructure(Mapping $mapping, array $expectation): void
57
    {
58
        $normalizer = new Normalizer();
59
        $normalized = $normalizer->normalize($mapping);
60
        ksort($expectation);
61
        ksort($normalized);
62
        Assert::assertEquals($expectation, $normalized);
63
    }
64
}
65