1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test\FlexiPeeHP; |
4
|
|
|
|
5
|
|
|
use FlexiPeeHP\FlexiBee; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class used to test Object To Array Conversion |
9
|
|
|
*/ |
10
|
|
|
class objTest extends \stdClass |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Simple Item |
14
|
|
|
* @var integer |
15
|
|
|
*/ |
16
|
|
|
public $item = 1; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Array item |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
public $arrItem = ['a', 'b' => 'c']; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Simple method |
26
|
|
|
* |
27
|
|
|
* @return boolean |
28
|
|
|
*/ |
29
|
|
|
public function method() |
30
|
|
|
{ |
31
|
|
|
return true; |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Generated by PHPUnit_SkeletonGenerator on 2016-05-04 at 10:08:36. |
37
|
|
|
*/ |
38
|
|
|
class FlexiBeeTest extends \Test\Ease\BrickTest |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* @var FlexiBee |
42
|
|
|
*/ |
43
|
|
|
protected $object; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Sets up the fixture, for example, opens a network connection. |
47
|
|
|
* This method is called before a test is executed. |
48
|
|
|
* @covers FlexiPeeHP\FlexiBee::__construct |
49
|
|
|
*/ |
50
|
|
|
protected function setUp() |
51
|
|
|
{ |
52
|
|
|
$this->object = new FlexiBee; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Tears down the fixture, for example, closes a network connection. |
57
|
|
|
* This method is called after a test is executed. |
58
|
|
|
*/ |
59
|
|
|
protected function tearDown() |
60
|
|
|
{ |
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testCurlInit() |
65
|
|
|
{ |
66
|
|
|
$this->object->curlInit(); |
67
|
|
|
$this->assertTrue(is_resource($this->object->curl)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @covers FlexiPeeHP\FlexiBee::setAgenda |
72
|
|
|
*/ |
73
|
|
|
public function testSetAgenda() |
74
|
|
|
{ |
75
|
|
|
$this->object->setAgenda('nastaveni'); |
76
|
|
|
$this->assertEquals('nastaveni', $this->object->agenda); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @covers FlexiPeeHP\FlexiBee::object2array |
81
|
|
|
*/ |
82
|
|
|
public function testObject2array() |
83
|
|
|
{ |
84
|
|
|
$this->assertNull($this->object->object2array(new \stdClass())); |
85
|
|
|
$this->assertEquals( |
86
|
|
|
[ |
87
|
|
|
'item' => 1, |
88
|
|
|
'arrItem' => ['a', 'b' => 'c'] |
89
|
|
|
] |
90
|
|
|
, $this->object->object2array(new objTest())); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @covers FlexiPeeHP\FlexiBee::performRequest |
95
|
|
|
*/ |
96
|
|
|
public function testPerformRequest() |
97
|
|
|
{ |
98
|
|
|
|
99
|
|
|
if (!is_null($this->object->agenda) && $this->object->agenda != 'test') { |
100
|
|
|
$json = $this->object->performRequest($this->object->agenda.'.json'); |
101
|
|
|
if (array_key_exists('message', $json)) { |
102
|
|
|
$this->assertArrayHasKey('@version', $json); |
103
|
|
|
} else { |
104
|
|
|
$this->assertArrayHasKey($this->object->agenda, $json); |
105
|
|
|
} |
106
|
|
|
} else { |
107
|
|
|
$this->object->agenda = 'c'; |
108
|
|
|
$this->object->prefix = ''; |
109
|
|
|
$this->object->company = ''; |
|
|
|
|
110
|
|
|
$this->object->nameSpace = 'companies'; |
111
|
|
|
$json = $this->object->performRequest(); |
112
|
|
|
$this->assertArrayHasKey('company', $json); |
113
|
|
|
|
114
|
|
|
$xml = $this->object->performRequest(null, null, 'xml'); |
115
|
|
|
$this->assertArrayHasKey('company', $xml); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @covers FlexiPeeHP\FlexiBee::getLastInsertedId |
121
|
|
|
* @depends testInsertToFlexiBee |
122
|
|
|
*/ |
123
|
|
|
public function testGetLastInsertedId() |
124
|
|
|
{ |
125
|
|
|
$this->assertNotEmpty($this->object->getLastInsertedId()); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @covers FlexiPeeHP\FlexiBee::xml2array |
130
|
|
|
*/ |
131
|
|
|
public function testXml2array() |
132
|
|
|
{ |
133
|
|
|
$xml = '<card xmlns="http://businesscard.org"> |
134
|
|
|
<name>John Doe</name> |
135
|
|
|
<title>CEO, Widget Inc.</title> |
136
|
|
|
<email>[email protected]</email> |
137
|
|
|
<phone>(202) 456-1414</phone> |
138
|
|
|
<logo url="widget.gif"/> |
139
|
|
|
</card>'; |
140
|
|
|
|
141
|
|
|
$data = ['name' => 'John Doe', 'title' => 'CEO, Widget Inc.', 'email' => '[email protected]', |
142
|
|
|
'phone' => '(202) 456-1414', 'logo' => '']; |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
$this->assertEquals($data, $this->object->xml2array($xml)); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @covers FlexiPeeHP\FlexiBee::disconnect |
150
|
|
|
* |
151
|
|
|
* @depends testPerformRequest |
152
|
|
|
* @depends testLoadFlexiData |
153
|
|
|
* @depends testGetFlexiRow |
154
|
|
|
* @depends testGetFlexiData |
155
|
|
|
* @depends testLoadFromFlexiBee |
156
|
|
|
* @depends testSaveToFlexiBee |
157
|
|
|
* @depends testInsertToFlexiBee |
158
|
|
|
* @depends testIdExists |
159
|
|
|
* @depends testRecordExists |
160
|
|
|
* @depends testGetColumnsFromFlexibee |
161
|
|
|
* @depends testSearchString |
162
|
|
|
*/ |
163
|
|
|
public function testDisconnect() |
164
|
|
|
{ |
165
|
|
|
$this->object->disconnect(); |
166
|
|
|
$this->assertNull($this->object->curl); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @covers FlexiPeeHP\FlexiBee::__destruct |
171
|
|
|
* @depends testDisconnect |
172
|
|
|
*/ |
173
|
|
|
public function test__destruct() |
174
|
|
|
{ |
175
|
|
|
$this->markTestSkipped(); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @covers FlexiPeeHP\FlexiBee::loadFlexiData |
180
|
|
|
* @todo Implement testLoadFlexiData(). |
181
|
|
|
*/ |
182
|
|
|
public function testLoadFlexiData() |
183
|
|
|
{ |
184
|
|
|
// Remove the following lines when you implement this test. |
185
|
|
|
$this->markTestIncomplete( |
186
|
|
|
'This test has not been implemented yet.' |
187
|
|
|
); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @covers FlexiPeeHP\FlexiBee::getFlexiRow |
192
|
|
|
*/ |
193
|
|
|
public function testGetFlexiRow() |
194
|
|
|
{ |
195
|
|
|
$this->object->getFlexiRow(0); |
196
|
|
|
$this->object->getFlexiRow(1); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @covers FlexiPeeHP\FlexiBee::getFlexiData |
201
|
|
|
*/ |
202
|
|
|
public function testGetFlexiData() |
203
|
|
|
{ |
204
|
|
|
if (is_null($this->object->agenda) || $this->object->agenda != 'test') { |
205
|
|
|
$this->object->agenda = 'c'; |
206
|
|
|
$this->object->prefix = ''; |
207
|
|
|
$this->object->company = ''; |
|
|
|
|
208
|
|
|
$this->object->nameSpace = 'companies'; |
209
|
|
|
$flexidata = $this->object->getFlexiData(); |
210
|
|
|
$this->assertArrayHasKey('company', $flexidata); |
211
|
|
|
} else { |
212
|
|
|
$flexidata = $this->object->getFlexiData(); |
213
|
|
|
$this->assertArrayHasKey($this->object->agenda, $flexidata); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @covers FlexiPeeHP\FlexiBee::loadFromFlexiBee |
219
|
|
|
*/ |
220
|
|
|
public function testLoadFromFlexiBee() |
221
|
|
|
{ |
222
|
|
|
$this->object->loadFromFlexiBee(); |
223
|
|
|
$this->object->loadFromFlexiBee(222); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @covers FlexiPeeHP\FlexiBee::saveToFlexiBee |
228
|
|
|
* @todo Implement testSaveToFlexiBee(). |
229
|
|
|
*/ |
230
|
|
|
public function testSaveToFlexiBee() |
231
|
|
|
{ |
232
|
|
|
// Remove the following lines when you implement this test. |
233
|
|
|
$this->markTestIncomplete( |
234
|
|
|
'This test has not been implemented yet.' |
235
|
|
|
); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @covers FlexiPeeHP\FlexiBee::jsonizeData |
240
|
|
|
*/ |
241
|
|
|
public function testJsonizeData() |
242
|
|
|
{ |
243
|
|
|
$this->assertEquals('{"winstrom":{"@version":"1.0","'.$this->object->agenda.'":{"key":"value"}}}', |
244
|
|
|
$this->object->jsonizeData(['key' => 'value'])); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @covers FlexiPeeHP\FlexiBee::insertToFlexiBee |
249
|
|
|
* @todo Implement testInsertToFlexiBee(). |
250
|
|
|
*/ |
251
|
|
|
public function testInsertToFlexiBee() |
252
|
|
|
{ |
253
|
|
|
// Remove the following lines when you implement this test. |
254
|
|
|
$this->markTestIncomplete( |
255
|
|
|
'This test has not been implemented yet.' |
256
|
|
|
); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @covers FlexiPeeHP\FlexiBee::idExists |
261
|
|
|
* @todo Implement testIdExists(). |
262
|
|
|
*/ |
263
|
|
|
public function testIdExists() |
264
|
|
|
{ |
265
|
|
|
// Remove the following lines when you implement this test. |
266
|
|
|
$this->markTestIncomplete( |
267
|
|
|
'This test has not been implemented yet.' |
268
|
|
|
); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @covers FlexiPeeHP\FlexiBee::recordExists |
273
|
|
|
* @todo Implement testRecordExists(). |
274
|
|
|
*/ |
275
|
|
|
public function testRecordExists() |
276
|
|
|
{ |
277
|
|
|
// Remove the following lines when you implement this test. |
278
|
|
|
$this->markTestIncomplete( |
279
|
|
|
'This test has not been implemented yet.' |
280
|
|
|
); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @covers FlexiPeeHP\FlexiBee::getColumnsFromFlexibee |
285
|
|
|
* @todo Implement testGetColumnsFromFlexibee(). |
286
|
|
|
*/ |
287
|
|
|
public function testGetColumnsFromFlexibee() |
288
|
|
|
{ |
289
|
|
|
// Remove the following lines when you implement this test. |
290
|
|
|
$this->markTestIncomplete( |
291
|
|
|
'This test has not been implemented yet.' |
292
|
|
|
); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @covers FlexiPeeHP\FlexiBee::getKod |
297
|
|
|
* @todo Implement testGetKod(). |
298
|
|
|
*/ |
299
|
|
|
public function testGetKod() |
300
|
|
|
{ |
301
|
|
|
// Remove the following lines when you implement this test. |
302
|
|
|
$this->markTestIncomplete( |
303
|
|
|
'This test has not been implemented yet.' |
304
|
|
|
); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* @covers FlexiPeeHP\FlexiBee::searchString |
309
|
|
|
* @todo Implement testSearchString(). |
310
|
|
|
*/ |
311
|
|
|
public function testSearchString() |
312
|
|
|
{ |
313
|
|
|
// Remove the following lines when you implement this test. |
314
|
|
|
$this->markTestIncomplete( |
315
|
|
|
'This test has not been implemented yet.' |
316
|
|
|
); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* @covers FlexiPeeHP\FlexiBee::logResult |
321
|
|
|
* @todo Implement testLogResult(). |
322
|
|
|
*/ |
323
|
|
|
public function testLogResult() |
324
|
|
|
{ |
325
|
|
|
// Remove the following lines when you implement this test. |
326
|
|
|
$this->markTestIncomplete( |
327
|
|
|
'This test has not been implemented yet.' |
328
|
|
|
); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @covers FlexiPeeHP\FlexiBee::flexiUrl |
333
|
|
|
*/ |
334
|
|
|
public function testFlexiUrl() |
335
|
|
|
{ |
336
|
|
|
$this->assertEquals("a = 1 and b = 'foo'", |
337
|
|
|
$this->object->flexiUrl(['a' => 1, 'b' => 'foo'], 'and')); |
338
|
|
|
$this->assertEquals("a = 1 or b = 'bar'", |
339
|
|
|
$this->object->flexiUrl(['a' => 1, 'b' => 'bar'], 'or')); |
340
|
|
|
} |
341
|
|
|
} |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.