1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\ODataMetadata\Tests\v3\edmx; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edmx\TDataServicesType; |
6
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edmx\TDesignerType; |
7
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edmx\TEdmxType; |
8
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edmx\TRuntimeType; |
9
|
|
|
use AlgoWeb\ODataMetadata\Tests\TestCase; |
10
|
|
|
use Mockery as m; |
11
|
|
|
|
12
|
|
|
class TEdmxTypeTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function testSetEmptyVersion() |
15
|
|
|
{ |
16
|
|
|
$version = " "; |
17
|
|
|
$foo = new TEdmxType(); |
18
|
|
|
|
19
|
|
|
$expected = "Version cannot be null or empty"; |
20
|
|
|
$actual = null; |
21
|
|
|
|
22
|
|
|
try { |
23
|
|
|
$foo->setVersion($version); |
24
|
|
|
} catch (\InvalidArgumentException $e) { |
25
|
|
|
$actual = $e->getMessage(); |
26
|
|
|
} |
27
|
|
|
$this->assertEquals($expected, $actual); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
View Code Duplication |
public function testSetDataServiceTypeNotOK() |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$dataServiceType = m::mock(TDataServicesType::class); |
33
|
|
|
$dataServiceType->shouldReceive('isOK')->andReturn(false)->once(); |
|
|
|
|
34
|
|
|
$foo = new TEdmxType(); |
35
|
|
|
|
36
|
|
|
$expected = ""; |
37
|
|
|
$actual = null; |
38
|
|
|
|
39
|
|
|
try { |
40
|
|
|
$foo->setDataServiceType($dataServiceType); |
41
|
|
|
} catch (\InvalidArgumentException $e) { |
42
|
|
|
$actual = $e->getMessage(); |
43
|
|
|
} |
44
|
|
|
$this->assertEquals($expected, $actual); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
public function testSetDesignerTypeNotOK() |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$designer = m::mock(TDesignerType::class); |
50
|
|
|
$designer->shouldReceive('isOK')->andReturn(false)->once(); |
|
|
|
|
51
|
|
|
$foo = new TEdmxType(); |
52
|
|
|
|
53
|
|
|
$expected = ""; |
54
|
|
|
$actual = null; |
55
|
|
|
|
56
|
|
|
try { |
57
|
|
|
$foo->setDesigner($designer); |
58
|
|
|
} catch (\InvalidArgumentException $e) { |
59
|
|
|
$actual = $e->getMessage(); |
60
|
|
|
} |
61
|
|
|
$this->assertEquals($expected, $actual); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
public function testSetDesignerTypeOK() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$designer = m::mock(TDesignerType::class); |
67
|
|
|
$designer->shouldReceive('isOK')->andReturn(true)->twice(); |
|
|
|
|
68
|
|
|
$foo = new TEdmxType(); |
69
|
|
|
|
70
|
|
|
$foo->setDesigner($designer); |
71
|
|
|
$this->assertTrue($foo->getDesigner()->isOK()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
View Code Duplication |
public function testSetRuntimeNotOK() |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
$runtime = m::mock(TRuntimeType::class); |
77
|
|
|
$runtime->shouldReceive('isOK')->andReturn(false)->once(); |
|
|
|
|
78
|
|
|
$foo = new TEdmxType(); |
79
|
|
|
|
80
|
|
|
$expected = ""; |
81
|
|
|
$actual = null; |
82
|
|
|
|
83
|
|
|
try { |
84
|
|
|
$foo->setRuntime($runtime); |
85
|
|
|
} catch (\InvalidArgumentException $e) { |
86
|
|
|
$actual = $e->getMessage(); |
87
|
|
|
} |
88
|
|
|
$this->assertEquals($expected, $actual); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
View Code Duplication |
public function testSetRuntimeOK() |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
$runtime = m::mock(TRuntimeType::class); |
94
|
|
|
$runtime->shouldReceive('isOK')->andReturn(true)->twice(); |
|
|
|
|
95
|
|
|
$foo = new TEdmxType(); |
96
|
|
|
|
97
|
|
|
$foo->setRuntime($runtime); |
98
|
|
|
$this->assertTrue($foo->getRuntime()->isOK()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
View Code Duplication |
public function testIsNewObjectOK() |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
$expected = "Version cannot be null or empty"; |
104
|
|
|
$actual = null; |
105
|
|
|
$foo = new TEdmxType(); |
106
|
|
|
|
107
|
|
|
$this->assertFalse($foo->isOK($actual)); |
108
|
|
|
$this->assertEquals($expected, $actual); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
View Code Duplication |
public function testIsObjectWithoutDataServiceOK() |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
$expected = "Data service type cannot be null"; |
114
|
|
|
$actual = null; |
115
|
|
|
$foo = new TEdmxType(); |
116
|
|
|
$foo->setVersion("1.5"); |
117
|
|
|
|
118
|
|
|
$this->assertFalse($foo->isOK($actual)); |
119
|
|
|
$this->assertEquals($expected, $actual); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
View Code Duplication |
public function testIsObjectWithBadDataServiceOK() |
|
|
|
|
123
|
|
|
{ |
124
|
|
|
$unwanted2 = "Version cannot be null or empty"; |
125
|
|
|
$actual = null; |
126
|
|
|
$dataServiceType = m::mock(TDataServicesType::class); |
127
|
|
|
$dataServiceType->shouldReceive('isOK')->andReturn(true, false)->twice(); |
|
|
|
|
128
|
|
|
$foo = new TEdmxType(); |
129
|
|
|
$foo->setVersion("1.5"); |
130
|
|
|
$foo->setDataServiceType($dataServiceType); |
131
|
|
|
|
132
|
|
|
$this->assertFalse($foo->isOK($actual)); |
133
|
|
|
$this->assertNotEquals($unwanted2, $actual); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
View Code Duplication |
public function testIsObjectWithBadDesignerServiceOK() |
|
|
|
|
138
|
|
|
{ |
139
|
|
|
$unwanted = "Data service type cannot be null"; |
140
|
|
|
$unwanted2 = "Version cannot be null or empty"; |
141
|
|
|
$actual = null; |
142
|
|
|
$designer = m::mock(TDesignerType::class); |
143
|
|
|
$designer->shouldReceive('isOK')->andReturn(true, false)->twice(); |
|
|
|
|
144
|
|
|
$dataServiceType = m::mock(TDataServicesType::class); |
145
|
|
|
$dataServiceType->shouldReceive('isOK')->andReturn(true)->once(); |
146
|
|
|
$foo = new TEdmxType(); |
147
|
|
|
$foo->setVersion("1.5"); |
148
|
|
|
$foo->setDataServiceType($dataServiceType); |
149
|
|
|
$foo->setDesigner($designer); |
150
|
|
|
|
151
|
|
|
$this->assertFalse($foo->isOK($actual)); |
152
|
|
|
$this->assertNotEquals($unwanted, $actual); |
153
|
|
|
$this->assertNotEquals($unwanted2, $actual); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
View Code Duplication |
public function testIsObjectWithBadRuntimeServiceOK() |
|
|
|
|
157
|
|
|
{ |
158
|
|
|
$unwanted = "Data service type cannot be null"; |
159
|
|
|
$unwanted2 = "Version cannot be null or empty"; |
160
|
|
|
$actual = null; |
161
|
|
|
$runtime = m::mock(TRuntimeType::class); |
162
|
|
|
$runtime->shouldReceive('isOK')->andReturn(true, false)->twice(); |
|
|
|
|
163
|
|
|
$dataServiceType = m::mock(TDataServicesType::class); |
164
|
|
|
$dataServiceType->shouldReceive('isOK')->andReturn(true)->once(); |
165
|
|
|
$foo = new TEdmxType(); |
166
|
|
|
$foo->setVersion("1.5"); |
167
|
|
|
$foo->setDataServiceType($dataServiceType); |
168
|
|
|
$foo->setRuntime($runtime); |
169
|
|
|
|
170
|
|
|
$this->assertFalse($foo->isOK($actual)); |
171
|
|
|
$this->assertNotEquals($unwanted, $actual); |
172
|
|
|
$this->assertNotEquals($unwanted2, $actual); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
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.