1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\ODataMetadata\Tests\v3\edmx; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edmx\TDataServicesType; |
6
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\Schema; |
7
|
|
|
use AlgoWeb\ODataMetadata\Tests\TestCase; |
8
|
|
|
use Mockery as m; |
9
|
|
|
|
10
|
|
|
class TDataServicesTypeTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
public function testServiceVersionGreaterThanMaxVersionWithIntegerVersions() |
13
|
|
|
{ |
14
|
|
|
$expected = "Data service version cannot be greater than maximum service version"; |
15
|
|
|
$actual = null; |
16
|
|
|
|
17
|
|
|
try { |
18
|
|
|
new TDataServicesType('3.0', '4.0'); |
19
|
|
|
} catch (\InvalidArgumentException $e) { |
20
|
|
|
$actual = $e->getMessage(); |
21
|
|
|
} |
22
|
|
|
$this->assertEquals($expected, $actual); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testServiceVersionGreaterThanMaxVersionWithNonIntegerVersions() |
26
|
|
|
{ |
27
|
|
|
$expected = "Data service version cannot be greater than maximum service version"; |
28
|
|
|
$actual = null; |
29
|
|
|
|
30
|
|
|
try { |
31
|
|
|
new TDataServicesType('3.1', '3.4'); |
32
|
|
|
} catch (\InvalidArgumentException $e) { |
33
|
|
|
$actual = $e->getMessage(); |
34
|
|
|
} |
35
|
|
|
$this->assertEquals($expected, $actual); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testMaxServiceVersionNotNumeric() |
39
|
|
|
{ |
40
|
|
|
$expected = "Maximum service version must be numeric"; |
41
|
|
|
$actual = null; |
42
|
|
|
|
43
|
|
|
try { |
44
|
|
|
new TDataServicesType(new \DateTime(), '3.4'); |
|
|
|
|
45
|
|
|
} catch (\InvalidArgumentException $e) { |
46
|
|
|
$actual = $e->getMessage(); |
47
|
|
|
} |
48
|
|
|
$this->assertEquals($expected, $actual); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testDataServiceVersionNotNumeric() |
52
|
|
|
{ |
53
|
|
|
$expected = "Data service version must be numeric"; |
54
|
|
|
$actual = null; |
55
|
|
|
|
56
|
|
|
try { |
57
|
|
|
new TDataServicesType('3.4', new \DateTime()); |
|
|
|
|
58
|
|
|
} catch (\InvalidArgumentException $e) { |
59
|
|
|
$actual = $e->getMessage(); |
60
|
|
|
} |
61
|
|
|
$this->assertEquals($expected, $actual); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testMaxDataServiceVersionOutOfRange() |
65
|
|
|
{ |
66
|
|
|
$expected = "Maximum data service version must be 3.0 or 4.0"; |
67
|
|
|
$actual = null; |
68
|
|
|
|
69
|
|
|
try { |
70
|
|
|
new TDataServicesType('2.0', '2.0'); |
71
|
|
|
} catch (\InvalidArgumentException $e) { |
72
|
|
|
$actual = $e->getMessage(); |
73
|
|
|
} |
74
|
|
|
$this->assertEquals($expected, $actual); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testDataServiceVersionOutOfRange() |
78
|
|
|
{ |
79
|
|
|
$expected = "Data service version must be 1.0, 2.0, 3.0 or 4.0"; |
80
|
|
|
$actual = null; |
81
|
|
|
|
82
|
|
|
try { |
83
|
|
|
new TDataServicesType('3.0', '0.5'); |
84
|
|
|
} catch (\InvalidArgumentException $e) { |
85
|
|
|
$actual = $e->getMessage(); |
86
|
|
|
} |
87
|
|
|
$this->assertEquals($expected, $actual); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testShouldNotBeAbleToSetEmptySchemaArray() |
91
|
|
|
{ |
92
|
|
|
$expected = "Data services array not a valid array"; |
93
|
|
|
$actual = null; |
94
|
|
|
|
95
|
|
|
$foo = new TDataServicesType(); |
96
|
|
|
|
97
|
|
|
try { |
98
|
|
|
$foo->setSchema([]); |
99
|
|
|
} catch (\InvalidArgumentException $e) { |
100
|
|
|
$actual = $e->getMessage(); |
101
|
|
|
} |
102
|
|
|
$this->assertEquals($expected, $actual); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
View Code Duplication |
public function testTryToAddBadSchema() |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
$expected = ""; |
108
|
|
|
$actual = null; |
109
|
|
|
|
110
|
|
|
$schema = m::mock(Schema::class); |
111
|
|
|
$schema->shouldReceive('isOK')->andReturn(false)->once(); |
|
|
|
|
112
|
|
|
|
113
|
|
|
$foo = new TDataServicesType(); |
114
|
|
|
try { |
115
|
|
|
$foo->addToSchema($schema); |
116
|
|
|
} catch (\InvalidArgumentException $e) { |
117
|
|
|
$actual = $e->getMessage(); |
118
|
|
|
} |
119
|
|
|
$this->assertEquals($expected, $actual); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
public function testCheckSchemaExists() |
124
|
|
|
{ |
125
|
|
|
$foo = new TDataServicesType(); |
126
|
|
|
$this->assertFalse($foo->issetSchema(1)); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function testUnsetMissingSchema() |
130
|
|
|
{ |
131
|
|
|
$foo = new TDataServicesType(); |
132
|
|
|
$foo->unsetSchema(1); |
133
|
|
|
$this->assertTrue(true); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function testSetHigherDataThanDefaultMaxServiceVersionNotOK() |
137
|
|
|
{ |
138
|
|
|
$expected = "Data service version cannot be greater than maximum service version"; |
139
|
|
|
$actual = null; |
140
|
|
|
|
141
|
|
|
$foo = new TDataServicesType(); |
142
|
|
|
$foo->setDataServiceVersion('4.0'); |
143
|
|
|
$this->assertFalse($foo->isOK($actual)); |
144
|
|
|
$this->assertEquals($expected, $actual); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
View Code Duplication |
public function testIsOKWhenSchemaNotOk() |
|
|
|
|
148
|
|
|
{ |
149
|
|
|
$expected = ""; |
150
|
|
|
$actual = null; |
151
|
|
|
|
152
|
|
|
$schema = m::mock(Schema::class); |
153
|
|
|
$schema->shouldReceive('isOK')->andReturn(true, false)->twice(); |
|
|
|
|
154
|
|
|
$foo = new TDataServicesType(); |
155
|
|
|
$foo->addToSchema($schema); |
156
|
|
|
$this->assertFalse($foo->isOK($actual)); |
157
|
|
|
$this->assertEquals($expected, $actual); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: