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