1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\ODataMetadata\Tests\v3\edm\EntityContainer; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\ODataMetadata\Tests\TestCase; |
6
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType; |
7
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType\EndAnonymousType; |
8
|
|
|
use Mockery as m; |
9
|
|
|
|
10
|
|
|
class AssociationSetAnonymousTypeTest extends TestCase |
11
|
|
|
{ |
12
|
|
View Code Duplication |
public function testSetBadName() |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
$expected = "Name must be a valid TSimpleIdentifier"; |
15
|
|
|
$actual = null; |
16
|
|
|
|
17
|
|
|
$foo = new AssociationSetAnonymousType(); |
18
|
|
|
|
19
|
|
|
try { |
20
|
|
|
$foo->setName(" _ "); |
21
|
|
|
} catch (\InvalidArgumentException $e) { |
22
|
|
|
$actual = $e->getMessage(); |
23
|
|
|
} |
24
|
|
|
$this->assertEquals($expected, $actual); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
View Code Duplication |
public function testSetBadAssociation() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$expected = "Association must be a valid TQualifiedName"; |
30
|
|
|
$actual = null; |
31
|
|
|
|
32
|
|
|
$foo = new AssociationSetAnonymousType(); |
33
|
|
|
|
34
|
|
|
try { |
35
|
|
|
$foo->setAssociation(" _ "); |
36
|
|
|
} catch (\InvalidArgumentException $e) { |
37
|
|
|
$actual = $e->getMessage(); |
38
|
|
|
} |
39
|
|
|
$this->assertEquals($expected, $actual); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
View Code Duplication |
public function testAddBadEnd() |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$expected = ""; |
45
|
|
|
$actual = null; |
46
|
|
|
|
47
|
|
|
$end = m::mock(EndAnonymousType::class); |
48
|
|
|
$end->shouldReceive('isOK')->andReturn(false); |
|
|
|
|
49
|
|
|
|
50
|
|
|
$foo = new AssociationSetAnonymousType(); |
51
|
|
|
|
52
|
|
|
try { |
53
|
|
|
$foo->addToEnd($end); |
54
|
|
|
} catch (\InvalidArgumentException $e) { |
55
|
|
|
$actual = $e->getMessage(); |
56
|
|
|
} |
57
|
|
|
$this->assertEquals($expected, $actual); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
public function testSetBadEnd() |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$expected = ""; |
63
|
|
|
$actual = null; |
64
|
|
|
|
65
|
|
|
$end = m::mock(EndAnonymousType::class); |
66
|
|
|
$end->shouldReceive('isOK')->andReturn(false); |
|
|
|
|
67
|
|
|
|
68
|
|
|
$foo = new AssociationSetAnonymousType(); |
69
|
|
|
|
70
|
|
|
try { |
71
|
|
|
$foo->setEnd([$end]); |
72
|
|
|
} catch (\InvalidArgumentException $e) { |
73
|
|
|
$actual = $e->getMessage(); |
74
|
|
|
} |
75
|
|
|
$this->assertEquals($expected, $actual); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
View Code Duplication |
public function testAddGoodEnd() |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
$end = m::mock(EndAnonymousType::class); |
81
|
|
|
$end->shouldReceive('isOK')->andReturn(true); |
|
|
|
|
82
|
|
|
|
83
|
|
|
$foo = new AssociationSetAnonymousType(); |
84
|
|
|
|
85
|
|
|
$foo->addToEnd($end); |
86
|
|
|
$this->assertTrue($foo->issetEnd(0)); |
87
|
|
|
$foo->unsetEnd(0); |
88
|
|
|
$this->assertFalse($foo->issetEnd(0)); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
View Code Duplication |
public function testIsOKNewObject() |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
$expected = "Name must be a valid TSimpleIdentifier"; |
94
|
|
|
$actual = null; |
95
|
|
|
|
96
|
|
|
$foo = new AssociationSetAnonymousType(); |
97
|
|
|
$this->assertFalse($foo->isOK($actual)); |
98
|
|
|
$this->assertEquals($expected, $actual); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
View Code Duplication |
public function testIsOKMissingAssociation() |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
$expected = "Association must be a valid TQualifiedName"; |
104
|
|
|
$actual = null; |
105
|
|
|
|
106
|
|
|
$foo = new AssociationSetAnonymousType(); |
107
|
|
|
$foo->setName('UnitPrice'); |
108
|
|
|
$this->assertFalse($foo->isOK($actual)); |
109
|
|
|
$this->assertEquals($expected, $actual); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testTooManyEnds() |
113
|
|
|
{ |
114
|
|
|
$expected = "Supplied array not a valid array: ". |
115
|
|
|
'AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType'; |
116
|
|
|
$actual = null; |
117
|
|
|
|
118
|
|
|
$end = m::mock(EndAnonymousType::class); |
119
|
|
|
$end->shouldReceive('isOK')->andReturn(true); |
|
|
|
|
120
|
|
|
|
121
|
|
|
$foo = new AssociationSetAnonymousType(); |
122
|
|
|
$foo->setName('UnitPrice'); |
123
|
|
|
$foo->setAssociation("Org.OData.Publication.V1.DocumentationUrl"); |
124
|
|
|
$foo->addToEnd($end); |
125
|
|
|
$foo->addToEnd($end); |
126
|
|
|
$foo->addToEnd($end); |
127
|
|
|
$this->assertFalse($foo->isOK($actual)); |
128
|
|
|
$this->assertEquals($expected, $actual); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.