1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2018 Gerrit Addiks. |
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
7
|
|
|
* @license GPL-3.0 |
8
|
|
|
* @author Gerrit Addiks <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Addiks\RDMBundle\Tests\Mapping\Drivers; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Addiks\RDMBundle\Tests\Hydration\EntityExample; |
15
|
|
|
use Addiks\RDMBundle\Mapping\Annotation\Service; |
16
|
|
|
use ReflectionProperty; |
17
|
|
|
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverChain; |
18
|
|
|
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverInterface; |
19
|
|
|
use Addiks\RDMBundle\Mapping\EntityMapping; |
20
|
|
|
use Addiks\RDMBundle\Mapping\ServiceMapping; |
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
22
|
|
|
|
23
|
|
|
final class MappingDriverChainTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var MappingDriverChain |
28
|
|
|
*/ |
29
|
|
|
private $mappingDriver; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var MappingDriverInterface |
33
|
|
|
*/ |
34
|
|
|
private $innerDriverA; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var MappingDriverInterface |
38
|
|
|
*/ |
39
|
|
|
private $innerDriverB; |
40
|
|
|
|
41
|
|
|
public function setUp(): void |
42
|
|
|
{ |
43
|
|
|
$this->innerDriverA = $this->createMock(MappingDriverInterface::class); |
|
|
|
|
44
|
|
|
$this->innerDriverB = $this->createMock(MappingDriverInterface::class); |
|
|
|
|
45
|
|
|
|
46
|
|
|
$this->mappingDriver = new MappingDriverChain([ |
47
|
|
|
$this->innerDriverA, |
48
|
|
|
$this->innerDriverB, |
49
|
|
|
]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @test |
54
|
|
|
*/ |
55
|
|
|
public function shouldCollectMappingData() |
56
|
|
|
{ |
57
|
|
|
$fieldMappingA = new ServiceMapping($this->createMock(ContainerInterface::class), "some_service"); |
58
|
|
|
$fieldMappingB = new ServiceMapping($this->createMock(ContainerInterface::class), "other_service"); |
59
|
|
|
|
60
|
|
|
/** @var array<Service> $expectedAnnotations */ |
61
|
|
|
$expectedFieldMappings = [ |
62
|
|
|
'foo' => $fieldMappingA, |
63
|
|
|
'bar' => $fieldMappingB |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
$this->innerDriverA->method('loadRDMMetadataForClass')->willReturn( |
|
|
|
|
67
|
|
|
new EntityMapping(EntityExample::class, [ |
68
|
|
|
'foo' => $fieldMappingA |
69
|
|
|
]) |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$this->innerDriverB->method('loadRDMMetadataForClass')->willReturn( |
73
|
|
|
new EntityMapping(EntityExample::class, [ |
74
|
|
|
'bar' => $fieldMappingB |
75
|
|
|
]) |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
/** @var EntityMapping $actualMapping */ |
79
|
|
|
$actualMapping = $this->mappingDriver->loadRDMMetadataForClass(EntityExample::class); |
80
|
|
|
|
81
|
|
|
$this->assertEquals($expectedFieldMappings, $actualMapping->getFieldMappings()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..