1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\ODataMetadata\Tests; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\ODataMetadata\IsOK; |
6
|
|
|
use AlgoWeb\ODataMetadata\MetadataManager; |
7
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer; |
8
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\Schema; |
9
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TAssociationType; |
10
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TComplexTypePropertyType; |
11
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TComplexTypeType; |
12
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType; |
13
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityTypeType; |
14
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionReturnTypeType; |
15
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionType; |
16
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType; |
17
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TTextType; |
18
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edmx\Edmx; |
19
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edmx\TDataServicesType; |
20
|
|
|
use Mockery as m; |
21
|
|
|
|
22
|
|
|
class MetadataManagerTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
public function testIsOKAtDefault() |
25
|
|
|
{ |
26
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
|
|
|
27
|
|
|
$metadataManager = new MetadataManager(); |
28
|
|
|
$msg = null; |
29
|
|
|
$edmx = $metadataManager->getEdmx(); |
30
|
|
|
$this->assertTrue($edmx->isOK($msg), $msg); |
31
|
|
|
$this->assertNull($msg); |
32
|
|
|
|
33
|
|
|
$d = $metadataManager->getEdmxXML(); |
|
|
|
|
34
|
|
|
$this->v3MetadataAgainstXSD($d); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function v3MetadataAgainstXSD($data) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
|
|
|
40
|
|
|
|
41
|
|
|
$goodxsd = dirname(__DIR__) . $ds . 'xsd' . $ds . 'Microsoft.Data.Entity.Design.Edmx_3.Fixed.xsd'; |
42
|
|
|
if (!file_exists($goodxsd)) { |
43
|
|
|
return true; |
44
|
|
|
} |
45
|
|
|
$xml = new \DOMDocument(); |
46
|
|
|
$xml->loadXML($data); |
47
|
|
|
return $xml->schemaValidate($goodxsd); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testEntitysAndProperties() |
51
|
|
|
{ |
52
|
|
|
$metadataManager = new MetadataManager(); |
53
|
|
|
$result = null; |
54
|
|
|
|
55
|
|
|
list($eType, $result) = $metadataManager->addEntityType('Category'); |
56
|
|
|
$this->assertNotFalse($eType, 'Etype is false not type ' . $metadataManager->getLastError()); |
57
|
|
|
$metadataManager->addPropertyToEntityType($eType, 'CategoryID', 'Int32', null, false, true, 'Identity'); |
58
|
|
|
$metadataManager->addPropertyToEntityType($eType, 'CategoryName', 'String'); |
59
|
|
|
$metadataManager->addPropertyToEntityType($eType, 'Description', 'String'); |
60
|
|
|
$metadataManager->addPropertyToEntityType($eType, 'Picture', 'Binary'); |
61
|
|
|
|
62
|
|
|
list($eType, $result) = $metadataManager->addEntityType('CustomerDemographic'); |
63
|
|
|
$metadataManager->addPropertyToEntityType($eType, 'CustomerTypeID', 'String', null, false, true); |
64
|
|
|
$metadataManager->addPropertyToEntityType($eType, 'CustomerDesc', 'String'); |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
$msg = null; |
68
|
|
|
$edmx = $metadataManager->getEdmx(); |
69
|
|
|
$this->assertTrue($edmx->isOK($msg), $msg); |
70
|
|
|
$this->assertNull($msg); |
71
|
|
|
|
72
|
|
|
$d = $metadataManager->getEdmxXML(); |
|
|
|
|
73
|
|
|
$this->v3MetadataAgainstXSD($d); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testEntitysAndPropertiesAndNavigationProperties() |
77
|
|
|
{ |
78
|
|
|
$msg = null; |
79
|
|
|
$metadataManager = new MetadataManager(); |
80
|
|
|
$result = null; |
81
|
|
|
|
82
|
|
|
list($CategoryType, $result) = $metadataManager->addEntityType('Category'); |
|
|
|
|
83
|
|
|
$this->assertNotFalse($CategoryType, 'Etype is false not type ' . $metadataManager->getLastError()); |
|
|
|
|
84
|
|
|
$metadataManager->addPropertyToEntityType($CategoryType, 'CategoryID', 'Int32', null, false, true, 'Identity'); |
|
|
|
|
85
|
|
|
$metadataManager->addPropertyToEntityType($CategoryType, 'CategoryName', 'String'); |
|
|
|
|
86
|
|
|
$metadataManager->addPropertyToEntityType($CategoryType, 'Description', 'String'); |
|
|
|
|
87
|
|
|
$metadataManager->addPropertyToEntityType($CategoryType, 'Picture', 'Binary'); |
|
|
|
|
88
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
89
|
|
|
|
90
|
|
|
list($CustomerDemographicType, $result) = $metadataManager->addEntityType('CustomerDemographic'); |
|
|
|
|
91
|
|
|
$metadataManager->addPropertyToEntityType($CustomerDemographicType, 'CustomerTypeID', 'String', null, false, true); |
|
|
|
|
92
|
|
|
$metadataManager->addPropertyToEntityType($CustomerDemographicType, 'CustomerDesc', 'String'); |
|
|
|
|
93
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
94
|
|
|
|
95
|
|
|
list($CustomerType, $result) = $metadataManager->addEntityType('Customer'); |
|
|
|
|
96
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, 'CustomerID', 'String', null, false, true); |
|
|
|
|
97
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, 'CompanyName', 'String'); |
|
|
|
|
98
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, 'ContactName', 'String'); |
|
|
|
|
99
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, 'ContactTitle', 'String'); |
|
|
|
|
100
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, 'Address', 'String'); |
|
|
|
|
101
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, 'City', 'String'); |
|
|
|
|
102
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, 'Region', 'String'); |
|
|
|
|
103
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, 'PostalCode', 'String'); |
|
|
|
|
104
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, 'Country', 'String'); |
|
|
|
|
105
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, 'Phone', 'String'); |
|
|
|
|
106
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, 'Fax', 'String'); |
|
|
|
|
107
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
108
|
|
|
|
109
|
|
|
list($EmployeeType, $result) = $metadataManager->addEntityType('Employee'); |
|
|
|
|
110
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'EmployeeID', 'Int32', null, false, true, 'Identity'); |
|
|
|
|
111
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'LastName', 'String'); |
|
|
|
|
112
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'FirstName', 'String'); |
|
|
|
|
113
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'Title', 'String'); |
|
|
|
|
114
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'TitleOfCourtesy', 'String'); |
|
|
|
|
115
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'BirthDate', 'DateTime'); |
|
|
|
|
116
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'HireDate', 'DateTime'); |
|
|
|
|
117
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'Address', 'String'); |
|
|
|
|
118
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'City', 'String'); |
|
|
|
|
119
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'Region', 'String'); |
|
|
|
|
120
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'PostalCode', 'String'); |
|
|
|
|
121
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'Country', 'String'); |
|
|
|
|
122
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'HomePhone', 'String'); |
|
|
|
|
123
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'Extension', 'String'); |
|
|
|
|
124
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'Photo', 'Binary'); |
|
|
|
|
125
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'Notes', 'String'); |
|
|
|
|
126
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'ReportsTo', 'Int32'); |
|
|
|
|
127
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, 'PhotoPath', 'String'); |
|
|
|
|
128
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
129
|
|
|
|
130
|
|
|
list($Order_DetailType, $result) = $metadataManager->addEntityType('Order_Detail'); |
|
|
|
|
131
|
|
|
$metadataManager->addPropertyToEntityType($Order_DetailType, 'OrderID', 'Int32', null, false, true); |
|
|
|
|
132
|
|
|
$metadataManager->addPropertyToEntityType($Order_DetailType, 'ProductID', 'Int32', null, false, true); |
|
|
|
|
133
|
|
|
$metadataManager->addPropertyToEntityType($Order_DetailType, 'UnitPrice', 'Decimal'); |
|
|
|
|
134
|
|
|
$metadataManager->addPropertyToEntityType($Order_DetailType, 'Quantity', 'Int16'); |
|
|
|
|
135
|
|
|
$metadataManager->addPropertyToEntityType($Order_DetailType, 'Discount', 'Single'); |
|
|
|
|
136
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
137
|
|
|
|
138
|
|
|
list($OrderType, $result) = $metadataManager->addEntityType('Order'); |
|
|
|
|
139
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'OrderID', 'Int32', null, false, true, 'Identity'); |
|
|
|
|
140
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'CustomerID', 'String'); |
|
|
|
|
141
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'EmployeeID', 'Int32'); |
|
|
|
|
142
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'OrderDate', 'DateTime'); |
|
|
|
|
143
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'RequiredDate', 'DateTime'); |
|
|
|
|
144
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'ShippedDate', 'DateTime'); |
|
|
|
|
145
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'ShipVia', 'DateTime'); |
|
|
|
|
146
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'Freight', 'Decimal'); |
|
|
|
|
147
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'ShipName', 'String'); |
|
|
|
|
148
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'ShipAddress', 'String'); |
|
|
|
|
149
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'ShipCity', 'String'); |
|
|
|
|
150
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'ShipRegion', 'String'); |
|
|
|
|
151
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'ShipPostalCode', 'String'); |
|
|
|
|
152
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, 'ShipCountry', 'String'); |
|
|
|
|
153
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
154
|
|
|
|
155
|
|
|
list($ProductType, $result) = $metadataManager->addEntityType('Product'); |
|
|
|
|
156
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, 'ProductID', 'Int32', null, false, true, 'Identity'); |
|
|
|
|
157
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, 'ProductName', 'String'); |
|
|
|
|
158
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, 'SupplierID', 'Int32'); |
|
|
|
|
159
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, 'CategoryID', 'Int32'); |
|
|
|
|
160
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, 'QuantityPerUnit', 'String'); |
|
|
|
|
161
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, 'UnitPrice', 'Decimal'); |
|
|
|
|
162
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, 'UnitsInStock', 'Int16'); |
|
|
|
|
163
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, 'UnitsOnOrder', 'Int16'); |
|
|
|
|
164
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, 'ReorderLevel', 'Int16'); |
|
|
|
|
165
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, 'Discontinued', 'Boolean'); |
|
|
|
|
166
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
167
|
|
|
|
168
|
|
|
$expectedRelation = 'Data.Category_Products_Product_Category'; |
169
|
|
|
list($principalNav, ) = $metadataManager->addNavigationPropertyToEntityType( |
170
|
|
|
$CategoryType, '*', 'Products', $ProductType, '1', 'Category', ['CategoryID'], ['CategoryID'] |
|
|
|
|
171
|
|
|
); |
172
|
|
|
$this->assertEquals($expectedRelation, $principalNav->getRelationship()); |
173
|
|
|
$metadataManager->addNavigationPropertyToEntityType( |
174
|
|
|
$Order_DetailType, '1', 'Order', $ProductType, '*', 'Order_Details', ['OrderID'], ['CategoryID'] |
|
|
|
|
175
|
|
|
); |
176
|
|
|
// <NavigationProperty Name="Order_Details" Relationship="NorthwindModel.FK_Order_Details_Products" ToRole="Order_Details" FromRole="Products"/> |
|
|
|
|
177
|
|
|
|
178
|
|
|
|
179
|
|
|
$msg = null; |
180
|
|
|
$edmx = $metadataManager->getEdmx(); |
181
|
|
|
$this->assertTrue($edmx->isOK($msg), $msg); |
182
|
|
|
$this->assertNull($msg); |
183
|
|
|
|
184
|
|
|
$d = $metadataManager->getEdmxXML(); |
|
|
|
|
185
|
|
|
$this->v3MetadataAgainstXSD($d); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function testAddManyToManyNavProperty() |
189
|
|
|
{ |
190
|
|
|
list($msg, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests(); |
|
|
|
|
191
|
|
|
|
192
|
|
|
$expectedRelation = 'Data.Category_custom_Customer_categor'; |
193
|
|
|
list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType( |
194
|
|
|
$CategoryType, |
|
|
|
|
195
|
|
|
'*', |
196
|
|
|
'custom', |
197
|
|
|
$CustomerType, |
|
|
|
|
198
|
|
|
'*', |
199
|
|
|
'categor' |
200
|
|
|
); |
201
|
|
|
$this->assertEquals($principal->getFromRole(), $dependent->getToRole()); |
202
|
|
|
$this->assertEquals($dependent->getFromRole(), $principal->getToRole()); |
203
|
|
|
$this->assertEquals('custom', $principal->getName()); |
204
|
|
|
$this->assertEquals('categor', $dependent->getName()); |
205
|
|
|
$this->assertEquals($expectedRelation, $principal->getRelationship()); |
206
|
|
|
$this->assertEquals($expectedRelation, $dependent->getRelationship()); |
207
|
|
|
|
208
|
|
|
$navProps = [$principal, $dependent]; |
209
|
|
|
$assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation(); |
210
|
|
|
$this->assertEquals(1, count($assoc)); |
211
|
|
|
$assoc = $assoc[0]; |
212
|
|
|
$this->assertTrue($assoc instanceof TAssociationType); |
213
|
|
|
$this->assertTrue($assoc->isOK($msg), $msg); |
214
|
|
|
|
215
|
|
|
$this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship()); |
216
|
|
|
$ends = $assoc->getEnd(); |
217
|
|
|
|
218
|
|
|
$this->assertEquals(2, count($ends)); |
219
|
|
|
$this->checkNavProps($navProps, $ends); |
220
|
|
|
list($principalEnd, $dependentEnd) = $this->figureOutEnds($ends, $principal, $dependent); |
221
|
|
|
$this->assertEquals('*', $principalEnd->getMultiplicity()); |
222
|
|
|
$this->assertEquals('*', $dependentEnd->getMultiplicity()); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
View Code Duplication |
public function testAddOneToManyNavProperty() |
226
|
|
|
{ |
227
|
|
|
list($msg, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests(); |
|
|
|
|
228
|
|
|
|
229
|
|
|
list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType( |
230
|
|
|
$CategoryType, |
|
|
|
|
231
|
|
|
'*', |
232
|
|
|
'custom', |
233
|
|
|
$CustomerType, |
|
|
|
|
234
|
|
|
'1', |
235
|
|
|
'categor' |
236
|
|
|
); |
237
|
|
|
$this->assertEquals($principal->getFromRole(), $dependent->getToRole()); |
238
|
|
|
$this->assertEquals($dependent->getFromRole(), $principal->getToRole()); |
239
|
|
|
$this->assertEquals('custom', $principal->getName()); |
240
|
|
|
$this->assertEquals('categor', $dependent->getName()); |
241
|
|
|
|
242
|
|
|
$navProps = [$principal, $dependent]; |
243
|
|
|
$assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation(); |
244
|
|
|
$this->assertEquals(1, count($assoc)); |
245
|
|
|
$assoc = $assoc[0]; |
246
|
|
|
$this->assertTrue($assoc instanceof TAssociationType); |
247
|
|
|
$this->assertTrue($assoc->isOK($msg), $msg); |
248
|
|
|
|
249
|
|
|
$this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship()); |
250
|
|
|
$ends = $assoc->getEnd(); |
251
|
|
|
|
252
|
|
|
$this->assertEquals(2, count($ends)); |
253
|
|
|
$this->checkNavProps($navProps, $ends); |
254
|
|
|
list($principalEnd, $dependentEnd) = $this->figureOutEnds($ends, $principal, $dependent); |
255
|
|
|
$this->assertEquals('*', $principalEnd->getMultiplicity()); |
256
|
|
|
$this->assertEquals('1', $dependentEnd->getMultiplicity()); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
View Code Duplication |
public function testAddManyToOneNavProperty() |
260
|
|
|
{ |
261
|
|
|
list($msg, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests(); |
|
|
|
|
262
|
|
|
|
263
|
|
|
list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType( |
264
|
|
|
$CategoryType, |
|
|
|
|
265
|
|
|
'1', |
266
|
|
|
'custom', |
267
|
|
|
$CustomerType, |
|
|
|
|
268
|
|
|
'*', |
269
|
|
|
'categor' |
270
|
|
|
); |
271
|
|
|
$this->assertEquals($principal->getFromRole(), $dependent->getToRole()); |
272
|
|
|
$this->assertEquals($dependent->getFromRole(), $principal->getToRole()); |
273
|
|
|
$this->assertEquals('custom', $principal->getName()); |
274
|
|
|
$this->assertEquals('categor', $dependent->getName()); |
275
|
|
|
|
276
|
|
|
$navProps = [$principal, $dependent]; |
277
|
|
|
$assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation(); |
278
|
|
|
$this->assertEquals(1, count($assoc)); |
279
|
|
|
$assoc = $assoc[0]; |
280
|
|
|
$this->assertTrue($assoc instanceof TAssociationType); |
281
|
|
|
$this->assertTrue($assoc->isOK($msg), $msg); |
282
|
|
|
|
283
|
|
|
$this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship()); |
284
|
|
|
$ends = $assoc->getEnd(); |
285
|
|
|
|
286
|
|
|
$this->assertEquals(2, count($ends)); |
287
|
|
|
$this->checkNavProps($navProps, $ends); |
288
|
|
|
list($principalEnd, $dependentEnd) = $this->figureOutEnds($ends, $principal, $dependent); |
289
|
|
|
$this->assertEquals('1', $principalEnd->getMultiplicity()); |
290
|
|
|
$this->assertEquals('*', $dependentEnd->getMultiplicity()); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
View Code Duplication |
public function testAddOneToOneForwardNavProperty() |
294
|
|
|
{ |
295
|
|
|
list($msg, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests(); |
|
|
|
|
296
|
|
|
|
297
|
|
|
list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType( |
298
|
|
|
$CategoryType, |
|
|
|
|
299
|
|
|
'0..1', |
300
|
|
|
'custom', |
301
|
|
|
$CustomerType, |
|
|
|
|
302
|
|
|
'1', |
303
|
|
|
'categor' |
304
|
|
|
); |
305
|
|
|
$this->assertEquals($principal->getFromRole(), $dependent->getToRole()); |
306
|
|
|
$this->assertEquals($dependent->getFromRole(), $principal->getToRole()); |
307
|
|
|
$this->assertEquals('custom', $principal->getName()); |
308
|
|
|
$this->assertEquals('categor', $dependent->getName()); |
309
|
|
|
|
310
|
|
|
$navProps = [$principal, $dependent]; |
311
|
|
|
$assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation(); |
312
|
|
|
$this->assertEquals(1, count($assoc)); |
313
|
|
|
$assoc = $assoc[0]; |
314
|
|
|
$this->assertTrue($assoc instanceof TAssociationType); |
315
|
|
|
$this->assertTrue($assoc->isOK($msg), $msg); |
316
|
|
|
|
317
|
|
|
$this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship()); |
318
|
|
|
$ends = $assoc->getEnd(); |
319
|
|
|
|
320
|
|
|
$this->assertEquals(2, count($ends)); |
321
|
|
|
$this->checkNavProps($navProps, $ends); |
322
|
|
|
list($principalEnd, $dependentEnd) = $this->figureOutEnds($ends, $principal, $dependent); |
323
|
|
|
$this->assertEquals('0..1', $principalEnd->getMultiplicity()); |
324
|
|
|
$this->assertEquals('1', $dependentEnd->getMultiplicity()); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
View Code Duplication |
public function testAddOneToOneReverseNavProperty() |
328
|
|
|
{ |
329
|
|
|
list($msg, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests(); |
|
|
|
|
330
|
|
|
|
331
|
|
|
list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType( |
332
|
|
|
$CategoryType, |
|
|
|
|
333
|
|
|
'1', |
334
|
|
|
'custom', |
335
|
|
|
$CustomerType, |
|
|
|
|
336
|
|
|
'0..1', |
337
|
|
|
'categor' |
338
|
|
|
); |
339
|
|
|
$this->assertEquals($principal->getFromRole(), $dependent->getToRole()); |
340
|
|
|
$this->assertEquals($dependent->getFromRole(), $principal->getToRole()); |
341
|
|
|
$this->assertEquals('custom', $principal->getName()); |
342
|
|
|
$this->assertEquals('categor', $dependent->getName()); |
343
|
|
|
|
344
|
|
|
$navProps = [$principal, $dependent]; |
345
|
|
|
$assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation(); |
346
|
|
|
$this->assertEquals(1, count($assoc)); |
347
|
|
|
$assoc = $assoc[0]; |
348
|
|
|
$this->assertTrue($assoc instanceof TAssociationType); |
349
|
|
|
$this->assertTrue($assoc->isOK($msg), $msg); |
350
|
|
|
|
351
|
|
|
$this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship()); |
352
|
|
|
$ends = $assoc->getEnd(); |
353
|
|
|
|
354
|
|
|
$this->assertEquals(2, count($ends)); |
355
|
|
|
$this->checkNavProps($navProps, $ends); |
356
|
|
|
list($principalEnd, $dependentEnd) = $this->figureOutEnds($ends, $principal, $dependent); |
357
|
|
|
$this->assertEquals('1', $principalEnd->getMultiplicity()); |
358
|
|
|
$this->assertEquals('0..1', $dependentEnd->getMultiplicity()); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
public function testMetadataSerialiseRoundTrip() |
362
|
|
|
{ |
363
|
|
|
$bar = new MetadataManager(); |
364
|
|
|
$foo = new MetadataManager(); |
365
|
|
|
|
366
|
|
|
$cereal = serialize($foo); |
367
|
|
|
|
368
|
|
|
$foo = unserialize($cereal); |
369
|
|
|
$this->assertTrue(null != $foo->getSerialiser()); |
370
|
|
|
$this->assertEquals($bar, $foo); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
public function testCreateSingletonBadReturnType() |
374
|
|
|
{ |
375
|
|
|
$returnType = m::mock(IsOK::class); |
376
|
|
|
$foo = new MetadataManager(); |
377
|
|
|
|
378
|
|
|
$expected = 'Expected return type must be either TEntityType or TComplexType'; |
379
|
|
|
$actual = null; |
380
|
|
|
|
381
|
|
|
try { |
382
|
|
|
$foo->createSingleton(null, $returnType); |
383
|
|
|
} catch (\InvalidArgumentException $e) { |
384
|
|
|
$actual = $e->getMessage(); |
385
|
|
|
} |
386
|
|
|
$this->assertEquals($expected, $actual); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
View Code Duplication |
public function testCreateSingletonEmptyName() |
390
|
|
|
{ |
391
|
|
|
$returnType = m::mock(TEntityTypeType::class); |
392
|
|
|
$this->assertTrue($returnType instanceof TEntityTypeType, get_class($returnType)); |
393
|
|
|
$foo = new MetadataManager(); |
394
|
|
|
|
395
|
|
|
$expected = 'Name must be a non-empty string'; |
396
|
|
|
$actual = null; |
397
|
|
|
|
398
|
|
|
try { |
399
|
|
|
$foo->createSingleton(null, $returnType); |
400
|
|
|
} catch (\InvalidArgumentException $e) { |
401
|
|
|
$actual = $e->getMessage(); |
402
|
|
|
} |
403
|
|
|
$this->assertEquals($expected, $actual); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
View Code Duplication |
public function testCreateSingletonNonStringName() |
407
|
|
|
{ |
408
|
|
|
$returnType = m::mock(TEntityTypeType::class); |
409
|
|
|
$this->assertTrue($returnType instanceof TEntityTypeType, get_class($returnType)); |
410
|
|
|
$foo = new MetadataManager(); |
411
|
|
|
|
412
|
|
|
$expected = 'Name must be a non-empty string'; |
413
|
|
|
$actual = null; |
414
|
|
|
|
415
|
|
|
try { |
416
|
|
|
$foo->createSingleton($returnType, $returnType); |
417
|
|
|
} catch (\InvalidArgumentException $e) { |
418
|
|
|
$actual = $e->getMessage(); |
419
|
|
|
} |
420
|
|
|
$this->assertEquals($expected, $actual); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
public function testCreateSingletonSuccessful() |
424
|
|
|
{ |
425
|
|
|
$msg = null; |
426
|
|
|
$name = 'singleton'; |
427
|
|
|
$returnType = m::mock(TEntityTypeType::class)->makePartial(); |
428
|
|
|
$returnType->shouldReceive('getName')->andReturn('doubleton'); |
429
|
|
|
|
430
|
|
|
$entityContainer = m::mock(EntityContainer::class)->makePartial(); |
431
|
|
|
$entityContainer->shouldReceive('addToFunctionImport')->andReturn(null)->once(); |
432
|
|
|
|
433
|
|
|
$schema = m::mock(Schema::class)->makePartial(); |
434
|
|
|
$schema->shouldReceive('getEntityContainer')->andReturn([$entityContainer])->once(); |
435
|
|
|
|
436
|
|
|
$services = m::mock(TDataServicesType::class); |
437
|
|
|
$services->shouldReceive('getSchema')->andReturn([$schema])->once(); |
438
|
|
|
|
439
|
|
|
$edmx = m::mock(Edmx::class)->makePartial(); |
440
|
|
|
$edmx->shouldReceive('getDataServiceType')->andReturn($services); |
441
|
|
|
|
442
|
|
|
$foo = m::mock(MetadataManager::class)->makePartial()->shouldAllowMockingProtectedMethods(); |
443
|
|
|
$foo->shouldReceive('getEdmx')->andReturn($edmx); |
444
|
|
|
$foo->shouldReceive('getNamespace')->andReturn('Data')->atLeast(1); |
445
|
|
|
|
446
|
|
|
$result = $foo->createSingleton($name, $returnType); |
447
|
|
|
$this->assertTrue($result instanceof EntityContainer\FunctionImportAnonymousType, get_class($result)); |
448
|
|
|
$this->assertTrue($result->isOK($msg)); |
449
|
|
|
$this->assertNull($result->getDocumentation()); |
450
|
|
|
} |
451
|
|
|
|
452
|
|
View Code Duplication |
public function testCreateSingletonWithDocumentation() |
453
|
|
|
{ |
454
|
|
|
$msg = null; |
455
|
|
|
$name = 'singleton'; |
456
|
|
|
$shortDesc = new TTextType(); |
457
|
|
|
$longDesc = new TTextType(); |
458
|
|
|
|
459
|
|
|
$returnType = m::mock(TEntityTypeType::class)->makePartial(); |
460
|
|
|
$returnType->shouldReceive('getName')->andReturn('doubleton'); |
461
|
|
|
|
462
|
|
|
$entityContainer = m::mock(EntityContainer::class)->makePartial(); |
463
|
|
|
$entityContainer->shouldReceive('addToFunctionImport')->andReturn(null)->once(); |
464
|
|
|
|
465
|
|
|
$schema = m::mock(Schema::class)->makePartial(); |
466
|
|
|
$schema->shouldReceive('getEntityContainer')->andReturn([$entityContainer])->once(); |
467
|
|
|
$edmx = m::mock(Edmx::class)->makePartial(); |
468
|
|
|
$edmx->shouldReceive('getDataServiceType->getSchema')->andReturn([$schema])->once(); |
469
|
|
|
|
470
|
|
|
$foo = m::mock(MetadataManager::class)->makePartial()->shouldAllowMockingProtectedMethods(); |
471
|
|
|
$foo->shouldReceive('getEdmx')->andReturn($edmx); |
472
|
|
|
$foo->shouldReceive('getNamespace')->andReturn('Data')->atLeast(1); |
473
|
|
|
|
474
|
|
|
$result = $foo->createSingleton($name, $returnType, $shortDesc, $longDesc); |
475
|
|
|
$this->assertTrue($result instanceof EntityContainer\FunctionImportAnonymousType, get_class($result)); |
476
|
|
|
$this->assertTrue($result->isOK($msg)); |
477
|
|
|
$this->assertNotNull($result->getDocumentation()); |
478
|
|
|
} |
479
|
|
|
|
480
|
|
View Code Duplication |
public function testCreateSingletonWithDocumentationOnlyShortDesc() |
481
|
|
|
{ |
482
|
|
|
$msg = null; |
483
|
|
|
$name = 'singleton'; |
484
|
|
|
$shortDesc = new TTextType(); |
485
|
|
|
$longDesc = null; |
486
|
|
|
|
487
|
|
|
$returnType = m::mock(TEntityTypeType::class)->makePartial(); |
488
|
|
|
$returnType->shouldReceive('getName')->andReturn('doubleton'); |
489
|
|
|
|
490
|
|
|
$entityContainer = m::mock(EntityContainer::class)->makePartial(); |
491
|
|
|
$entityContainer->shouldReceive('addToFunctionImport')->andReturn(null)->once(); |
492
|
|
|
|
493
|
|
|
$schema = m::mock(Schema::class)->makePartial(); |
494
|
|
|
$schema->shouldReceive('getEntityContainer')->andReturn([$entityContainer])->once(); |
495
|
|
|
$edmx = m::mock(Edmx::class)->makePartial(); |
496
|
|
|
$edmx->shouldReceive('getDataServiceType->getSchema')->andReturn([$schema])->once(); |
497
|
|
|
|
498
|
|
|
$foo = m::mock(MetadataManager::class)->makePartial()->shouldAllowMockingProtectedMethods(); |
499
|
|
|
$foo->shouldReceive('getEdmx')->andReturn($edmx); |
500
|
|
|
$foo->shouldReceive('getNamespace')->andReturn('Data')->atLeast(1); |
501
|
|
|
|
502
|
|
|
$result = $foo->createSingleton($name, $returnType, $shortDesc, $longDesc); |
503
|
|
|
$this->assertTrue($result instanceof EntityContainer\FunctionImportAnonymousType, get_class($result)); |
504
|
|
|
$this->assertTrue($result->isOK($msg)); |
505
|
|
|
$this->assertNull($result->getDocumentation()); |
506
|
|
|
} |
507
|
|
|
|
508
|
|
View Code Duplication |
public function testCreateSingletonWithDocumentationOnlyLongDesc() |
509
|
|
|
{ |
510
|
|
|
$msg = null; |
511
|
|
|
$name = 'singleton'; |
512
|
|
|
$shortDesc = null; |
513
|
|
|
$longDesc = new TTextType(); |
514
|
|
|
|
515
|
|
|
$returnType = m::mock(TEntityTypeType::class)->makePartial(); |
516
|
|
|
$returnType->shouldReceive('getName')->andReturn('doubleton'); |
517
|
|
|
|
518
|
|
|
$entityContainer = m::mock(EntityContainer::class)->makePartial(); |
519
|
|
|
$entityContainer->shouldReceive('addToFunctionImport')->andReturn(null)->once(); |
520
|
|
|
|
521
|
|
|
$schema = m::mock(Schema::class)->makePartial(); |
522
|
|
|
$schema->shouldReceive('getEntityContainer')->andReturn([$entityContainer])->once(); |
523
|
|
|
$edmx = m::mock(Edmx::class)->makePartial(); |
524
|
|
|
$edmx->shouldReceive('getDataServiceType->getSchema')->andReturn([$schema])->once(); |
525
|
|
|
|
526
|
|
|
$foo = m::mock(MetadataManager::class)->makePartial()->shouldAllowMockingProtectedMethods(); |
527
|
|
|
$foo->shouldReceive('getEdmx')->andReturn($edmx); |
528
|
|
|
$foo->shouldReceive('getNamespace')->andReturn('Data')->atLeast(1); |
529
|
|
|
|
530
|
|
|
$result = $foo->createSingleton($name, $returnType, $shortDesc, $longDesc); |
531
|
|
|
$this->assertTrue($result instanceof EntityContainer\FunctionImportAnonymousType, get_class($result)); |
532
|
|
|
$this->assertTrue($result->isOK($msg)); |
533
|
|
|
$this->assertNull($result->getDocumentation()); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
View Code Duplication |
public function testMalformedMultiplicity() |
537
|
|
|
{ |
538
|
|
|
list(, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests(); |
|
|
|
|
539
|
|
|
|
540
|
|
|
$expected = 'Malformed multiplicity - valid values are *, 0..1 and 1'; |
541
|
|
|
$actual = null; |
542
|
|
|
|
543
|
|
|
try { |
544
|
|
|
$metadataManager->addNavigationPropertyToEntityType( |
545
|
|
|
$CategoryType, |
|
|
|
|
546
|
|
|
'1', |
547
|
|
|
'Customers', |
548
|
|
|
$CustomerType, |
|
|
|
|
549
|
|
|
'ABC', |
550
|
|
|
'Categories' |
551
|
|
|
); |
552
|
|
|
} catch (\InvalidArgumentException $e) { |
553
|
|
|
$actual = $e->getMessage(); |
554
|
|
|
} |
555
|
|
|
$this->assertEquals($expected, $actual); |
556
|
|
|
} |
557
|
|
|
|
558
|
|
View Code Duplication |
public function testInvalidMultiplicityBelongsOnBothEnds() |
559
|
|
|
{ |
560
|
|
|
list(, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests(); |
|
|
|
|
561
|
|
|
|
562
|
|
|
$expected = 'Invalid multiplicity combination - 1 1'; |
563
|
|
|
$actual = null; |
564
|
|
|
|
565
|
|
|
try { |
566
|
|
|
$metadataManager->addNavigationPropertyToEntityType( |
567
|
|
|
$CategoryType, |
|
|
|
|
568
|
|
|
'1', |
569
|
|
|
'Customers', |
570
|
|
|
$CustomerType, |
|
|
|
|
571
|
|
|
'1', |
572
|
|
|
'Categories' |
573
|
|
|
); |
574
|
|
|
} catch (\InvalidArgumentException $e) { |
575
|
|
|
$actual = $e->getMessage(); |
576
|
|
|
} |
577
|
|
|
$this->assertEquals($expected, $actual); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
View Code Duplication |
public function testInvalidMultiplicityManyToHasMany() |
581
|
|
|
{ |
582
|
|
|
list(, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests(); |
|
|
|
|
583
|
|
|
|
584
|
|
|
$expected = 'Invalid multiplicity combination - * 0..1'; |
585
|
|
|
$actual = null; |
586
|
|
|
|
587
|
|
|
try { |
588
|
|
|
$metadataManager->addNavigationPropertyToEntityType( |
589
|
|
|
$CategoryType, |
|
|
|
|
590
|
|
|
'*', |
591
|
|
|
'Customers', |
592
|
|
|
$CustomerType, |
|
|
|
|
593
|
|
|
'0..1', |
594
|
|
|
'Categories' |
595
|
|
|
); |
596
|
|
|
} catch (\InvalidArgumentException $e) { |
597
|
|
|
$actual = $e->getMessage(); |
598
|
|
|
} |
599
|
|
|
$this->assertEquals($expected, $actual); |
600
|
|
|
} |
601
|
|
|
|
602
|
|
View Code Duplication |
public function testAddComplexType() |
603
|
|
|
{ |
604
|
|
|
list(, $metadataManager, , ) = $this->setUpMetadataForNavTests(); |
605
|
|
|
|
606
|
|
|
$name = 'Name'; |
607
|
|
|
$accessType = 'Public'; |
608
|
|
|
$summary = new TTextType(); |
609
|
|
|
$longDescription = new TTextType(); |
610
|
|
|
|
611
|
|
|
$oldCount = count($metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getComplexType()); |
612
|
|
|
|
613
|
|
|
$result = $metadataManager->addComplexType($name, $accessType, $summary, $longDescription); |
614
|
|
|
|
615
|
|
|
$newCount = count($metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getComplexType()); |
616
|
|
|
$this->assertEquals($oldCount+1, $newCount); |
617
|
|
|
$this->assertNotNull($result); |
618
|
|
|
$this->assertTrue($result instanceof TComplexTypeType, get_class($result)); |
619
|
|
|
$this->assertNotNull($result->getDocumentation()); |
620
|
|
|
} |
621
|
|
|
|
622
|
|
View Code Duplication |
public function testAddComplexTypeWithOnlySummary() |
623
|
|
|
{ |
624
|
|
|
list(, $metadataManager, , ) = $this->setUpMetadataForNavTests(); |
625
|
|
|
|
626
|
|
|
$name = 'Name'; |
627
|
|
|
$accessType = 'Public'; |
628
|
|
|
$summary = new TTextType(); |
629
|
|
|
$longDescription = null; |
630
|
|
|
|
631
|
|
|
$oldCount = count($metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getComplexType()); |
632
|
|
|
|
633
|
|
|
$result = $metadataManager->addComplexType($name, $accessType, $summary, $longDescription); |
634
|
|
|
|
635
|
|
|
$newCount = count($metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getComplexType()); |
636
|
|
|
$this->assertEquals($oldCount+1, $newCount); |
637
|
|
|
$this->assertNotNull($result); |
638
|
|
|
$this->assertTrue($result instanceof TComplexTypeType, get_class($result)); |
639
|
|
|
$this->assertNull($result->getDocumentation()); |
640
|
|
|
} |
641
|
|
|
|
642
|
|
View Code Duplication |
public function testAddComplexTypeWithOnlyDescription() |
643
|
|
|
{ |
644
|
|
|
list(, $metadataManager, , ) = $this->setUpMetadataForNavTests(); |
645
|
|
|
|
646
|
|
|
$name = 'Name'; |
647
|
|
|
$accessType = 'Public'; |
648
|
|
|
$summary = null; |
649
|
|
|
$longDescription = new TTextType(); |
650
|
|
|
|
651
|
|
|
$oldCount = count($metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getComplexType()); |
652
|
|
|
|
653
|
|
|
$result = $metadataManager->addComplexType($name, $accessType, $summary, $longDescription); |
654
|
|
|
|
655
|
|
|
$newCount = count($metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getComplexType()); |
656
|
|
|
$this->assertEquals($oldCount+1, $newCount); |
657
|
|
|
$this->assertNotNull($result); |
658
|
|
|
$this->assertTrue($result instanceof TComplexTypeType, get_class($result)); |
659
|
|
|
$this->assertNull($result->getDocumentation()); |
660
|
|
|
} |
661
|
|
|
|
662
|
|
View Code Duplication |
public function testAddPropertyToComplexTypeDefaultValueArray() |
663
|
|
|
{ |
664
|
|
|
$expected = 'Default value cannot be object or array'; |
665
|
|
|
$actual = null; |
666
|
|
|
|
667
|
|
|
list(, $metadataManager, , ) = $this->setUpMetadataForNavTests(); |
668
|
|
|
$complex = m::mock(TComplexTypeType::class); |
669
|
|
|
$name = 'name'; |
670
|
|
|
$type = 'type'; |
671
|
|
|
$defaultValue = []; |
672
|
|
|
|
673
|
|
|
try { |
674
|
|
|
$metadataManager->addPropertyToComplexType($complex, $name, $type, $defaultValue); |
675
|
|
|
} catch (\InvalidArgumentException $e) { |
676
|
|
|
$actual = $e->getMessage(); |
677
|
|
|
} |
678
|
|
|
$this->assertEquals($expected, $actual); |
679
|
|
|
} |
680
|
|
|
|
681
|
|
View Code Duplication |
public function testAddPropertyToComplexTypeDefaultValueObject() |
682
|
|
|
{ |
683
|
|
|
$expected = 'Default value cannot be object or array'; |
684
|
|
|
$actual = null; |
685
|
|
|
|
686
|
|
|
list(, $metadataManager, , ) = $this->setUpMetadataForNavTests(); |
687
|
|
|
$complex = m::mock(TComplexTypeType::class); |
688
|
|
|
$name = 'name'; |
689
|
|
|
$type = 'type'; |
690
|
|
|
$defaultValue = new \stdClass(); |
691
|
|
|
|
692
|
|
|
try { |
693
|
|
|
$metadataManager->addPropertyToComplexType($complex, $name, $type, $defaultValue); |
694
|
|
|
} catch (\InvalidArgumentException $e) { |
695
|
|
|
$actual = $e->getMessage(); |
696
|
|
|
} |
697
|
|
|
$this->assertEquals($expected, $actual); |
698
|
|
|
} |
699
|
|
|
|
700
|
|
View Code Duplication |
public function testAddPropertyToComplexTypeDefaultValueBoolean() |
701
|
|
|
{ |
702
|
|
|
list(, $metadataManager, , ) = $this->setUpMetadataForNavTests(); |
703
|
|
|
$complex = m::mock(TComplexTypeType::class); |
704
|
|
|
$complex->shouldReceive('addToProperty') |
705
|
|
|
->with(m::type(TComplexTypePropertyType::class))->andReturnNull()->once(); |
706
|
|
|
$name = 'name'; |
707
|
|
|
$type = 'type'; |
708
|
|
|
$defaultValue = true; |
709
|
|
|
$summary = new TTextType(); |
710
|
|
|
$longDescription = new TTextType(); |
711
|
|
|
$expectedDefault = 'true'; |
712
|
|
|
|
713
|
|
|
$result = $metadataManager->addPropertyToComplexType( |
714
|
|
|
$complex, |
715
|
|
|
$name, |
716
|
|
|
$type, |
717
|
|
|
$defaultValue, |
718
|
|
|
false, |
719
|
|
|
$summary, |
720
|
|
|
$longDescription |
721
|
|
|
); |
722
|
|
|
$this->assertEquals(1, count($result->getDocumentation())); |
723
|
|
|
$this->assertEquals($expectedDefault, $result->getDefaultValue()); |
724
|
|
|
} |
725
|
|
|
|
726
|
|
View Code Duplication |
public function testAddPropertyToComplexTypeDefaultValueBooleanOnlySummary() |
727
|
|
|
{ |
728
|
|
|
list(, $metadataManager, , ) = $this->setUpMetadataForNavTests(); |
729
|
|
|
$complex = m::mock(TComplexTypeType::class); |
730
|
|
|
$complex->shouldReceive('addToProperty') |
731
|
|
|
->with(m::type(TComplexTypePropertyType::class))->andReturnNull()->once(); |
732
|
|
|
$name = 'name'; |
733
|
|
|
$type = 'type'; |
734
|
|
|
$defaultValue = true; |
735
|
|
|
$summary = new TTextType(); |
736
|
|
|
$longDescription = null; |
737
|
|
|
$expectedDefault = 'true'; |
738
|
|
|
|
739
|
|
|
$result = $metadataManager->addPropertyToComplexType( |
740
|
|
|
$complex, |
741
|
|
|
$name, |
742
|
|
|
$type, |
743
|
|
|
$defaultValue, |
744
|
|
|
false, |
745
|
|
|
$summary, |
746
|
|
|
$longDescription |
747
|
|
|
); |
748
|
|
|
$this->assertNotNull($result); |
749
|
|
|
$this->assertEquals(0, count($result->getDocumentation())); |
750
|
|
|
$this->assertEquals($expectedDefault, $result->getDefaultValue()); |
751
|
|
|
} |
752
|
|
|
|
753
|
|
View Code Duplication |
public function testAddPropertyToComplexTypeDefaultValueBooleanOnlyDescription() |
754
|
|
|
{ |
755
|
|
|
list(, $metadataManager, , ) = $this->setUpMetadataForNavTests(); |
756
|
|
|
$complex = m::mock(TComplexTypeType::class); |
757
|
|
|
$complex->shouldReceive('addToProperty') |
758
|
|
|
->with(m::type(TComplexTypePropertyType::class))->andReturnNull()->once(); |
759
|
|
|
$name = 'name'; |
760
|
|
|
$type = 'type'; |
761
|
|
|
$defaultValue = true; |
762
|
|
|
$summary = null; |
763
|
|
|
$longDescription = new TTextType(); |
764
|
|
|
$expectedDefault = 'true'; |
765
|
|
|
|
766
|
|
|
$result = $metadataManager->addPropertyToComplexType( |
767
|
|
|
$complex, |
768
|
|
|
$name, |
769
|
|
|
$type, |
770
|
|
|
$defaultValue, |
771
|
|
|
false, |
772
|
|
|
$summary, |
773
|
|
|
$longDescription |
774
|
|
|
); |
775
|
|
|
$this->assertEquals(0, count($result->getDocumentation())); |
776
|
|
|
$this->assertEquals($expectedDefault, $result->getDefaultValue()); |
777
|
|
|
} |
778
|
|
|
|
779
|
|
View Code Duplication |
public function testAddPropertyToEntityType() |
780
|
|
|
{ |
781
|
|
|
$metadataManager = new MetadataManager(); |
782
|
|
|
$entity = m::mock(TEntityTypeType::class); |
783
|
|
|
$entity->shouldReceive('addToProperty') |
784
|
|
|
->with(m::type(TEntityPropertyType::class))->andReturnNull()->once(); |
785
|
|
|
$name = 'name'; |
786
|
|
|
$type = 'type'; |
787
|
|
|
$summary = new TTextType(); |
788
|
|
|
$defaultValue = 'true'; |
789
|
|
|
$longDescription = new TTextType(); |
790
|
|
|
|
791
|
|
|
$result = $metadataManager->addPropertyToEntityType( |
792
|
|
|
$entity, |
793
|
|
|
$name, |
794
|
|
|
$type, |
795
|
|
|
$defaultValue, |
796
|
|
|
false, |
797
|
|
|
false, |
798
|
|
|
null, |
799
|
|
|
$summary, |
800
|
|
|
$longDescription |
801
|
|
|
); |
802
|
|
|
$this->assertNotNull($result); |
803
|
|
|
$this->assertTrue(is_array($result->getDocumentation())); |
804
|
|
|
$this->assertEquals(1, count($result->getDocumentation())); |
805
|
|
|
$this->assertEquals('true', $result->getDefaultValue()); |
806
|
|
|
} |
807
|
|
|
|
808
|
|
View Code Duplication |
public function testAddPropertyToEntityTypeOnlySummary() |
809
|
|
|
{ |
810
|
|
|
$metadataManager = new MetadataManager(); |
811
|
|
|
$entity = m::mock(TEntityTypeType::class); |
812
|
|
|
$entity->shouldReceive('addToProperty') |
813
|
|
|
->with(m::type(TEntityPropertyType::class))->andReturnNull()->once(); |
814
|
|
|
$name = 'name'; |
815
|
|
|
$type = 'type'; |
816
|
|
|
$summary = new TTextType(); |
817
|
|
|
$defaultValue = 'true'; |
818
|
|
|
$longDescription = null; |
819
|
|
|
|
820
|
|
|
$result = $metadataManager->addPropertyToEntityType( |
821
|
|
|
$entity, |
822
|
|
|
$name, |
823
|
|
|
$type, |
824
|
|
|
$defaultValue, |
825
|
|
|
false, |
826
|
|
|
false, |
827
|
|
|
null, |
828
|
|
|
$summary, |
829
|
|
|
$longDescription |
830
|
|
|
); |
831
|
|
|
$this->assertNotNull($result); |
832
|
|
|
$this->assertTrue(is_array($result->getDocumentation())); |
833
|
|
|
$this->assertEquals(0, count($result->getDocumentation())); |
834
|
|
|
$this->assertEquals('true', $result->getDefaultValue()); |
835
|
|
|
} |
836
|
|
|
|
837
|
|
View Code Duplication |
public function testAddPropertyToEntityTypeOnlyDescription() |
838
|
|
|
{ |
839
|
|
|
$metadataManager = new MetadataManager(); |
840
|
|
|
$entity = m::mock(TEntityTypeType::class); |
841
|
|
|
$entity->shouldReceive('addToProperty') |
842
|
|
|
->with(m::type(TEntityPropertyType::class))->andReturnNull()->once(); |
843
|
|
|
$name = 'name'; |
844
|
|
|
$type = 'type'; |
845
|
|
|
$summary = null; |
846
|
|
|
$defaultValue = 'true'; |
847
|
|
|
$longDescription = new TTextType(); |
848
|
|
|
|
849
|
|
|
$result = $metadataManager->addPropertyToEntityType( |
850
|
|
|
$entity, |
851
|
|
|
$name, |
852
|
|
|
$type, |
853
|
|
|
$defaultValue, |
854
|
|
|
false, |
855
|
|
|
false, |
856
|
|
|
null, |
857
|
|
|
$summary, |
858
|
|
|
$longDescription |
859
|
|
|
); |
860
|
|
|
$this->assertNotNull($result); |
861
|
|
|
$this->assertTrue(is_array($result->getDocumentation())); |
862
|
|
|
$this->assertEquals(0, count($result->getDocumentation())); |
863
|
|
|
$this->assertEquals('true', $result->getDefaultValue()); |
864
|
|
|
} |
865
|
|
|
|
866
|
|
View Code Duplication |
public function testAddEntityTypeWithDocumentation() |
867
|
|
|
{ |
868
|
|
|
$name = 'name'; |
869
|
|
|
$accessType = 'Public'; |
870
|
|
|
$summary = new TTextType(); |
871
|
|
|
$longDescription = new TTextType(); |
872
|
|
|
|
873
|
|
|
$metadataManager = new MetadataManager(); |
874
|
|
|
list($result, ) = $metadataManager->addEntityType($name, null, false, $accessType, $summary, $longDescription); |
875
|
|
|
$this->assertNotNull($result->getDocumentation()); |
876
|
|
|
} |
877
|
|
|
|
878
|
|
View Code Duplication |
public function testAddEntityTypeWithDocumentationFromOnlySummary() |
879
|
|
|
{ |
880
|
|
|
$name = 'name'; |
881
|
|
|
$accessType = 'Public'; |
882
|
|
|
$summary = new TTextType(); |
883
|
|
|
$longDescription = null; |
884
|
|
|
|
885
|
|
|
$metadataManager = new MetadataManager(); |
886
|
|
|
list($result, ) = $metadataManager->addEntityType($name, null, false, $accessType, $summary, $longDescription); |
887
|
|
|
$this->assertNull($result->getDocumentation()); |
888
|
|
|
} |
889
|
|
|
|
890
|
|
View Code Duplication |
public function testAddEntityTypeWithDocumentationFromOnlyDocumentation() |
891
|
|
|
{ |
892
|
|
|
$name = 'name'; |
893
|
|
|
$accessType = 'Public'; |
894
|
|
|
$summary = null; |
895
|
|
|
$longDescription = new TTextType(); |
896
|
|
|
|
897
|
|
|
$metadataManager = new MetadataManager(); |
898
|
|
|
list($result, ) = $metadataManager->addEntityType($name, null, false, $accessType, $summary, $longDescription); |
899
|
|
|
$this->assertNull($result->getDocumentation()); |
900
|
|
|
} |
901
|
|
|
|
902
|
|
View Code Duplication |
public function testAddNavigationPropertyToEntityTypeWithDocumentation() |
903
|
|
|
{ |
904
|
|
|
list(, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests(); |
|
|
|
|
905
|
|
|
|
906
|
|
|
$summary = new TTextType(); |
907
|
|
|
$longDescription = new TTextType(); |
908
|
|
|
$mult = '*'; |
909
|
|
|
$principalProperty = 'Categories'; |
910
|
|
|
$dependentProperty = 'Customers'; |
911
|
|
|
|
912
|
|
|
list($principal, $dependent) = $metadataManager |
913
|
|
|
->addNavigationPropertyToEntityType( |
914
|
|
|
$CategoryType, |
|
|
|
|
915
|
|
|
$mult, |
916
|
|
|
$principalProperty, |
917
|
|
|
$CustomerType, |
|
|
|
|
918
|
|
|
$mult, |
919
|
|
|
$dependentProperty, |
920
|
|
|
null, |
921
|
|
|
null, |
922
|
|
|
'Public', |
923
|
|
|
'Public', |
924
|
|
|
'Public', |
925
|
|
|
'Public', |
926
|
|
|
$summary, |
927
|
|
|
$longDescription, |
928
|
|
|
$summary, |
929
|
|
|
$longDescription |
930
|
|
|
); |
931
|
|
|
|
932
|
|
|
$this->assertNotNull($principal->getDocumentation()); |
933
|
|
|
$this->assertNotNull($dependent->getDocumentation()); |
934
|
|
|
} |
935
|
|
|
|
936
|
|
View Code Duplication |
public function testAddNavigationPropertyToEntityTypeWithDocumentationWithOnlySummary() |
937
|
|
|
{ |
938
|
|
|
list(, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests(); |
|
|
|
|
939
|
|
|
|
940
|
|
|
$summary = null; |
941
|
|
|
$longDescription = new TTextType(); |
942
|
|
|
$mult = '*'; |
943
|
|
|
$principalProperty = 'Categories'; |
944
|
|
|
$dependentProperty = 'Customers'; |
945
|
|
|
|
946
|
|
|
list($principal, $dependent) = $metadataManager |
947
|
|
|
->addNavigationPropertyToEntityType( |
948
|
|
|
$CategoryType, |
|
|
|
|
949
|
|
|
$mult, |
950
|
|
|
$principalProperty, |
951
|
|
|
$CustomerType, |
|
|
|
|
952
|
|
|
$mult, |
953
|
|
|
$dependentProperty, |
954
|
|
|
null, |
955
|
|
|
null, |
956
|
|
|
'Public', |
957
|
|
|
'Public', |
958
|
|
|
'Public', |
959
|
|
|
'Public', |
960
|
|
|
$summary, |
961
|
|
|
$longDescription, |
962
|
|
|
$summary, |
963
|
|
|
$longDescription |
964
|
|
|
); |
965
|
|
|
|
966
|
|
|
$this->assertNull($principal->getDocumentation()); |
967
|
|
|
$this->assertNull($dependent->getDocumentation()); |
968
|
|
|
} |
969
|
|
|
|
970
|
|
View Code Duplication |
public function testAddNavigationPropertyToEntityTypeWithDocumentationWithOnlyDescription() |
971
|
|
|
{ |
972
|
|
|
list(, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests(); |
|
|
|
|
973
|
|
|
|
974
|
|
|
$summary = new TTextType(); |
975
|
|
|
$longDescription = null; |
976
|
|
|
$mult = '*'; |
977
|
|
|
$principalProperty = 'Categories'; |
978
|
|
|
$dependentProperty = 'Customers'; |
979
|
|
|
|
980
|
|
|
list($principal, $dependent) = $metadataManager |
981
|
|
|
->addNavigationPropertyToEntityType( |
982
|
|
|
$CategoryType, |
|
|
|
|
983
|
|
|
$mult, |
984
|
|
|
$principalProperty, |
985
|
|
|
$CustomerType, |
|
|
|
|
986
|
|
|
$mult, |
987
|
|
|
$dependentProperty, |
988
|
|
|
null, |
989
|
|
|
null, |
990
|
|
|
'Public', |
991
|
|
|
'Public', |
992
|
|
|
'Public', |
993
|
|
|
'Public', |
994
|
|
|
$summary, |
995
|
|
|
$longDescription, |
996
|
|
|
$summary, |
997
|
|
|
$longDescription |
998
|
|
|
); |
999
|
|
|
|
1000
|
|
|
$this->assertNull($principal->getDocumentation()); |
1001
|
|
|
$this->assertNull($dependent->getDocumentation()); |
1002
|
|
|
} |
1003
|
|
|
|
1004
|
|
|
public function testCreateAssociationFromNavigationPropertyRelationMismatch() |
1005
|
|
|
{ |
1006
|
|
|
$principalType = m::mock(TEntityTypeType::class); |
1007
|
|
|
$dependentType = m::mock(TEntityTypeType::class); |
1008
|
|
|
$principalNav = m::mock(TNavigationPropertyType::class); |
1009
|
|
|
$principalNav->shouldReceive('getRelationship')->andReturn('foo')->once(); |
1010
|
|
|
$dependentNav = m::mock(TNavigationPropertyType::class); |
1011
|
|
|
$dependentNav->shouldReceive('getRelationship')->andReturn('bar')->once(); |
1012
|
|
|
|
1013
|
|
|
$metadataManager = new MetadataManagerDummy(); |
1014
|
|
|
|
1015
|
|
|
$expected = 'If you have both a dependent property and a principal property, relationship should match'; |
1016
|
|
|
$actual = null; |
1017
|
|
|
|
1018
|
|
|
try { |
1019
|
|
|
$metadataManager->createAssocationFromNavigationProperty( |
1020
|
|
|
$principalType, |
1021
|
|
|
$dependentType, |
1022
|
|
|
$principalNav, |
1023
|
|
|
$dependentNav, |
1024
|
|
|
'*', |
1025
|
|
|
'*' |
1026
|
|
|
); |
1027
|
|
|
} catch (\InvalidArgumentException $e) { |
1028
|
|
|
$actual = $e->getMessage(); |
1029
|
|
|
} |
1030
|
|
|
$this->assertEquals($expected, $actual); |
1031
|
|
|
} |
1032
|
|
|
|
1033
|
|
View Code Duplication |
public function testCreateAssociationFromNavigationPropertyForwardRoleMismatch() |
1034
|
|
|
{ |
1035
|
|
|
$principalType = m::mock(TEntityTypeType::class); |
1036
|
|
|
$dependentType = m::mock(TEntityTypeType::class); |
1037
|
|
|
$principalNav = m::mock(TNavigationPropertyType::class); |
1038
|
|
|
$principalNav->shouldReceive('getRelationship')->andReturn('foo')->once(); |
|
|
|
|
1039
|
|
|
$principalNav->shouldReceive('getToRole')->andReturn('Forwards'); |
1040
|
|
|
$principalNav->shouldReceive('getFromRole')->andReturn('Reverse'); |
1041
|
|
|
$dependentNav = m::mock(TNavigationPropertyType::class); |
1042
|
|
|
$dependentNav->shouldReceive('getRelationship')->andReturn('foo')->once(); |
1043
|
|
|
$dependentNav->shouldReceive('getToRole')->andReturn('Reverse'); |
1044
|
|
|
$dependentNav->shouldReceive('getFromRole')->andReturn('Sideways'); |
1045
|
|
|
|
1046
|
|
|
$metadataManager = new MetadataManagerDummy(); |
1047
|
|
|
|
1048
|
|
|
$expected = 'Principal to role should match dependent from role, and vice versa'; |
1049
|
|
|
$actual = null; |
1050
|
|
|
|
1051
|
|
|
try { |
1052
|
|
|
$metadataManager->createAssocationFromNavigationProperty( |
1053
|
|
|
$principalType, |
1054
|
|
|
$dependentType, |
1055
|
|
|
$principalNav, |
1056
|
|
|
$dependentNav, |
1057
|
|
|
'*', |
1058
|
|
|
'*' |
1059
|
|
|
); |
1060
|
|
|
} catch (\InvalidArgumentException $e) { |
1061
|
|
|
$actual = $e->getMessage(); |
1062
|
|
|
} |
1063
|
|
|
$this->assertEquals($expected, $actual); |
1064
|
|
|
} |
1065
|
|
|
|
1066
|
|
View Code Duplication |
public function testCreateAssociationFromNavigationPropertyReverseRoleMismatch() |
1067
|
|
|
{ |
1068
|
|
|
$principalType = m::mock(TEntityTypeType::class); |
1069
|
|
|
$dependentType = m::mock(TEntityTypeType::class); |
1070
|
|
|
$principalNav = m::mock(TNavigationPropertyType::class); |
1071
|
|
|
$principalNav->shouldReceive('getRelationship')->andReturn('foo')->once(); |
|
|
|
|
1072
|
|
|
$principalNav->shouldReceive('getToRole')->andReturn('Forwards'); |
1073
|
|
|
$principalNav->shouldReceive('getFromRole')->andReturn('Reverse'); |
1074
|
|
|
$dependentNav = m::mock(TNavigationPropertyType::class); |
1075
|
|
|
$dependentNav->shouldReceive('getRelationship')->andReturn('foo')->once(); |
1076
|
|
|
$dependentNav->shouldReceive('getToRole')->andReturn('Sideways'); |
1077
|
|
|
$dependentNav->shouldReceive('getFromRole')->andReturn('Forwards'); |
1078
|
|
|
|
1079
|
|
|
$metadataManager = new MetadataManagerDummy(); |
1080
|
|
|
|
1081
|
|
|
$expected = 'Principal to role should match dependent from role, and vice versa'; |
1082
|
|
|
$actual = null; |
1083
|
|
|
|
1084
|
|
|
try { |
1085
|
|
|
$metadataManager->createAssocationFromNavigationProperty( |
1086
|
|
|
$principalType, |
1087
|
|
|
$dependentType, |
1088
|
|
|
$principalNav, |
1089
|
|
|
$dependentNav, |
1090
|
|
|
'*', |
1091
|
|
|
'*' |
1092
|
|
|
); |
1093
|
|
|
} catch (\InvalidArgumentException $e) { |
1094
|
|
|
$actual = $e->getMessage(); |
1095
|
|
|
} |
1096
|
|
|
$this->assertEquals($expected, $actual); |
1097
|
|
|
} |
1098
|
|
|
|
1099
|
|
|
/** |
1100
|
|
|
* @return array |
1101
|
|
|
*/ |
1102
|
|
|
private function setUpMetadataForNavTests() |
1103
|
|
|
{ |
1104
|
|
|
$msg = null; |
1105
|
|
|
$metadataManager = new MetadataManager('Data', 'Container'); |
1106
|
|
|
$expectedCategorySetName = 'Categories'; |
|
|
|
|
1107
|
|
|
$expectedCustomerSetName = 'Customers'; |
|
|
|
|
1108
|
|
|
|
1109
|
|
|
list($CategoryType, $CategorySet) = $metadataManager->addEntityType('Category'); |
|
|
|
|
1110
|
|
|
list($CustomerType, $CustomerSet) = $metadataManager->addEntityType('Customer'); |
|
|
|
|
1111
|
|
|
$this->assertTrue($CategoryType->isOK($msg), $msg); |
|
|
|
|
1112
|
|
|
$this->assertTrue($CustomerType->isOK($msg), $msg); |
|
|
|
|
1113
|
|
|
$this->assertEquals($expectedCategorySetName, $CategorySet->getName()); |
|
|
|
|
1114
|
|
|
$this->assertEquals($expectedCustomerSetName, $CustomerSet->getName()); |
|
|
|
|
1115
|
|
|
return [$msg, $metadataManager, $CategoryType, $CustomerType]; |
|
|
|
|
1116
|
|
|
} |
1117
|
|
|
|
1118
|
|
|
/** |
1119
|
|
|
* @param $navProps |
1120
|
|
|
* @param $ends |
1121
|
|
|
*/ |
1122
|
|
|
private function checkNavProps($navProps, $ends) |
1123
|
|
|
{ |
1124
|
|
|
foreach ($navProps as $prop) { |
1125
|
|
|
$propToRole = $prop->getToRole(); |
1126
|
|
|
$propFromRole = $prop->getFromRole(); |
1127
|
|
|
$fromMatch = $ends[0]->getRole() == $propToRole |
1128
|
|
|
|| $ends[1]->getRole() == $propToRole; |
1129
|
|
|
$this->assertTrue($fromMatch, 'toRole must match at least one end role'); |
1130
|
|
|
if ($ends[0]->getRole() == $propToRole) { |
1131
|
|
|
$this->assertEquals($ends[1]->getRole(), $propFromRole); |
1132
|
|
|
$this->assertNotEquals($ends[0]->getRole(), $propFromRole); |
1133
|
|
|
} else { |
1134
|
|
|
$this->assertEquals($ends[0]->getRole(), $propFromRole); |
1135
|
|
|
$this->assertNotEquals($ends[1]->getRole(), $propFromRole); |
1136
|
|
|
} |
1137
|
|
|
} |
1138
|
|
|
} |
1139
|
|
|
|
1140
|
|
|
/** |
1141
|
|
|
* @param $ends |
1142
|
|
|
* @param $principal |
1143
|
|
|
* @param $dependent |
1144
|
|
|
* @return array |
1145
|
|
|
*/ |
1146
|
|
|
private function figureOutEnds($ends, $principal, $dependent) |
1147
|
|
|
{ |
1148
|
|
|
// if role is from Products, then type must be from Products - ie, use getFromRole |
1149
|
|
|
$principalEnd = ($ends[0]->getRole() == $principal->getFromRole()) ? $ends[0] : $ends[1]; |
1150
|
|
|
$dependentEnd = ($ends[0]->getRole() == $dependent->getFromRole()) ? $ends[0] : $ends[1]; |
1151
|
|
|
return [$principalEnd, $dependentEnd]; |
1152
|
|
|
} |
1153
|
|
|
} |
1154
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.