|
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\Hydration; |
|
12
|
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use Addiks\RDMBundle\Hydration\EntityHydrator; |
|
15
|
|
|
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverInterface; |
|
16
|
|
|
use Addiks\RDMBundle\Mapping\Annotation\Service; |
|
17
|
|
|
use Addiks\RDMBundle\Tests\Hydration\ServiceExample; |
|
18
|
|
|
use Addiks\RDMBundle\Tests\Hydration\EntityExample; |
|
19
|
|
|
use ErrorException; |
|
20
|
|
|
use Addiks\RDMBundle\Mapping\ServiceMapping; |
|
21
|
|
|
use Addiks\RDMBundle\Mapping\EntityMapping; |
|
22
|
|
|
use Addiks\RDMBundle\ValueResolver\ValueResolverInterface; |
|
|
|
|
|
|
23
|
|
|
use Addiks\RDMBundle\Exception\FailedRDMAssertionExceptionInterface; |
|
24
|
|
|
use Addiks\RDMBundle\DataLoader\DataLoaderInterface; |
|
25
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
26
|
|
|
use Addiks\RDMBundle\Mapping\EntityMappingInterface; |
|
27
|
|
|
use Addiks\RDMBundle\Mapping\MappingInterface; |
|
28
|
|
|
use Addiks\RDMBundle\Hydration\HydrationContextInterface; |
|
29
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
30
|
|
|
|
|
31
|
|
|
final class EntityHydratorTest extends TestCase |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var EntityHydrator |
|
36
|
|
|
*/ |
|
37
|
|
|
private $hydrator; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var MappingDriverInterface |
|
41
|
|
|
*/ |
|
42
|
|
|
private $mappingDriver; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var DataLoaderInterface |
|
46
|
|
|
*/ |
|
47
|
|
|
private $dbalDataLoader; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var ContainerInterface |
|
51
|
|
|
*/ |
|
52
|
|
|
private $container; |
|
53
|
|
|
|
|
54
|
|
|
public function setUp(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$this->mappingDriver = $this->createMock(MappingDriverInterface::class); |
|
|
|
|
|
|
57
|
|
|
$this->dbalDataLoader = $this->createMock(DataLoaderInterface::class); |
|
|
|
|
|
|
58
|
|
|
$this->container = $this->createMock(ContainerInterface::class); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$this->hydrator = new EntityHydrator( |
|
61
|
|
|
$this->mappingDriver, |
|
62
|
|
|
$this->dbalDataLoader |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @test |
|
68
|
|
|
*/ |
|
69
|
|
|
public function shouldHydrateAnEntityWithServices() |
|
70
|
|
|
{ |
|
71
|
|
|
$fooMapping = $this->createMock(MappingInterface::class); |
|
72
|
|
|
$barMapping = $this->createMock(MappingInterface::class); |
|
73
|
|
|
$fazMapping = $this->createMock(MappingInterface::class); |
|
74
|
|
|
|
|
75
|
|
|
$this->mappingDriver->method("loadRDMMetadataForClass")->willReturn( |
|
|
|
|
|
|
76
|
|
|
new EntityMapping(EntityExample::class, [ |
|
77
|
|
|
'foo' => $fooMapping, |
|
78
|
|
|
'bar' => $barMapping, |
|
79
|
|
|
'faz' => $fazMapping |
|
80
|
|
|
]) |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
$serviceA = new ServiceExample("SomeService", 123); |
|
84
|
|
|
$serviceB = new ServiceExample("AnotherService", 456); |
|
85
|
|
|
$serviceC = new ServiceExample("PrivateService", 789); |
|
86
|
|
|
|
|
87
|
|
|
$entity = new EntityExample(); |
|
88
|
|
|
|
|
89
|
|
|
$fooMapping->method("resolveValue")->willReturn($serviceA); |
|
90
|
|
|
$barMapping->method("resolveValue")->willReturn($serviceB); |
|
91
|
|
|
$fazMapping->method("resolveValue")->willReturn($serviceC); |
|
92
|
|
|
|
|
93
|
|
|
$this->hydrator->hydrateEntity($entity, $this->createMock(EntityManagerInterface::class)); |
|
94
|
|
|
|
|
95
|
|
|
$this->assertEquals($serviceA, $entity->foo); |
|
96
|
|
|
$this->assertEquals($serviceB, $entity->bar); |
|
97
|
|
|
$this->assertEquals($serviceC, $entity->getFaz()); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @test |
|
102
|
|
|
*/ |
|
103
|
|
|
public function shouldAssertHydration() |
|
104
|
|
|
{ |
|
105
|
|
|
$fazMapping = $this->createMock(MappingInterface::class); |
|
106
|
|
|
|
|
107
|
|
|
/** @var ServiceExample $fooService */ |
|
108
|
|
|
$fazService = $this->createMock(ServiceExample::class); |
|
109
|
|
|
|
|
110
|
|
|
$entity = new EntityExample(null, null, null, $fazService); |
|
111
|
|
|
|
|
112
|
|
|
$this->mappingDriver->method("loadRDMMetadataForClass")->willReturn( |
|
113
|
|
|
new EntityMapping(EntityExample::class, [ |
|
114
|
|
|
'faz' => $fazMapping, |
|
115
|
|
|
]) |
|
116
|
|
|
); |
|
117
|
|
|
|
|
118
|
|
|
$fazMapping->expects($this->once())->method("assertValue")->with( |
|
119
|
|
|
$this->isInstanceOf(HydrationContextInterface::class), |
|
120
|
|
|
$this->equalTo([]), |
|
121
|
|
|
$this->equalTo($fazService) |
|
122
|
|
|
); |
|
123
|
|
|
|
|
124
|
|
|
$this->hydrator->assertHydrationOnEntity($entity, $this->createMock(EntityManagerInterface::class)); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths