|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2017 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 Doctrine\ORM\EntityManagerInterface; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
16
|
|
|
use Addiks\RDMBundle\Hydration\EntityHydratorLazyLoadProxy; |
|
17
|
|
|
use Addiks\RDMBundle\Tests\Hydration\EntityExample; |
|
18
|
|
|
use Addiks\RDMBundle\Hydration\EntityHydratorInterface; |
|
19
|
|
|
|
|
20
|
|
|
final class EntityHydratorLazyLoadProxyTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var EntityHydratorLazyLoadProxy |
|
25
|
|
|
*/ |
|
26
|
|
|
private $hydratorProxy; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var ContainerInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $container; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var EntityHydratorInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private $innerHydrator; |
|
37
|
|
|
|
|
38
|
|
|
public function setUp(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this->innerHydrator = $this->createMock(EntityHydratorInterface::class); |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
$this->container = $this->createMock(ContainerInterface::class); |
|
|
|
|
|
|
43
|
|
|
$this->container->method("get")->will($this->returnValueMap([ |
|
44
|
|
|
["some_service_id", ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->innerHydrator] |
|
45
|
|
|
])); |
|
46
|
|
|
|
|
47
|
|
|
$this->hydratorProxy = new EntityHydratorLazyLoadProxy($this->container, "some_service_id"); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @test |
|
52
|
|
|
*/ |
|
53
|
|
|
public function shouldForwardEntityHydration() |
|
54
|
|
|
{ |
|
55
|
|
|
/** @var EntityExample $entity */ |
|
56
|
|
|
$entity = $this->createMock(EntityExample::class); |
|
57
|
|
|
|
|
58
|
|
|
/** @var EntityManagerInterface $entityManager */ |
|
59
|
|
|
$entityManager = $this->createMock(EntityManagerInterface::class); |
|
60
|
|
|
|
|
61
|
|
|
$this->innerHydrator->expects($this->once())->method("hydrateEntity")->with( |
|
|
|
|
|
|
62
|
|
|
$this->equalTo($entity), |
|
63
|
|
|
$this->equalTo($entityManager) |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
$this->hydratorProxy->hydrateEntity($entity, $entityManager); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @test |
|
71
|
|
|
*/ |
|
72
|
|
|
public function shouldForwardEntityHydrationAssertion() |
|
73
|
|
|
{ |
|
74
|
|
|
/** @var EntityExample $entity */ |
|
75
|
|
|
$entity = $this->createMock(EntityExample::class); |
|
76
|
|
|
|
|
77
|
|
|
/** @var EntityManagerInterface $entityManager */ |
|
78
|
|
|
$entityManager = $this->createMock(EntityManagerInterface::class); |
|
79
|
|
|
|
|
80
|
|
|
$this->innerHydrator->expects($this->once())->method("assertHydrationOnEntity")->with( |
|
81
|
|
|
$this->equalTo($entity), |
|
82
|
|
|
$this->equalTo($entityManager) |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
$this->hydratorProxy->assertHydrationOnEntity($entity, $entityManager); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
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..