|
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\ChoiceMapping; |
|
12
|
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use Addiks\RDMBundle\Mapping\ChoiceMapping; |
|
15
|
|
|
use Doctrine\DBAL\Schema\Column; |
|
16
|
|
|
use Doctrine\DBAL\Types\Type; |
|
17
|
|
|
use Addiks\RDMBundle\Mapping\MappingInterface; |
|
18
|
|
|
|
|
19
|
|
|
final class ChoiceMappingTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var ChoiceMapping |
|
24
|
|
|
*/ |
|
25
|
|
|
private $choiceMapping; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var MappingInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
private $optionMappingA; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var MappingInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
private $optionMappingB; |
|
36
|
|
|
|
|
37
|
|
|
public function setUp() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->optionMappingA = $this->createMock(MappingInterface::class); |
|
|
|
|
|
|
40
|
|
|
$this->optionMappingB = $this->createMock(MappingInterface::class); |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
$this->choiceMapping = new ChoiceMapping( |
|
43
|
|
|
new Column("some_column_name", Type::getType('string'), [ |
|
44
|
|
|
'notnull' => false, |
|
45
|
|
|
'length' => 255 |
|
46
|
|
|
]), |
|
47
|
|
|
[ |
|
48
|
|
|
$this->optionMappingA, |
|
49
|
|
|
$this->optionMappingB, |
|
50
|
|
|
], |
|
51
|
|
|
"in foo_file at bar_line!" |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @test |
|
57
|
|
|
*/ |
|
58
|
|
|
public function shouldHaveChoices() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->assertEquals([$this->optionMappingA, $this->optionMappingB], $this->choiceMapping->getChoices()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @test |
|
65
|
|
|
*/ |
|
66
|
|
|
public function shouldDescribeOrigin() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->assertEquals("in foo_file at bar_line!", $this->choiceMapping->describeOrigin()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @test |
|
73
|
|
|
*/ |
|
74
|
|
|
public function shouldCollectColumns() |
|
75
|
|
|
{ |
|
76
|
|
|
$choiceColumn = new Column("some_column_name", Type::getType('string'), [ |
|
77
|
|
|
'notnull' => false, |
|
78
|
|
|
'length' => 255 |
|
79
|
|
|
]); |
|
80
|
|
|
|
|
81
|
|
|
$columnA = new Column("foo_column", Type::getType('integer'), []); |
|
82
|
|
|
$columnB = new Column("bar_column", Type::getType('date'), []); |
|
83
|
|
|
|
|
84
|
|
|
/** @var array<Column> $expectedColumns */ |
|
85
|
|
|
$expectedColumns = array( |
|
86
|
|
|
$choiceColumn, |
|
87
|
|
|
$columnA, |
|
88
|
|
|
$columnB, |
|
89
|
|
|
); |
|
90
|
|
|
|
|
91
|
|
|
$this->optionMappingA->method('collectDBALColumns')->willReturn([$columnA]); |
|
|
|
|
|
|
92
|
|
|
$this->optionMappingB->method('collectDBALColumns')->willReturn([$columnB]); |
|
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
/** @var array<Column> $actualColumns */ |
|
95
|
|
|
$actualColumns = $this->choiceMapping->collectDBALColumns(); |
|
96
|
|
|
|
|
97
|
|
|
$this->assertEquals($expectedColumns, $actualColumns); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @test |
|
102
|
|
|
*/ |
|
103
|
|
|
public function shouldHaveDeterminatorColumn() |
|
104
|
|
|
{ |
|
105
|
|
|
$expectedColumn = new Column("some_column_name", Type::getType('string'), [ |
|
106
|
|
|
'notnull' => false, |
|
107
|
|
|
'length' => 255 |
|
108
|
|
|
]); |
|
109
|
|
|
|
|
110
|
|
|
$this->assertEquals($expectedColumn, $this->choiceMapping->getDeterminatorColumn()); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @test |
|
115
|
|
|
*/ |
|
116
|
|
|
public function shouldHaveADeterminatorColumnName() |
|
117
|
|
|
{ |
|
118
|
|
|
$this->assertEquals("some_column_name", $this->choiceMapping->getDeterminatorColumnName()); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|
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..