Passed
Push — feature/initial-implementation ( 0c2c6c...79751f )
by Fike
01:54
created

RendererTest::renderDataProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 32
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\API\Mapping\DocumentMappingInterface;
8
use AmaTeam\ElasticSearch\API\Mapping\MappingInterface;
9
use AmaTeam\ElasticSearch\Mapping\DocumentMapping;
10
use AmaTeam\ElasticSearch\Mapping\DocumentMappingView;
11
use AmaTeam\ElasticSearch\Mapping\Mapping;
12
use AmaTeam\ElasticSearch\Mapping\PropertyMapping;
13
use AmaTeam\ElasticSearch\Mapping\PropertyMappingView;
14
use AmaTeam\ElasticSearch\Mapping\Renderer;
15
use Codeception\Test\Unit;
16
use PHPUnit\Framework\Assert;
17
18
class RendererTest extends Unit
19
{
20
    public function renderDataProvider()
21
    {
22
        $variants = [];
23
        $source = (new DocumentMapping())->setForcedViewName('dwindled');
24
        $source
25
            ->setDefaultView(
26
                (new DocumentMappingView())
27
                    ->setParameter('dynamic', true)
28
            );
29
        $source
30
            ->requestView('dwindled')
31
            ->setParameter('enabled', true);
32
        $property = (new PropertyMapping())->setForcedViewName('full');
33
        $property
34
            ->setDefaultView(
35
                (new PropertyMappingView())
36
                    ->setType('integer')
37
                    ->setParameter('coerce', true)
38
            );
39
        $property
40
            ->requestView('dwindled')
41
            ->setParameter('copyTo', 'target');
42
        $source->setProperties(['id' => $property]);
43
        $resultingProperty = (new Mapping())
44
            ->setType('integer')
45
            ->setParameter('coerce', true)
46
            ->setParameter('copyTo', 'target');
47
        $result = (new Mapping())
48
            ->setParameter('enabled', true)
49
            ->setParameter('dynamic', true)
50
            ->setProperties(['id' => $resultingProperty]);
51
        $variants[] = [
52
            $source,
53
            ['short'],
54
            $result
55
        ];
56
        return $variants;
57
    }
58
59
    /**
60
     * @param DocumentMappingInterface $source
61
     * @param array $views
62
     * @param MappingInterface $expectation
63
     *
64
     * @test
65
     * @dataProvider renderDataProvider
66
     */
67
    public function shouldRenderAsExpected(
68
        DocumentMappingInterface $source,
69
        array $views,
70
        MappingInterface $expectation
71
    ) {
72
        $renderer = new Renderer();
73
        $result = $renderer->render($source, ...$views);
74
        Assert::assertEquals($expectation, $result);
75
    }
76
}
77