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'); |
|
|
|
|
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
|
|
|
|
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.