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

ReaderTest::setUpBeforeClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\Test\Suite\Functional\Mapping\Annotation\Property;
6
7
use AmaTeam\ElasticSearch\Mapping\PropertyMapping;
8
use AmaTeam\ElasticSearch\Mapping\Annotation\Property\Reader;
9
use AmaTeam\ElasticSearch\Mapping\PropertyMappingView;
10
use AmaTeam\ElasticSearch\Test\Support\ElasticSearch\Dummy\PlainStructure;
11
use AmaTeam\ElasticSearch\Utility\Classes;
12
use Codeception\Test\Unit;
13
use Doctrine\Common\Annotations\AnnotationRegistry;
14
use PHPUnit\Framework\Assert;
15
use ReflectionProperty;
16
17
class ReaderTest extends Unit
18
{
19
    public static function setUpBeforeClass()
20
    {
21
        parent::setUpBeforeClass();
22
        AnnotationRegistry::registerLoader('class_exists');
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\Common\Annotati...istry::registerLoader() has been deprecated: this method is deprecated and will be removed in doctrine/annotations 2.0 autoloading should be deferred to the globally registered autoloader by then. For now, use @example AnnotationRegistry::registerLoader('class_exists') ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

22
        /** @scrutinizer ignore-deprecated */ AnnotationRegistry::registerLoader('class_exists');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
23
    }
24
25
    public function dataProvider()
26
    {
27
        $variants = [];
28
29
        $parent = Classes::normalizeAbsoluteName(PlainStructure::class);
30
        $descriptor = (new PropertyMapping($parent, 'children'))
31
            ->setForcedViewName('short');
32
        $descriptor
33
            ->setDefaultView(
34
                (new PropertyMappingView())
35
                    ->setType('object')
36
            );
37
        $descriptor
38
            ->requestView('full')
39
            ->setTargetClass($parent);
40
        $variants[] = [
41
            $parent,
42
            'children',
43
            $descriptor
44
        ];
45
46
        $descriptor = new PropertyMapping($parent, 'id');
47
        $descriptor
48
            ->requestView('short')
49
            ->setType('integer');
50
        $descriptor
51
            ->requestView('full')
52
            ->setType('string');
53
        $variants[] = [
54
            $parent,
55
            'id',
56
            $descriptor
57
        ];
58
        return $variants;
59
    }
60
61
    /**
62
     * @param string $className
63
     * @param string $property
64
     * @param PropertyMapping $expectation
65
     *
66
     * @test
67
     * @dataProvider dataProvider
68
     */
69
    public function shouldReadExpectedValues(string $className, string $property, PropertyMapping $expectation)
70
    {
71
        $reader = new Reader();
72
        $property = new ReflectionProperty($className, $property);
73
        $result = $reader->read($property);
74
        Assert::assertEquals($expectation, $result);
75
    }
76
}
77