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