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\Mapping; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Addiks\RDMBundle\Mapping\MappingProxy; |
15
|
|
|
use Addiks\RDMBundle\Mapping\MappingInterface; |
16
|
|
|
use Doctrine\DBAL\Schema\Column; |
17
|
|
|
use Addiks\RDMBundle\Hydration\HydrationContextInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
19
|
|
|
|
20
|
|
|
final class MappingProxyTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var MappingProxy |
25
|
|
|
*/ |
26
|
|
|
private $proxy; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var MappingInterface |
30
|
|
|
*/ |
31
|
|
|
private $innerMapping; |
32
|
|
|
|
33
|
|
|
public function setUp() |
34
|
|
|
{ |
35
|
|
|
$this->innerMapping = $this->createMock(MappingInterface::class); |
|
|
|
|
36
|
|
|
|
37
|
|
|
$this->proxy = new MappingProxy($this->innerMapping, "prefix_"); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @test |
42
|
|
|
*/ |
43
|
|
|
public function shouldForwardOrigin() |
44
|
|
|
{ |
45
|
|
|
/** @var string $origin */ |
46
|
|
|
$origin = "some origin!"; |
47
|
|
|
|
48
|
|
|
$this->innerMapping->method("describeOrigin")->willReturn($origin); |
|
|
|
|
49
|
|
|
|
50
|
|
|
$this->assertEquals($origin, $this->proxy->describeOrigin()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @test |
55
|
|
|
*/ |
56
|
|
|
public function shouldForwardCollectedColumns() |
57
|
|
|
{ |
58
|
|
|
/** @var array<Column> $columns */ |
59
|
|
|
$columns = [$this->createMock(Column::class)]; |
60
|
|
|
|
61
|
|
|
$this->innerMapping->method("collectDBALColumns")->willReturn($columns); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$this->assertEquals($columns, $this->proxy->collectDBALColumns()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @test |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
public function shouldForwardValueResolving() |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
/** @var string $value */ |
72
|
|
|
$value = "Lorem ipsum"; |
73
|
|
|
|
74
|
|
|
/** @var HydrationContextInterface $context */ |
75
|
|
|
$context = $this->createMock(HydrationContextInterface::class); |
76
|
|
|
|
77
|
|
|
$this->innerMapping->method("resolveValue")->willReturn($value); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$this->assertEquals($value, $this->proxy->resolveValue($context, [])); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @test |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function shouldForwardValueReverting() |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
/** @var array<string, string> $data */ |
88
|
|
|
$data = ["column" => "Lorem ipsum"]; |
89
|
|
|
|
90
|
|
|
/** @var HydrationContextInterface $context */ |
91
|
|
|
$context = $this->createMock(HydrationContextInterface::class); |
92
|
|
|
|
93
|
|
|
$this->innerMapping->method("revertValue")->willReturn($data); |
|
|
|
|
94
|
|
|
|
95
|
|
|
$this->assertEquals($data, $this->proxy->revertValue($context, [])); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @test |
100
|
|
|
*/ |
101
|
|
|
public function shouldForwardValueAssertion() |
102
|
|
|
{ |
103
|
|
|
/** @var array<string, string> $data */ |
104
|
|
|
$data = ["column" => "Lorem ipsum"]; |
|
|
|
|
105
|
|
|
|
106
|
|
|
/** @var HydrationContextInterface $context */ |
107
|
|
|
$context = $this->createMock(HydrationContextInterface::class); |
108
|
|
|
|
109
|
|
|
$this->innerMapping->expects($this->once())->method("assertValue")->with( |
|
|
|
|
110
|
|
|
$this->equalTo($context), |
111
|
|
|
$this->equalTo([]), |
112
|
|
|
$this->equalTo("Lorem ipsum") |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
$this->proxy->assertValue($context, [], 'Lorem ipsum'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @test |
120
|
|
|
*/ |
121
|
|
View Code Duplication |
public function shouldForwardWakeUp() |
|
|
|
|
122
|
|
|
{ |
123
|
|
|
/** @var ContainerInterface $context */ |
124
|
|
|
$container = $this->createMock(ContainerInterface::class); |
125
|
|
|
|
126
|
|
|
$this->innerMapping->expects($this->once())->method("wakeUpMapping")->with( |
|
|
|
|
127
|
|
|
$this->equalTo($container) |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
$this->proxy->wakeUpMapping($container); |
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
} |
134
|
|
|
|
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..