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