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\Drivers\MappingDriverInterface; |
16
|
|
|
use Addiks\RDMBundle\Mapping\Drivers\MappingYamlDriver; |
17
|
|
|
use Addiks\RDMBundle\Mapping\EntityMapping; |
18
|
|
|
use Addiks\RDMBundle\Mapping\ServiceMapping; |
19
|
|
|
use Addiks\RDMBundle\Mapping\ChoiceMapping; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
21
|
|
|
use Doctrine\Persistence\Mapping\Driver\FileLocator; |
22
|
|
|
|
23
|
|
|
final class MappingYamlDriverTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var MappingYamlDriver |
28
|
|
|
*/ |
29
|
|
|
private $mappingDriver; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var MappingDriverInterface |
33
|
|
|
*/ |
34
|
|
|
private $fileLocator; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var ContainerInterface |
38
|
|
|
*/ |
39
|
|
|
private $container; |
40
|
|
|
|
41
|
|
|
public function setUp(): void |
42
|
|
|
{ |
43
|
|
|
$this->fileLocator = $this->createMock(FileLocator::class); |
|
|
|
|
44
|
|
|
$this->container = $this->createMock(ContainerInterface::class); |
|
|
|
|
45
|
|
|
|
46
|
|
|
$this->mappingDriver = new MappingYamlDriver( |
47
|
|
|
$this->container, |
48
|
|
|
$this->fileLocator |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @test |
54
|
|
|
*/ |
55
|
|
|
public function shouldReadMappingData() |
56
|
|
|
{ |
57
|
|
|
/** @var string $mappingFilePath */ |
58
|
|
|
$mappingFilePath = __DIR__ . "/EntityExample.orm.yml"; |
59
|
|
|
|
60
|
|
|
$expectedMapping = new EntityMapping(EntityExample::class, [ |
61
|
|
|
'foo' => new ServiceMapping($this->container, 'some_service', false, "in file '{$mappingFilePath}'"), |
62
|
|
|
'bar' => new ServiceMapping($this->container, 'other_service', false, "in file '{$mappingFilePath}'"), |
63
|
|
|
'baz' => new ChoiceMapping('baz_column', [ |
64
|
|
|
'lorem' => new ServiceMapping($this->container, "lorem_service", false, "in file '{$mappingFilePath}'"), |
65
|
|
|
'ipsum' => new ServiceMapping($this->container, "ipsum_service", true, "in file '{$mappingFilePath}'"), |
66
|
|
|
], "in file '{$mappingFilePath}'"), |
67
|
|
|
]); |
68
|
|
|
|
69
|
|
|
$this->fileLocator->method('fileExists')->willReturn(true); |
|
|
|
|
70
|
|
|
$this->fileLocator->method('findMappingFile')->willReturn($mappingFilePath); |
71
|
|
|
|
72
|
|
|
/** @var EntityMapping $actualMapping */ |
73
|
|
|
$actualMapping = $this->mappingDriver->loadRDMMetadataForClass(EntityExample::class); |
74
|
|
|
|
75
|
|
|
$this->assertEquals($expectedMapping, $actualMapping); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @test |
80
|
|
|
*/ |
81
|
|
|
public function shouldNotReadOtherEntitiesMappingData() |
82
|
|
|
{ |
83
|
|
|
/** @var string $mappingFilePath */ |
84
|
|
|
$mappingFilePath = __DIR__ . "/EntityExample.orm.yml"; |
85
|
|
|
|
86
|
|
|
$this->fileLocator->method('fileExists')->willReturn(true); |
87
|
|
|
$this->fileLocator->method('findMappingFile')->willReturn($mappingFilePath); |
88
|
|
|
|
89
|
|
|
/** @var EntityMapping $actualMapping */ |
90
|
|
|
$actualMapping = $this->mappingDriver->loadRDMMetadataForClass( |
91
|
|
|
get_class($this->createMock(EntityExample::class)) |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$this->assertNull($actualMapping); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
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..