Passed
Push — master ( 59e1a5...f37dc8 )
by Christopher
05:53
created

MetadataManagerTest::testAddPropertyToComplexTypeDefaultValueBooleanOnlySummary()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 22

Duplication

Lines 26
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 26
loc 26
rs 8.8571
cc 1
eloc 22
nc 1
nop 0
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
    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_custom_Customer_categor';
192
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
193
            $CategoryType,
194
            '*',
195
            'custom',
196
            $CustomerType,
197
            '*',
198
            'categor'
199
        );
200
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
201
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
202
        $this->assertEquals('custom', $principal->getName());
203
        $this->assertEquals('categor', $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
        $this->checkNavProps($navProps, $ends);
219
        list($principalEnd, $dependentEnd) = $this->figureOutEnds($ends, $principal, $dependent);
220
        $this->assertEquals('*', $principalEnd->getMultiplicity());
221
        $this->assertEquals('*', $dependentEnd->getMultiplicity());
222
    }
223
224
    public function testAddOneToManyNavProperty()
225
    {
226
        list($msg, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
227
228
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
229
            $CategoryType,
230
            '*',
231
            'custom',
232
            $CustomerType,
233
            '1',
234
            'categor'
235
        );
236
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
237
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
238
        $this->assertEquals('custom', $principal->getName());
239
        $this->assertEquals('categor', $dependent->getName());
240
241
        $navProps = [$principal, $dependent];
242
        $assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation();
243
        $this->assertEquals(1, count($assoc));
244
        $assoc = $assoc[0];
245
        $this->assertTrue($assoc instanceof TAssociationType);
246
        $this->assertTrue($assoc->isOK($msg), $msg);
247
248
        $this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship());
249
        $ends = $assoc->getEnd();
250
251
        $this->assertEquals(2, count($ends));
252
        $this->checkNavProps($navProps, $ends);
253
        list($principalEnd, $dependentEnd) = $this->figureOutEnds($ends, $principal, $dependent);
254
        $this->assertEquals('*', $principalEnd->getMultiplicity());
255
        $this->assertEquals('1', $dependentEnd->getMultiplicity());
256
    }
257
258
    public function testAddManyToOneNavProperty()
259
    {
260
        list($msg, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
261
262
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
263
            $CategoryType,
264
            '1',
265
            'custom',
266
            $CustomerType,
267
            '*',
268
            'categor'
269
        );
270
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
271
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
272
        $this->assertEquals('custom', $principal->getName());
273
        $this->assertEquals('categor', $dependent->getName());
274
275
        $navProps = [$principal, $dependent];
276
        $assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation();
277
        $this->assertEquals(1, count($assoc));
278
        $assoc = $assoc[0];
279
        $this->assertTrue($assoc instanceof TAssociationType);
280
        $this->assertTrue($assoc->isOK($msg), $msg);
281
282
        $this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship());
283
        $ends = $assoc->getEnd();
284
285
        $this->assertEquals(2, count($ends));
286
        $this->checkNavProps($navProps, $ends);
287
        list($principalEnd, $dependentEnd) = $this->figureOutEnds($ends, $principal, $dependent);
288
        $this->assertEquals('1', $principalEnd->getMultiplicity());
289
        $this->assertEquals('*', $dependentEnd->getMultiplicity());
290
    }
291
292
    public function testAddOneToOneForwardNavProperty()
293
    {
294
        list($msg, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
295
296
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
297
            $CategoryType,
298
            '0..1',
299
            'custom',
300
            $CustomerType,
301
            '1',
302
            'categor'
303
        );
304
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
305
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
306
        $this->assertEquals('custom', $principal->getName());
307
        $this->assertEquals('categor', $dependent->getName());
308
309
        $navProps = [$principal, $dependent];
310
        $assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation();
311
        $this->assertEquals(1, count($assoc));
312
        $assoc = $assoc[0];
313
        $this->assertTrue($assoc instanceof TAssociationType);
314
        $this->assertTrue($assoc->isOK($msg), $msg);
315
316
        $this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship());
317
        $ends = $assoc->getEnd();
318
319
        $this->assertEquals(2, count($ends));
320
        $this->checkNavProps($navProps, $ends);
321
        list($principalEnd, $dependentEnd) = $this->figureOutEnds($ends, $principal, $dependent);
322
        $this->assertEquals('0..1', $principalEnd->getMultiplicity());
323
        $this->assertEquals('1', $dependentEnd->getMultiplicity());
324
    }
325
326
    public function testAddOneToOneReverseNavProperty()
327
    {
328
        list($msg, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
329
330
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
331
            $CategoryType,
332
            '1',
333
            'custom',
334
            $CustomerType,
335
            '0..1',
336
            'categor'
337
        );
338
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
339
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
340
        $this->assertEquals('custom', $principal->getName());
341
        $this->assertEquals('categor', $dependent->getName());
342
343
        $navProps = [$principal, $dependent];
344
        $assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation();
345
        $this->assertEquals(1, count($assoc));
346
        $assoc = $assoc[0];
347
        $this->assertTrue($assoc instanceof TAssociationType);
348
        $this->assertTrue($assoc->isOK($msg), $msg);
349
350
        $this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship());
351
        $ends = $assoc->getEnd();
352
353
        $this->assertEquals(2, count($ends));
354
        $this->checkNavProps($navProps, $ends);
355
        list($principalEnd, $dependentEnd) = $this->figureOutEnds($ends, $principal, $dependent);
356
        $this->assertEquals('1', $principalEnd->getMultiplicity());
357
        $this->assertEquals('0..1', $dependentEnd->getMultiplicity());
358
    }
359
360
    public function testMetadataSerialiseRoundTrip()
361
    {
362
        $bar = new MetadataManager();
363
        $foo = new MetadataManager();
364
365
        $cereal = serialize($foo);
366
367
        $foo = unserialize($cereal);
368
        $this->assertTrue(null != $foo->getSerialiser());
369
        $this->assertEquals($bar, $foo);
370
    }
371
372
    public function testCreateSingletonBadReturnType()
373
    {
374
        $returnType = m::mock(IsOK::class);
375
        $foo = new MetadataManager();
376
377
        $expected = 'Expected return type must be either TEntityType or TComplexType';
378
        $actual = null;
379
380
        try {
381
            $foo->createSingleton(null, $returnType);
382
        } catch (\InvalidArgumentException $e) {
383
            $actual = $e->getMessage();
384
        }
385
        $this->assertEquals($expected, $actual);
386
    }
387
388
    public function testCreateSingletonEmptyName()
389
    {
390
        $returnType = m::mock(TEntityTypeType::class);
391
        $this->assertTrue($returnType instanceof TEntityTypeType, get_class($returnType));
392
        $foo = new MetadataManager();
393
394
        $expected = 'Name must be a non-empty string';
395
        $actual = null;
396
397
        try {
398
            $foo->createSingleton(null, $returnType);
399
        } catch (\InvalidArgumentException $e) {
400
            $actual = $e->getMessage();
401
        }
402
        $this->assertEquals($expected, $actual);
403
    }
404
405
    public function testCreateSingletonNonStringName()
406
    {
407
        $returnType = m::mock(TEntityTypeType::class);
408
        $this->assertTrue($returnType instanceof TEntityTypeType, get_class($returnType));
409
        $foo = new MetadataManager();
410
411
        $expected = 'Name must be a non-empty string';
412
        $actual = null;
413
414
        try {
415
            $foo->createSingleton($returnType, $returnType);
416
        } catch (\InvalidArgumentException $e) {
417
            $actual = $e->getMessage();
418
        }
419
        $this->assertEquals($expected, $actual);
420
    }
421
422
    public function testCreateSingletonSuccessful()
423
    {
424
        $msg = null;
425
        $name = 'singleton';
426
        $returnType = m::mock(TEntityTypeType::class)->makePartial();
427
        $returnType->shouldReceive('getName')->andReturn('doubleton');
428
429
        $entityContainer = m::mock(EntityContainer::class)->makePartial();
430
        $entityContainer->shouldReceive('addToFunctionImport')->andReturn(null)->once();
431
432
        $schema = m::mock(Schema::class)->makePartial();
433
        $schema->shouldReceive('getEntityContainer')->andReturn([$entityContainer])->once();
434
        $edmx = m::mock(Edmx::class)->makePartial();
435
        $edmx->shouldReceive('getDataServiceType->getSchema')->andReturn([$schema])->once();
436
437
        $foo = m::mock(MetadataManager::class)->makePartial();
438
        $foo->shouldReceive('getEdmx')->andReturn($edmx);
439
440
        $result = $foo->createSingleton($name, $returnType);
441
        $this->assertTrue($result instanceof EntityContainer\FunctionImportAnonymousType, get_class($result));
442
        $this->assertTrue($result->isOK($msg));
443
        $this->assertNull($result->getDocumentation());
444
    }
445
446
    public function testCreateSingletonWithDocumentation()
447
    {
448
        $msg = null;
449
        $name = 'singleton';
450
        $shortDesc = new TTextType();
451
        $longDesc = new TTextType();
452
453
        $returnType = m::mock(TEntityTypeType::class)->makePartial();
454
        $returnType->shouldReceive('getName')->andReturn('doubleton');
455
456
        $entityContainer = m::mock(EntityContainer::class)->makePartial();
457
        $entityContainer->shouldReceive('addToFunctionImport')->andReturn(null)->once();
458
459
        $schema = m::mock(Schema::class)->makePartial();
460
        $schema->shouldReceive('getEntityContainer')->andReturn([$entityContainer])->once();
461
        $edmx = m::mock(Edmx::class)->makePartial();
462
        $edmx->shouldReceive('getDataServiceType->getSchema')->andReturn([$schema])->once();
463
464
        $foo = m::mock(MetadataManager::class)->makePartial();
465
        $foo->shouldReceive('getEdmx')->andReturn($edmx);
466
467
        $result = $foo->createSingleton($name, $returnType, $shortDesc, $longDesc);
468
        $this->assertTrue($result instanceof EntityContainer\FunctionImportAnonymousType, get_class($result));
469
        $this->assertTrue($result->isOK($msg));
470
        $this->assertNotNull($result->getDocumentation());
471
    }
472
473
    public function testCreateSingletonWithDocumentationOnlyShortDesc()
474
    {
475
        $msg = null;
476
        $name = 'singleton';
477
        $shortDesc = new TTextType();
478
        $longDesc = null;
479
480
        $returnType = m::mock(TEntityTypeType::class)->makePartial();
481
        $returnType->shouldReceive('getName')->andReturn('doubleton');
482
483
        $entityContainer = m::mock(EntityContainer::class)->makePartial();
484
        $entityContainer->shouldReceive('addToFunctionImport')->andReturn(null)->once();
485
486
        $schema = m::mock(Schema::class)->makePartial();
487
        $schema->shouldReceive('getEntityContainer')->andReturn([$entityContainer])->once();
488
        $edmx = m::mock(Edmx::class)->makePartial();
489
        $edmx->shouldReceive('getDataServiceType->getSchema')->andReturn([$schema])->once();
490
491
        $foo = m::mock(MetadataManager::class)->makePartial();
492
        $foo->shouldReceive('getEdmx')->andReturn($edmx);
493
494
        $result = $foo->createSingleton($name, $returnType, $shortDesc, $longDesc);
495
        $this->assertTrue($result instanceof EntityContainer\FunctionImportAnonymousType, get_class($result));
496
        $this->assertTrue($result->isOK($msg));
497
        $this->assertNull($result->getDocumentation());
498
    }
499
500
    public function testCreateSingletonWithDocumentationOnlyLongDesc()
501
    {
502
        $msg = null;
503
        $name = 'singleton';
504
        $shortDesc = null;
505
        $longDesc = new TTextType();
506
507
        $returnType = m::mock(TEntityTypeType::class)->makePartial();
508
        $returnType->shouldReceive('getName')->andReturn('doubleton');
509
510
        $entityContainer = m::mock(EntityContainer::class)->makePartial();
511
        $entityContainer->shouldReceive('addToFunctionImport')->andReturn(null)->once();
512
513
        $schema = m::mock(Schema::class)->makePartial();
514
        $schema->shouldReceive('getEntityContainer')->andReturn([$entityContainer])->once();
515
        $edmx = m::mock(Edmx::class)->makePartial();
516
        $edmx->shouldReceive('getDataServiceType->getSchema')->andReturn([$schema])->once();
517
518
        $foo = m::mock(MetadataManager::class)->makePartial();
519
        $foo->shouldReceive('getEdmx')->andReturn($edmx);
520
521
        $result = $foo->createSingleton($name, $returnType, $shortDesc, $longDesc);
522
        $this->assertTrue($result instanceof EntityContainer\FunctionImportAnonymousType, get_class($result));
523
        $this->assertTrue($result->isOK($msg));
524
        $this->assertNull($result->getDocumentation());
525
    }
526
527
    public function testMalformedMultiplicity()
528
    {
529
        list(, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
530
531
        $expected = 'Malformed multiplicity - valid values are *, 0..1 and 1';
532
        $actual = null;
533
534
        try {
535
            $metadataManager->addNavigationPropertyToEntityType(
536
                $CategoryType,
537
                '1',
538
                'Customers',
539
                $CustomerType,
540
                'ABC',
541
                'Categories'
542
            );
543
        } catch (\InvalidArgumentException $e) {
544
            $actual = $e->getMessage();
545
        }
546
        $this->assertEquals($expected, $actual);
547
    }
548
549
    public function testInvalidMultiplicityBelongsOnBothEnds()
550
    {
551
        list(, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
552
553
        $expected =  'Invalid multiplicity combination - 1 1';
554
        $actual = null;
555
556
        try {
557
            $metadataManager->addNavigationPropertyToEntityType(
558
                $CategoryType,
559
                '1',
560
                'Customers',
561
                $CustomerType,
562
                '1',
563
                'Categories'
564
            );
565
        } catch (\InvalidArgumentException $e) {
566
            $actual = $e->getMessage();
567
        }
568
        $this->assertEquals($expected, $actual);
569
    }
570
571
    public function testInvalidMultiplicityManyToHasMany()
572
    {
573
        list(, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
574
575
        $expected =  'Invalid multiplicity combination - * 0..1';
576
        $actual = null;
577
578
        try {
579
            $metadataManager->addNavigationPropertyToEntityType(
580
                $CategoryType,
581
                '*',
582
                'Customers',
583
                $CustomerType,
584
                '0..1',
585
                'Categories'
586
            );
587
        } catch (\InvalidArgumentException $e) {
588
            $actual = $e->getMessage();
589
        }
590
        $this->assertEquals($expected, $actual);
591
    }
592
593
    public function testAddComplexType()
594
    {
595
        list(, $metadataManager, , ) = $this->setUpMetadataForNavTests();
596
597
        $name = 'Name';
598
        $accessType = 'Public';
599
        $summary = new TTextType();
600
        $longDescription = new TTextType();
601
602
        $oldCount = count($metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getComplexType());
603
604
        $result = $metadataManager->addComplexType($name, $accessType, $summary, $longDescription);
605
606
        $newCount = count($metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getComplexType());
607
        $this->assertEquals($oldCount+1, $newCount);
608
        $this->assertNotNull($result);
609
        $this->assertTrue($result instanceof TComplexTypeType, get_class($result));
610
        $this->assertNotNull($result->getDocumentation());
611
    }
612
613
    public function testAddComplexTypeWithOnlySummary()
614
    {
615
        list(, $metadataManager, , ) = $this->setUpMetadataForNavTests();
616
617
        $name = 'Name';
618
        $accessType = 'Public';
619
        $summary = new TTextType();
620
        $longDescription = null;
621
622
        $oldCount = count($metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getComplexType());
623
624
        $result = $metadataManager->addComplexType($name, $accessType, $summary, $longDescription);
625
626
        $newCount = count($metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getComplexType());
627
        $this->assertEquals($oldCount+1, $newCount);
628
        $this->assertNotNull($result);
629
        $this->assertTrue($result instanceof TComplexTypeType, get_class($result));
630
        $this->assertNull($result->getDocumentation());
631
    }
632
633
    public function testAddComplexTypeWithOnlyDescription()
634
    {
635
        list(, $metadataManager, , ) = $this->setUpMetadataForNavTests();
636
637
        $name = 'Name';
638
        $accessType = 'Public';
639
        $summary = null;
640
        $longDescription = new TTextType();
641
642
        $oldCount = count($metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getComplexType());
643
644
        $result = $metadataManager->addComplexType($name, $accessType, $summary, $longDescription);
645
646
        $newCount = count($metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getComplexType());
647
        $this->assertEquals($oldCount+1, $newCount);
648
        $this->assertNotNull($result);
649
        $this->assertTrue($result instanceof TComplexTypeType, get_class($result));
650
        $this->assertNull($result->getDocumentation());
651
    }
652
653
    public function testAddPropertyToComplexTypeDefaultValueArray()
654
    {
655
        $expected = 'Default value cannot be object or array';
656
        $actual = null;
657
658
        list(, $metadataManager, , ) = $this->setUpMetadataForNavTests();
659
        $complex = m::mock(TComplexTypeType::class);
660
        $name = 'name';
661
        $type = 'type';
662
        $defaultValue = [];
663
664
        try {
665
            $metadataManager->addPropertyToComplexType($complex, $name, $type, $defaultValue);
666
        } catch (\InvalidArgumentException $e) {
667
            $actual = $e->getMessage();
668
        }
669
        $this->assertEquals($expected, $actual);
670
    }
671
672
    public function testAddPropertyToComplexTypeDefaultValueObject()
673
    {
674
        $expected = 'Default value cannot be object or array';
675
        $actual = null;
676
677
        list(, $metadataManager, , ) = $this->setUpMetadataForNavTests();
678
        $complex = m::mock(TComplexTypeType::class);
679
        $name = 'name';
680
        $type = 'type';
681
        $defaultValue = new \stdClass();
682
683
        try {
684
            $metadataManager->addPropertyToComplexType($complex, $name, $type, $defaultValue);
685
        } catch (\InvalidArgumentException $e) {
686
            $actual = $e->getMessage();
687
        }
688
        $this->assertEquals($expected, $actual);
689
    }
690
691
    public function testAddPropertyToComplexTypeDefaultValueBoolean()
692
    {
693
        list(, $metadataManager, , ) = $this->setUpMetadataForNavTests();
694
        $complex = m::mock(TComplexTypeType::class);
695
        $complex->shouldReceive('addToProperty')
696
            ->with(m::type(TComplexTypePropertyType::class))->andReturnNull()->once();
697
        $name = 'name';
698
        $type = 'type';
699
        $defaultValue = true;
700
        $summary = new TTextType();
701
        $longDescription = new TTextType();
702
        $expectedDefault = 'true';
703
704
        $result = $metadataManager->addPropertyToComplexType(
705
            $complex,
706
            $name,
707
            $type,
708
            $defaultValue,
709
            false,
710
            $summary,
711
            $longDescription
712
        );
713
        $this->assertEquals(1, count($result->getDocumentation()));
714
        $this->assertEquals($expectedDefault, $result->getDefaultValue());
715
    }
716
717
    public function testAddPropertyToComplexTypeDefaultValueBooleanOnlySummary()
718
    {
719
        list(, $metadataManager, , ) = $this->setUpMetadataForNavTests();
720
        $complex = m::mock(TComplexTypeType::class);
721
        $complex->shouldReceive('addToProperty')
722
            ->with(m::type(TComplexTypePropertyType::class))->andReturnNull()->once();
723
        $name = 'name';
724
        $type = 'type';
725
        $defaultValue = true;
726
        $summary = new TTextType();
727
        $longDescription = null;
728
        $expectedDefault = 'true';
729
730
        $result = $metadataManager->addPropertyToComplexType(
731
            $complex,
732
            $name,
733
            $type,
734
            $defaultValue,
735
            false,
736
            $summary,
737
            $longDescription
738
        );
739
        $this->assertNotNull($result);
740
        $this->assertEquals(0, count($result->getDocumentation()));
741
        $this->assertEquals($expectedDefault, $result->getDefaultValue());
742
    }
743
744
    public function testAddPropertyToComplexTypeDefaultValueBooleanOnlyDescription()
745
    {
746
        list(, $metadataManager, , ) = $this->setUpMetadataForNavTests();
747
        $complex = m::mock(TComplexTypeType::class);
748
        $complex->shouldReceive('addToProperty')
749
            ->with(m::type(TComplexTypePropertyType::class))->andReturnNull()->once();
750
        $name = 'name';
751
        $type = 'type';
752
        $defaultValue = true;
753
        $summary = null;
754
        $longDescription = new TTextType();
755
        $expectedDefault = 'true';
756
757
        $result = $metadataManager->addPropertyToComplexType(
758
            $complex,
759
            $name,
760
            $type,
761
            $defaultValue,
762
            false,
763
            $summary,
764
            $longDescription
765
        );
766
        $this->assertEquals(0, count($result->getDocumentation()));
767
        $this->assertEquals($expectedDefault, $result->getDefaultValue());
768
    }
769
770
    public function testAddPropertyToEntityType()
771
    {
772
        $metadataManager = new MetadataManager();
773
        $entity = m::mock(TEntityTypeType::class);
774
        $entity->shouldReceive('addToProperty')
775
            ->with(m::type(TEntityPropertyType::class))->andReturnNull()->once();
776
        $name = 'name';
777
        $type = 'type';
778
        $summary = new TTextType();
779
        $defaultValue = 'true';
780
        $longDescription = new TTextType();
781
782
        $result = $metadataManager->addPropertyToEntityType(
783
            $entity,
784
            $name,
785
            $type,
786
            $defaultValue,
787
            false,
788
            false,
789
            null,
790
            $summary,
791
            $longDescription
792
        );
793
        $this->assertNotNull($result);
794
        $this->assertTrue(is_array($result->getDocumentation()));
795
        $this->assertEquals(1, count($result->getDocumentation()));
796
        $this->assertEquals('true', $result->getDefaultValue());
797
    }
798
799
    public function testAddPropertyToEntityTypeOnlySummary()
800
    {
801
        $metadataManager = new MetadataManager();
802
        $entity = m::mock(TEntityTypeType::class);
803
        $entity->shouldReceive('addToProperty')
804
            ->with(m::type(TEntityPropertyType::class))->andReturnNull()->once();
805
        $name = 'name';
806
        $type = 'type';
807
        $summary = new TTextType();
808
        $defaultValue = 'true';
809
        $longDescription = null;
810
811
        $result = $metadataManager->addPropertyToEntityType(
812
            $entity,
813
            $name,
814
            $type,
815
            $defaultValue,
816
            false,
817
            false,
818
            null,
819
            $summary,
820
            $longDescription
821
        );
822
        $this->assertNotNull($result);
823
        $this->assertTrue(is_array($result->getDocumentation()));
824
        $this->assertEquals(0, count($result->getDocumentation()));
825
        $this->assertEquals('true', $result->getDefaultValue());
826
    }
827
828
    public function testAddPropertyToEntityTypeOnlyDescription()
829
    {
830
        $metadataManager = new MetadataManager();
831
        $entity = m::mock(TEntityTypeType::class);
832
        $entity->shouldReceive('addToProperty')
833
            ->with(m::type(TEntityPropertyType::class))->andReturnNull()->once();
834
        $name = 'name';
835
        $type = 'type';
836
        $summary = null;
837
        $defaultValue = 'true';
838
        $longDescription = new TTextType();
839
840
        $result = $metadataManager->addPropertyToEntityType(
841
            $entity,
842
            $name,
843
            $type,
844
            $defaultValue,
845
            false,
846
            false,
847
            null,
848
            $summary,
849
            $longDescription
850
        );
851
        $this->assertNotNull($result);
852
        $this->assertTrue(is_array($result->getDocumentation()));
853
        $this->assertEquals(0, count($result->getDocumentation()));
854
        $this->assertEquals('true', $result->getDefaultValue());
855
    }
856
857
    public function testAddEntityTypeWithDocumentation()
858
    {
859
        $name = 'name';
860
        $accessType = 'Public';
861
        $summary = new TTextType();
862
        $longDescription = new TTextType();
863
864
        $metadataManager = new MetadataManager();
865
        list($result, ) = $metadataManager->addEntityType($name, null, false, $accessType, $summary, $longDescription);
866
        $this->assertNotNull($result->getDocumentation());
867
    }
868
869
    public function testAddEntityTypeWithDocumentationFromOnlySummary()
870
    {
871
        $name = 'name';
872
        $accessType = 'Public';
873
        $summary = new TTextType();
874
        $longDescription = null;
875
876
        $metadataManager = new MetadataManager();
877
        list($result, ) = $metadataManager->addEntityType($name, null, false, $accessType, $summary, $longDescription);
878
        $this->assertNull($result->getDocumentation());
879
    }
880
881
    public function testAddEntityTypeWithDocumentationFromOnlyDocumentation()
882
    {
883
        $name = 'name';
884
        $accessType = 'Public';
885
        $summary = null;
886
        $longDescription = new TTextType();
887
888
        $metadataManager = new MetadataManager();
889
        list($result, ) = $metadataManager->addEntityType($name, null, false, $accessType, $summary, $longDescription);
890
        $this->assertNull($result->getDocumentation());
891
    }
892
893
    public function testAddNavigationPropertyToEntityTypeWithDocumentation()
894
    {
895
        list(, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
896
897
        $summary = new TTextType();
898
        $longDescription = new TTextType();
899
        $mult = '*';
900
        $principalProperty = 'Categories';
901
        $dependentProperty = 'Customers';
902
903
        list($principal, $dependent) = $metadataManager
904
            ->addNavigationPropertyToEntityType(
905
                $CategoryType,
906
                $mult,
907
                $principalProperty,
908
                $CustomerType,
909
                $mult,
910
                $dependentProperty,
911
                null,
912
                null,
913
                'Public',
914
                'Public',
915
                'Public',
916
                'Public',
917
                $summary,
918
                $longDescription,
919
                $summary,
920
                $longDescription
921
            );
922
923
        $this->assertNotNull($principal->getDocumentation());
924
        $this->assertNotNull($dependent->getDocumentation());
925
    }
926
927
    public function testAddNavigationPropertyToEntityTypeWithDocumentationWithOnlySummary()
928
    {
929
        list(, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
930
931
        $summary = null;
932
        $longDescription = new TTextType();
933
        $mult = '*';
934
        $principalProperty = 'Categories';
935
        $dependentProperty = 'Customers';
936
937
        list($principal, $dependent) = $metadataManager
938
            ->addNavigationPropertyToEntityType(
939
                $CategoryType,
940
                $mult,
941
                $principalProperty,
942
                $CustomerType,
943
                $mult,
944
                $dependentProperty,
945
                null,
946
                null,
947
                'Public',
948
                'Public',
949
                'Public',
950
                'Public',
951
                $summary,
952
                $longDescription,
953
                $summary,
954
                $longDescription
955
            );
956
957
        $this->assertNull($principal->getDocumentation());
958
        $this->assertNull($dependent->getDocumentation());
959
    }
960
961
    public function testAddNavigationPropertyToEntityTypeWithDocumentationWithOnlyDescription()
962
    {
963
        list(, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
964
965
        $summary = new TTextType();
966
        $longDescription = null;
967
        $mult = '*';
968
        $principalProperty = 'Categories';
969
        $dependentProperty = 'Customers';
970
971
        list($principal, $dependent) = $metadataManager
972
            ->addNavigationPropertyToEntityType(
973
                $CategoryType,
974
                $mult,
975
                $principalProperty,
976
                $CustomerType,
977
                $mult,
978
                $dependentProperty,
979
                null,
980
                null,
981
                'Public',
982
                'Public',
983
                'Public',
984
                'Public',
985
                $summary,
986
                $longDescription,
987
                $summary,
988
                $longDescription
989
            );
990
991
        $this->assertNull($principal->getDocumentation());
992
        $this->assertNull($dependent->getDocumentation());
993
    }
994
995
    public function testCreateAssociationFromNavigationPropertyRelationMismatch()
996
    {
997
        $principalType = m::mock(TEntityTypeType::class);
998
        $dependentType = m::mock(TEntityTypeType::class);
999
        $principalNav = m::mock(TNavigationPropertyType::class);
1000
        $principalNav->shouldReceive('getRelationship')->andReturn('foo')->once();
1001
        $dependentNav = m::mock(TNavigationPropertyType::class);
1002
        $dependentNav->shouldReceive('getRelationship')->andReturn('bar')->once();
1003
1004
        $metadataManager = new MetadataManagerDummy();
1005
1006
        $expected = 'If you have both a dependent property and a principal property, relationship should match';
1007
        $actual = null;
1008
1009
        try {
1010
            $metadataManager->createAssocationFromNavigationProperty(
1011
                $principalType,
1012
                $dependentType,
1013
                $principalNav,
1014
                $dependentNav,
1015
                '*',
1016
                '*'
1017
            );
1018
        } catch (\InvalidArgumentException $e) {
1019
            $actual = $e->getMessage();
1020
        }
1021
        $this->assertEquals($expected, $actual);
1022
    }
1023
1024
    public function testCreateAssociationFromNavigationPropertyForwardRoleMismatch()
1025
    {
1026
        $principalType = m::mock(TEntityTypeType::class);
1027
        $dependentType = m::mock(TEntityTypeType::class);
1028
        $principalNav = m::mock(TNavigationPropertyType::class);
1029
        $principalNav->shouldReceive('getRelationship')->andReturn('foo')->once();
1030
        $principalNav->shouldReceive('getToRole')->andReturn('Forwards');
1031
        $principalNav->shouldReceive('getFromRole')->andReturn('Reverse');
1032
        $dependentNav = m::mock(TNavigationPropertyType::class);
1033
        $dependentNav->shouldReceive('getRelationship')->andReturn('foo')->once();
1034
        $dependentNav->shouldReceive('getToRole')->andReturn('Reverse');
1035
        $dependentNav->shouldReceive('getFromRole')->andReturn('Sideways');
1036
1037
        $metadataManager = new MetadataManagerDummy();
1038
1039
        $expected = 'Principal to role should match dependent from role, and vice versa';
1040
        $actual = null;
1041
1042
        try {
1043
            $metadataManager->createAssocationFromNavigationProperty(
1044
                $principalType,
1045
                $dependentType,
1046
                $principalNav,
1047
                $dependentNav,
1048
                '*',
1049
                '*'
1050
            );
1051
        } catch (\InvalidArgumentException $e) {
1052
            $actual = $e->getMessage();
1053
        }
1054
        $this->assertEquals($expected, $actual);
1055
    }
1056
1057
    public function testCreateAssociationFromNavigationPropertyReverseRoleMismatch()
1058
    {
1059
        $principalType = m::mock(TEntityTypeType::class);
1060
        $dependentType = m::mock(TEntityTypeType::class);
1061
        $principalNav = m::mock(TNavigationPropertyType::class);
1062
        $principalNav->shouldReceive('getRelationship')->andReturn('foo')->once();
1063
        $principalNav->shouldReceive('getToRole')->andReturn('Forwards');
1064
        $principalNav->shouldReceive('getFromRole')->andReturn('Reverse');
1065
        $dependentNav = m::mock(TNavigationPropertyType::class);
1066
        $dependentNav->shouldReceive('getRelationship')->andReturn('foo')->once();
1067
        $dependentNav->shouldReceive('getToRole')->andReturn('Sideways');
1068
        $dependentNav->shouldReceive('getFromRole')->andReturn('Forwards');
1069
1070
        $metadataManager = new MetadataManagerDummy();
1071
1072
        $expected = 'Principal to role should match dependent from role, and vice versa';
1073
        $actual = null;
1074
1075
        try {
1076
            $metadataManager->createAssocationFromNavigationProperty(
1077
                $principalType,
1078
                $dependentType,
1079
                $principalNav,
1080
                $dependentNav,
1081
                '*',
1082
                '*'
1083
            );
1084
        } catch (\InvalidArgumentException $e) {
1085
            $actual = $e->getMessage();
1086
        }
1087
        $this->assertEquals($expected, $actual);
1088
    }
1089
1090
    /**
1091
     * @return array
1092
     */
1093
    private function setUpMetadataForNavTests()
1094
    {
1095
        $msg = null;
1096
        $metadataManager = new MetadataManager('Data', 'Container');
1097
        $expectedCategorySetName = 'Categories';
1098
        $expectedCustomerSetName = 'Customers';
1099
1100
        list($CategoryType, $CategorySet) = $metadataManager->addEntityType('Category');
1101
        list($CustomerType, $CustomerSet) = $metadataManager->addEntityType('Customer');
1102
        $this->assertTrue($CategoryType->isOK($msg), $msg);
1103
        $this->assertTrue($CustomerType->isOK($msg), $msg);
1104
        $this->assertEquals($expectedCategorySetName, $CategorySet->getName());
1105
        $this->assertEquals($expectedCustomerSetName, $CustomerSet->getName());
1106
        return [$msg, $metadataManager, $CategoryType, $CustomerType];
1107
    }
1108
1109
    /**
1110
     * @param $navProps
1111
     * @param $ends
1112
     */
1113
    private function checkNavProps($navProps, $ends)
1114
    {
1115
        foreach ($navProps as $prop) {
1116
            $propToRole = $prop->getToRole();
1117
            $propFromRole = $prop->getFromRole();
1118
            $fromMatch = $ends[0]->getRole() == $propToRole
1119
                         || $ends[1]->getRole() == $propToRole;
1120
            $this->assertTrue($fromMatch, 'toRole must match at least one end role');
1121
            if ($ends[0]->getRole() == $propToRole) {
1122
                $this->assertEquals($ends[1]->getRole(), $propFromRole);
1123
                $this->assertNotEquals($ends[0]->getRole(), $propFromRole);
1124
            } else {
1125
                $this->assertEquals($ends[0]->getRole(), $propFromRole);
1126
                $this->assertNotEquals($ends[1]->getRole(), $propFromRole);
1127
            }
1128
        }
1129
    }
1130
1131
    /**
1132
     * @param $ends
1133
     * @param $principal
1134
     * @param $dependent
1135
     * @return array
1136
     */
1137
    private function figureOutEnds($ends, $principal, $dependent)
1138
    {
1139
        // if role is from Products, then type must be from Products - ie, use getFromRole
1140
        $principalEnd = ($ends[0]->getRole() == $principal->getFromRole()) ? $ends[0] : $ends[1];
1141
        $dependentEnd = ($ends[0]->getRole() == $dependent->getFromRole()) ? $ends[0] : $ends[1];
1142
        return [$principalEnd, $dependentEnd];
1143
    }
1144
}
1145