FlexiBeeROTest   F
last analyzed

Complexity

Total Complexity 217

Size/Duplication

Total Lines 1418
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 217
eloc 624
dl 0
loc 1418
rs 1.976
c 0
b 0
f 0

88 Methods

Rating   Name   Duplication   Size   Complexity  
A testLoadFromFlexiBee() 0 4 1
A testGetLastInsertedId() 0 3 1
A testGetDataForJson() 0 3 1
A testGetRecordID() 0 4 1
A testUrlEncode() 0 4 1
A testParseResponse() 0 4 1
A testSetCompany() 0 4 1
A testLogBanner() 0 3 1
A testDisconnect() 0 4 1
A tearDown() 0 2 1
A testGetEvidence() 0 4 1
A testDoCurlRequest() 0 3 1
A testGetCompany() 0 3 1
A testGetFlexiRow() 0 4 1
A testGetAllFromFlexibee() 0 3 1
A testdestruct() 0 3 1
A testSetFormat() 0 4 1
A testSetPrefix() 0 7 1
B testSetAction() 0 19 8
A testRawResponseToArray() 0 11 1
A testGetResponseFormat() 0 10 1
B testIdExists() 0 22 9
A testGetExternalID() 0 9 1
A testGetRecordIdent() 0 13 1
B testGetFlexiData() 0 39 6
A testGetConnectionOptions() 0 8 1
B testPerformRequest() 0 26 8
B testGetResponseEvidence() 0 16 8
B testGetJsonizedData() 0 24 8
A testProcessInit() 0 26 6
A testSetUp() 0 24 1
B testGetGlobalVersion() 0 17 8
A testObjectToID() 0 7 1
B testGetColumnsFromFlexibee() 0 19 8
A testSetEvidence() 0 7 1
A testExtractUrlParams() 0 6 1
A testXml2array() 0 20 1
A testGetKod() 0 27 1
A testRawJsonToArray() 0 20 2
A testLogResult() 0 20 1
A setUp() 0 6 1
A testGetApiUrl() 0 12 2
A testObject2array() 0 9 1
A testConstructor() 0 24 2
A testCurlInit() 0 5 1
B testRecordExists() 0 30 8
A testRawXmlToArray() 0 22 2
B testgetColumnsInfo() 0 15 7
B testGetEvidenceInfo() 0 15 8
B testgetActionsInfo() 0 18 8
A testError500Reporter() 0 4 1
A test__wakeup() 0 3 1
A testgetEvidenceUrl() 0 4 1
A testSendUnsent() 0 3 1
A testGetFlexiBeeURL() 0 3 1
A testSetPostFields() 0 4 1
A testUncode() 0 3 1
B testgetRelationsInfo() 0 18 10
B testGetEvidenceName() 0 15 8
A testEvidenceUrlWithSuffix() 0 9 1
B testGetReportsInfo() 0 15 7
A testArrayCleanUP() 0 4 1
A testSetFilter() 0 4 1
A testSetMyKey() 0 3 1
A testFlexiUrl() 0 20 1
A testSaveResponseToFile() 0 5 1
A test_destruct() 0 3 1
A testDraw() 0 4 1
A testCode() 0 3 1
A testFlexiDateTimeToDateTime() 0 4 1
A testJoin() 0 8 1
A testTakeData() 0 10 1
A testAddDefaultUrlParams() 0 8 1
A testFlexiDateToDateTime() 0 4 1
A testSendByMail() 0 4 1
A testIgnore404() 0 4 1
B testgetFirstRecordID() 0 14 8
A testevidenceToClassName() 0 4 1
A testunifyResponseFormat() 0 40 2
A testDownloadInFormat() 0 3 1
A testSetDataValue() 0 8 2
A testtoString() 0 15 1
A testGetColumnInfo() 0 3 1
A testDateToFlexiDate() 0 5 1
A testSaveDebugFiles() 0 3 1
A testGetInFormat() 0 7 1
A testDateToFlexiDateTime() 0 5 1
B testGetVazby() 0 16 8

How to fix   Complexity   

Complex Class

Complex classes like FlexiBeeROTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use FlexiBeeROTest, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Test\FlexiPeeHP;
4
5
use FlexiPeeHP\FlexiBeeRO;
6
7
/**
8
 * Generated by PHPUnit_SkeletonGenerator on 2016-05-04 at 10:08:36.
9
 */
10
class FlexiBeeROTest extends \Test\Ease\SandTest
11
{
12
    /**
13
     * @var FlexiBeeRO
14
     */
15
    protected $object;
16
17
    /**
18
     * Example JSON 
19
     * @var string json 
20
     */
21
    public $json = '{"winstrom":{"@version":"1.0","adresar":[{"id":"2574","kontakty":[{"id":"299"}]}]}}';
22
23
    /**
24
     * Example XML
25
     * @var string xml 
26
     */
27
    public $xml = '<?xml version="1.0" encoding="utf-8"?>
28
29
<winstrom version="1.0">
30
  <!-- Adresář -->
31
  <adresar>
32
    <!-- ID (celé číslo) - -->
33
    <id>2574</id>
34
    <kontakty>
35
      <!-- Kontakty -->
36
      <kontakt>
37
        <!-- ID (celé číslo) - -->
38
        <id>299</id>
39
      </kontakt>
40
    </kontakty>
41
  </adresar>
42
</winstrom>';
43
44
    /**
45
     * Sets up the fixture, for example, opens a network connection.
46
     * This method is called before a test is executed.
47
     * @covers FlexiPeeHP\FlexiBeeRO::__construct
48
     */
49
    protected function setUp(): void
50
    {
51
        $this->object                  = new FlexiBeeRO();
52
        $this->object->prefix          = '/';
53
        $this->object->debug           = true;
54
        $this->object->reportRecipient = '[email protected]';
55
    }
56
57
    /**
58
     * Tears down the fixture, for example, closes a network connection.
59
     * This method is called after a test is executed.
60
     */
61
    protected function tearDown(): void
62
    {
63
        
64
    }
65
66
    /**
67
     * @covers FlexiPeeHP\FlexiBeeRO::logBanner
68
     */
69
    public function testLogBanner()
70
    {
71
        $this->object->logBanner(addslashes(get_class($this)));
72
    }
73
74
    /**
75
     * Test Constructor
76
     *
77
     * @depends testLogBanner
78
     * @covers FlexiPeeHP\FlexiBeeRO::__construct
79
     */
80
    public function testConstructor()
81
    {
82
        $classname = get_class($this->object);
83
        $evidence  = $this->object->getEvidence();
84
85
        // Get mock, without the constructor being called
86
        $mock = $this->getMockBuilder($classname)
0 ignored issues
show
Bug introduced by
The method getMockBuilder() does not exist on Test\FlexiPeeHP\FlexiBeeROTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
        $mock = $this->/** @scrutinizer ignore-call */ getMockBuilder($classname)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
            ->disableOriginalConstructor()
88
            ->getMockForAbstractClass();
89
        $mock->__construct(1, ['debug' => false]);
90
91
        if (!isset(\FlexiPeeHP\EvidenceList::$name[$evidence])) {
92
            $evidence = 'adresar';
93
        }
94
95
        $mock->__construct('',
96
            [
97
            'company' => constant('FLEXIBEE_COMPANY'),
98
            'url' => constant('FLEXIBEE_URL'),
99
            'user' => constant('FLEXIBEE_LOGIN'),
100
            'password' => constant('FLEXIBEE_PASSWORD'),
101
            'debug' => true,
102
            'prefix' => 'c',
103
            'evidence' => $evidence]);
104
    }
105
106
    /**
107
     * @covers FlexiPeeHP\FlexiBeeRO::curlInit
108
     */
109
    public function testCurlInit()
110
    {
111
        $this->object->timeout = 120;
112
        $this->object->curlInit();
113
        $this->assertTrue(is_resource($this->object->curl));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not exist on Test\FlexiPeeHP\FlexiBeeROTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

113
        $this->/** @scrutinizer ignore-call */ 
114
               assertTrue(is_resource($this->object->curl));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
114
    }
115
116
    /**
117
     * @covers FlexiPeeHP\FlexiBeeRO::processInit
118
     */
119
    public function testProcessInit()
120
    {
121
        $this->object->processInit(1);
122
        $this->object->processInit(['id' => 1]);
123
        $this->assertEquals(1, $this->object->getDataValue('id'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not exist on Test\FlexiPeeHP\FlexiBeeROTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

123
        $this->/** @scrutinizer ignore-call */ 
124
               assertEquals(1, $this->object->getDataValue('id'));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
124
125
        if (!is_null($this->object->evidence) && $this->object->evidence != 'test') {
0 ignored issues
show
introduced by
The condition is_null($this->object->evidence) is always false.
Loading history...
126
127
128
            $firstID = $this->object->getColumnsFromFlexibee(['id', 'kod'],
129
                ['limit' => 1]);
130
131
            if (count($firstID) && isset($firstID[0]['id'])) {
132
133
                $this->object->processInit((int) current($firstID));
134
                $this->assertNotEmpty($this->object->__toString());
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not exist on Test\FlexiPeeHP\FlexiBeeROTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

134
                $this->/** @scrutinizer ignore-call */ 
135
                       assertNotEmpty($this->object->__toString());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
135
136
                if (isset($firstID[0]['kod'])) {
137
                    $this->object->processInit('code:'.$firstID[0]['kod']);
138
                    $this->assertNotEmpty($this->object->__toString());
139
                }
140
141
                $this->object->processInit($this->object->getEvidenceURL().'/'.$firstID[0]['id'].'.xml');
142
            } else {
143
                $this->markTestSkipped(sprintf('Evidence %s does not contain first record',
0 ignored issues
show
Bug introduced by
The method markTestSkipped() does not exist on Test\FlexiPeeHP\FlexiBeeROTest. Did you maybe mean markTestSuiteSkipped()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

143
                $this->/** @scrutinizer ignore-call */ 
144
                       markTestSkipped(sprintf('Evidence %s does not contain first record',

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
144
                        $this->object->getEvidence()));
145
            }
146
        }
147
    }
148
149
    /**
150
     * @covers FlexiPeeHP\FlexiBeeRO::setUp
151
     */
152
    public function testSetUp()
153
    {
154
        $this->object->authSessionId = 'XXXtestXXX';
155
        $this->object->setUp(
156
            [
157
                'company' => 'cmp',
158
                'url' => 'url',
159
                'user' => 'usr',
160
                'password' => 'pwd',
161
                'prefix' => 'c',
162
                'debug' => true,
163
                'defaultUrlParams' => ['limit' => 10],
164
                'evidence' => 'smlouva',
165
                'detail' => 'summary',
166
                'filter' => 'testfilter',
167
                'ignore404' => true,
168
                'offline' => true
169
            ]
170
        );
171
        $this->assertEquals('cmp', $this->object->company);
172
        $this->assertEquals('url', $this->object->url);
173
        $this->assertEquals('usr', $this->object->user);
174
        $this->assertEquals('/c/', $this->object->prefix);
175
        $this->assertEquals('pwd', $this->object->password);
176
    }
177
178
    /**
179
     * @covers FlexiPeeHP\FlexiBeeRO::getConnectionOptions
180
     */
181
    public function testGetConnectionOptions()
182
    {
183
        $options                     = $this->object->getConnectionOptions();
184
        $this->assertArrayHasKey('url', $options);
0 ignored issues
show
Bug introduced by
The method assertArrayHasKey() does not exist on Test\FlexiPeeHP\FlexiBeeROTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

184
        $this->/** @scrutinizer ignore-call */ 
185
               assertArrayHasKey('url', $options);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
185
        $this->object->timeout       = 120;
186
        $this->object->authSessionId = 'sessid';
187
        $this->object->setCompany('test');
188
        $this->object->getConnectionOptions();
189
    }
190
191
    /**
192
     * @covers FlexiPeeHP\FlexiBeeRO::setPrefix
193
     * @expectedException \Exception
194
     */
195
    public function testSetPrefix()
196
    {
197
        $this->object->setPrefix('c');
198
        $this->assertEquals('/c/', $this->object->prefix);
199
        $this->object->setPrefix(null);
200
        $this->assertEquals('', $this->object->prefix);
201
        $this->object->setPrefix('fail');
202
    }
203
204
    /**
205
     * @covers FlexiPeeHP\FlexiBeeRO::setFormat
206
     */
207
    public function testSetFormat()
208
    {
209
        $this->object->setFormat('xml');
210
        $this->assertEquals('xml', $this->object->format);
211
    }
212
213
    /**
214
     * We can set only evidence defined in EvidenceList class
215
     *
216
     * @covers FlexiPeeHP\FlexiBeeRO::setEvidence
217
     * @expectedException \Exception
218
     */
219
    public function testSetEvidence()
220
    {
221
        $this->object->setEvidence('adresar');
222
        $this->assertEquals('adresar', $this->object->evidence);
223
        $this->object->setPrefix('c');
224
        $this->object->debug = true;
225
        $this->object->setEvidence('fail');
226
    }
227
228
    /**
229
     * @covers FlexiPeeHP\FlexiBeeRO::setCompany
230
     */
231
    public function testSetCompany()
232
    {
233
        $this->object->setCompany('test_s_r_o_');
234
        $this->assertEquals('test_s_r_o_', $this->object->company);
235
    }
236
237
    /**
238
     * @covers FlexiPeeHP\FlexiBeeRO::object2array
239
     */
240
    public function testObject2array()
241
    {
242
        $this->assertNull($this->object->object2array(new \stdClass()));
0 ignored issues
show
Bug introduced by
The method assertNull() does not exist on Test\FlexiPeeHP\FlexiBeeROTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

242
        $this->/** @scrutinizer ignore-call */ 
243
               assertNull($this->object->object2array(new \stdClass()));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
243
        $this->assertEquals(
244
            [
245
            'item' => 1,
246
            'arrItem' => ['a', 'b' => 'c']
247
            ]
248
            , $this->object->object2array(new \Test\ObjectForTesting()));
249
    }
250
251
    /**
252
     * @covers FlexiPeeHP\FlexiBeeRO::objectToID
253
     */
254
    public function testObjectToID()
255
    {
256
        $this->object->setDataValue('kod', 'TEST');
257
        $this->assertEquals('code:TEST',
258
            $this->object->objectToID($this->object));
259
260
        $this->assertEquals('TEST', $this->object->objectToID('TEST'));
0 ignored issues
show
Bug introduced by
'TEST' of type string is incompatible with the type array|object expected by parameter $object of FlexiPeeHP\FlexiBeeRO::objectToID(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

260
        $this->assertEquals('TEST', $this->object->objectToID(/** @scrutinizer ignore-type */ 'TEST'));
Loading history...
261
    }
262
263
    /**
264
     * @covers FlexiPeeHP\FlexiBeeRO::performRequest
265
     */
266
    public function testPerformRequest()
267
    {
268
        $evidence = $this->object->getEvidence();
269
        switch ($evidence) {
270
            case null:
271
            case '':
272
            case 'c':
273
            case 'test':
274
            case 'status':
275
            case 'nastaveni':
276
                $this->object->performRequest(null, 'GET', 'xml');
277
                break;
278
279
            default:
280
                $this->object->performRequest(null, 'GET', 'json');
281
                $this->object->performRequest(null, 'GET', 'xml');
282
                break;
283
        }
284
285
        //404 Test
286
287
        $notFound = $this->object->performRequest('error404.json');
288
        if (array_key_exists('message', $notFound)) {
289
            $this->assertEquals('false', $notFound['success']);
290
        } else {
291
            echo '';
292
        }
293
    }
294
295
    /**
296
     * @covers FlexiPeeHP\FlexiBeeRO::rawResponseToArray
297
     */
298
    public function testRawResponseToArray()
299
    {
300
301
        $this->assertTrue(is_array(
302
                $this->object->rawResponseToArray($this->json, 'json')));
303
        $this->assertTrue(is_array(
304
                $this->object->rawResponseToArray($this->xml, 'xml')));
305
        $this->assertTrue(is_array(
306
                $this->object->rawResponseToArray('simpletext', 'txt')));
307
        $this->assertTrue(is_array(
308
                $this->object->rawResponseToArray('othertext', 'other')));
309
    }
310
311
    /**
312
     * @covers FlexiPeeHP\FlexiBeeRO::rawJsonToArray
313
     */
314
    public function testRawJsonToArray()
315
    {
316
        $this->assertNull($this->object->rawJsonToArray($this->json.'XXX'));
317
        $evidence    = $this->object->getResponseEvidence() ? $this->object->getResponseEvidence()
318
                : 'adresar';
319
        $arrayWeWant = [
320
            '@version' => '1.0',
321
            $evidence =>
322
            [
323
                [
324
                    'id' => '2574',
325
                    'kontakty' =>
326
                    [
327
                        ['id' => '299']
328
                    ]
329
                ]
330
            ]
331
        ];
332
        $this->assertEquals($arrayWeWant,
333
            $this->object->rawJsonToArray($this->json));
334
    }
335
336
    /**
337
     * @covers FlexiPeeHP\FlexiBeeRO::rawXmlToArray
338
     */
339
    public function testRawXmlToArray()
340
    {
341
        $evidence    = $this->object->getResponseEvidence() ? $this->object->getResponseEvidence()
342
                : 'adresar';
343
        $arrayWeWant = [
344
            '@version' => '1.0',
345
            $evidence =>
346
            [
347
                [
348
                    'id' => '2574',
349
                    'kontakty' =>
350
                    [
351
                        ['kontakt' => [
352
                                ['id' => '299']
353
                            ]
354
                        ]
355
                    ]
356
                ]
357
            ]
358
        ];
359
        $this->assertEquals($arrayWeWant,
360
            $this->object->rawXmlToArray($this->xml));
361
    }
362
363
    /**
364
     * @covers FlexiPeeHP\FlexiBeeRO::parseResponse
365
     */
366
    public function testParseResponse()
367
    {
368
        $this->object->parseResponse($this->object->rawJsonToArray($this->json),
369
            200);
370
    }
371
372
    /**
373
     * @covers FlexiPeeHP\FlexiBeeRO::doCurlRequest
374
     */
375
    public function testDoCurlRequest()
376
    {
377
        $this->object->doCurlRequest(constant('FLEXIBEE_URL'), 'GET');
378
    }
379
380
    /**
381
     * @covers FlexiPeeHP\FlexiBeeRO::setAction
382
     */
383
    public function testSetAction()
384
    {
385
        switch ($this->object->getEvidence()) {
386
            case '':
387
            case 'c':
388
            case 'hooks':
389
            case 'status':
390
            case 'changes':
391
            case 'nastaveni':
392
            case 'evidence-list':
393
                $this->object->setAction('none');
394
                break;
395
            default:
396
                $this->assertTrue($this->object->setAction('new'));
397
                $this->object->actionsAvailable = [];
398
                $this->assertFalse($this->object->setAction('none'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not exist on Test\FlexiPeeHP\FlexiBeeROTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

398
                $this->/** @scrutinizer ignore-call */ 
399
                       assertFalse($this->object->setAction('none'));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
399
                $this->object->actionsAvailable = ['copy'];
400
                $this->assertFalse($this->object->setAction('none'));
401
                break;
402
        }
403
    }
404
405
    /**
406
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidence
407
     */
408
    public function testGetEvidence()
409
    {
410
        $this->assertEquals($this->object->evidence,
411
            $this->object->getEvidence());
412
    }
413
414
    /**
415
     * @covers FlexiPeeHP\FlexiBeeRO::getCompany
416
     */
417
    public function testGetCompany()
418
    {
419
        $this->assertEquals($this->object->company, $this->object->getCompany());
420
    }
421
422
    /**
423
     * @covers FlexiPeeHP\FlexiBeeRO::getResponseEvidence
424
     */
425
    public function testGetResponseEvidence()
426
    {
427
        $responseEvidence = $this->object->getResponseEvidence();
428
        switch ($this->object->getEvidence()) {
429
            case '':
430
            case 'c':
431
            case 'hooks':
432
            case 'status':
433
            case 'changes':
434
            case 'nastaveni':
435
            case 'evidence-list':
436
                break;
437
            default:
438
                $this->assertEquals($this->object->getEvidence(),
439
                    $responseEvidence);
440
                break;
441
        }
442
    }
443
444
    /**
445
     * @covers FlexiPeeHP\FlexiBeeRO::getLastInsertedId
446
     * @depends testInsertToFlexiBee
447
     */
448
    public function testGetLastInsertedId()
449
    {
450
        $this->assertNotEmpty($this->object->getLastInsertedId());
0 ignored issues
show
Bug introduced by
The method getLastInsertedId() does not exist on FlexiPeeHP\FlexiBeeRO. It seems like you code against a sub-type of FlexiPeeHP\FlexiBeeRO such as FlexiPeeHP\FlexiBeeRW. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

450
        $this->assertNotEmpty($this->object->/** @scrutinizer ignore-call */ getLastInsertedId());
Loading history...
451
    }
452
453
    /**
454
     * @covers FlexiPeeHP\FlexiBeeRO::xml2array
455
     */
456
    public function testXml2array()
457
    {
458
        $arrayWeWant = [
459
            '@version' => '1.0',
460
            'adresar' =>
461
            [
462
                [
463
                    'id' => '2574',
464
                    'kontakty' =>
465
                    [
466
                        ['kontakt' => [
467
                                ['id' => '299']
468
                            ]
469
                        ]
470
                    ]
471
                ]
472
            ]
473
        ];
474
475
        $this->assertEquals($arrayWeWant, $this->object->xml2array($this->xml));
476
    }
477
478
    /**
479
     * @covers FlexiPeeHP\FlexiBeeRO::extractUrlParams
480
     */
481
    public function testExtractUrlParams()
482
    {
483
        $conditions = ['id' => 23, 'limit' => 10];
484
        $this->object->extractUrlParams($conditions, $urlParams);
485
        $this->assertEquals(['id' => 23], $conditions);
486
        $this->assertEquals(['limit' => 10], $urlParams);
487
    }
488
489
    /**
490
     * @covers FlexiPeeHP\FlexiBeeRO::urlEncode
491
     */
492
    public function testUrlEncode()
493
    {
494
        $this->assertEquals("stitky%3D'code:VIP'%20or%20stitky%3D'code:DULEZITE'",
495
            FlexiBeeRO::urlEncode("stitky='code:VIP' or stitky='code:DULEZITE'"));
496
    }
497
498
    /**
499
     * @covers FlexiPeeHP\FlexiBeeRO::getAllFromFlexibee
500
     */
501
    public function testGetAllFromFlexibee()
502
    {
503
        $this->object->getAllFromFlexibee();
504
    }
505
506
    /**
507
     * @covers FlexiPeeHP\FlexiBeeRO::disconnect
508
     *
509
     * @depends testPerformRequest
510
     * @depends testLoadFlexiData
511
     * @depends testGetFlexiRow
512
     * @depends testGetFlexiData
513
     * @depends testLoadFromFlexiBee
514
     * @depends testInsertToFlexiBee
515
     * @depends testIdExists
516
     * @depends testRecordExists
517
     * @depends testGetColumnsFromFlexibee
518
     * @depends testSearchString
519
     */
520
    public function testDisconnect()
521
    {
522
        $this->object->disconnect();
523
        $this->assertNull($this->object->curl);
524
    }
525
526
    /**
527
     * @covers FlexiPeeHP\FlexiBeeRO::__destruct
528
     * @depends testDisconnect
529
     */
530
    public function testdestruct()
531
    {
532
        $this->markTestSkipped();
533
    }
534
535
    /**
536
     * @covers FlexiPeeHP\FlexiBeeRO::getFlexiRow
537
     */
538
    public function testGetFlexiRow()
539
    {
540
        $this->object->getFlexiRow(0);
541
        $this->object->getFlexiRow(1);
542
    }
543
544
    /**
545
     * @covers FlexiPeeHP\FlexiBeeRO::getFlexiData
546
     */
547
    public function testGetFlexiData()
548
    {
549
        $evidence = $this->object->getEvidence();
550
        switch ($evidence) {
551
            case null:
552
                $this->object->getFlexiData();
553
                break;
554
            case 'c':
555
                $this->object->evidence  = 'c';
556
                $this->object->prefix    = '';
557
                $this->object->company   = '';
558
                $this->object->nameSpace = 'companies';
559
                $flexidata               = $this->object->getFlexiData();
560
                $this->assertArrayHasKey('company', $flexidata);
561
                break;
562
            case 'evidence-list':
563
                $flexidata               = $this->object->getFlexiData(null,
564
                    ['detail' => 'id']);
565
                $this->assertArrayHasKey('evidenceType', $flexidata[0]);
566
                break;
567
568
            default:
569
                $flexidata = $this->object->getFlexiData(null,
570
                    ['detail' => 'id']);
571
572
                if (is_array($flexidata)) {
0 ignored issues
show
introduced by
The condition is_array($flexidata) is always true.
Loading history...
573
                    if (count($flexidata)) {
574
                        $this->markTestSkipped('Empty evidence');
575
                    } else {
576
                        $this->assertArrayHasKey(0, $flexidata);
577
578
                        $this->assertArrayHasKey('id', $flexidata[0]);
579
                        $filtrered = $this->object->getFlexiData(null,
580
                            ["id = ".$flexidata[0]['id'], 'detail' => 'full']);
581
                        $this->assertArrayHasKey(0, $filtrered);
582
                        $this->assertArrayHasKey('id', $filtrered[0]);
583
                    }
584
                }
585
                break;
586
        }
587
    }
588
589
    /**
590
     * @covers FlexiPeeHP\FlexiBeeRO::loadFromFlexiBee
591
     */
592
    public function testLoadFromFlexiBee()
593
    {
594
        $this->object->loadFromFlexiBee();
595
        $this->object->loadFromFlexiBee(222);
596
    }
597
598
    /**
599
     * @covers FlexiPeeHP\FlexiBeeRO::getJsonizedData
600
     */
601
    public function testGetJsonizedData()
602
    {
603
        $this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"}}}',
604
            $this->object->getJsonizedData(['key' => 'value']));
605
606
        switch ($this->object->getEvidence()) {
607
            case '':
608
            case 'c':
609
            case 'hooks':
610
            case 'status':
611
            case 'changes':
612
            case 'nastaveni':
613
            case 'evidence-list':
614
                $this->object->getJsonizedData(['key' => 'value']);
615
                break;
616
            default:
617
                $this->object->setAction('copy');
618
                $this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"},"'.$this->object->evidence.'@action":"copy"}}',
619
                    $this->object->getJsonizedData(['key' => 'value']));
620
621
                $this->object->action = 'storno';
0 ignored issues
show
Bug introduced by
The property action is declared protected in FlexiPeeHP\FlexiBeeRO and cannot be accessed from this context.
Loading history...
622
                $this->object->filter = "stavUhrK = 'stavUhr.uhrazeno'";
623
                $this->object->getJsonizedData([]);
624
                break;
625
        }
626
    }
627
628
    /**
629
     * @covers FlexiPeeHP\FlexiBeeRO::getDataForJSON
630
     */
631
    public function testGetDataForJson()
632
    {
633
        $this->object->getDataForJSON();
634
    }
635
636
    /**
637
     * @covers FlexiPeeHP\FlexiBeeRO::idExists
638
     */
639
    public function testIdExists()
640
    {
641
        $this->assertFalse($this->object->idExists('nonexistent'));
642
        switch ($this->object->getEvidence()) {
643
            case '':
644
            case 'c':
645
            case 'hooks':
646
            case 'status':
647
            case 'changes':
648
            case 'nastaveni':
649
            case 'evidence-list':
650
                break;
651
            default:
652
                $first = $this->object->getColumnsFromFlexibee(['id'],
653
                    ['limit' => 1], 'id');
654
                if (empty($first)) {
655
                    $this->markTestSkipped('empty evidence ?');
656
                } else {
657
                    $this->object->setData($first);
658
                    $this->assertTrue($this->object->idExists());
659
                }
660
                break;
661
        }
662
    }
663
664
    /**
665
     * @covers FlexiPeeHP\FlexiBeeRO::getRecordID
666
     */
667
    public function testGetRecordID()
668
    {
669
        $this->object->setData([$this->object->getKeyColumn() => 10]);
670
        $this->assertEquals(10, $this->object->getRecordID());
671
    }
672
673
    /**
674
     * @covers FlexiPeeHP\FlexiBeeRO::getRecordIdent
675
     */
676
    public function testGetRecordIdent()
677
    {
678
        $this->object->dataReset();
679
        $this->assertNull($this->object->getRecordIdent());
680
681
        $this->object->setMyKey(20);
682
        $this->assertEquals(20, $this->object->getRecordIdent());
683
684
        $this->object->setDataValue('kod', 'test');
685
        $this->assertEquals('code:TEST', $this->object->getRecordIdent());
686
687
        $this->object->setDataValue('external-ids', ['ext:test:10']);
688
        $this->assertEquals('ext:test:10', $this->object->getRecordIdent());
689
    }
690
691
    /**
692
     * @covers FlexiPeeHP\FlexiBeeRO::recordExists
693
     */
694
    public function testRecordExists()
695
    {
696
        $evidence = $this->object->getEvidence();
697
698
        switch ($evidence) {
699
            case null:
700
            case 'c':
701
            case 'status':
702
            case 'evidence-list':
703
                $this->object->recordExists();
704
                break;
705
706
            default:
707
                $flexidata = $this->object->getFlexiData(null,
708
                    ['limit' => 1, 'detail' => 'id']);
709
                if (is_array($flexidata) && !count($flexidata)) {
710
                    $this->assertFalse($this->object->recordExists(['id' => 1]),
711
                        'Record ID 1 exists in empty evidence ?');
712
                } else {
713
                    if (!is_null($flexidata)) {
714
                        $this->object->setData(['id' => (int) $flexidata[0]['id']]);
715
                        $this->assertTrue($this->object->recordExists(),
716
                            'First record exists test failed');
717
                        $this->assertFalse($this->object->recordExists(['id' => 0]),
718
                            'Record ID 0 exists');
719
                        $this->assertFalse($this->object->recordExists(['unexistent' => 1]),
720
                            'Unexistent Record exist ?');
721
                    }
722
                }
723
                break;
724
        }
725
    }
726
727
    /**
728
     * @covers FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee
729
     */
730
    public function testGetColumnsFromFlexibee()
731
    {
732
733
        switch ($this->object->getEvidence()) {
734
            case '':
735
            case 'c':
736
            case 'hooks':
737
            case 'status':
738
            case 'changes':
739
            case 'nastaveni':
740
            case 'evidence-list':
741
                break;
742
            default:
743
                $this->object->getColumnsFromFlexibee(['id', 'kod'],
744
                    ['limit' => 1], 'id');
745
                $this->object->getColumnsFromFlexibee('summary', ['limit' => 1],
0 ignored issues
show
Bug introduced by
'summary' of type string is incompatible with the type string[] expected by parameter $columnsList of FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

745
                $this->object->getColumnsFromFlexibee(/** @scrutinizer ignore-type */ 'summary', ['limit' => 1],
Loading history...
746
                    'id');
747
748
                break;
749
        }
750
    }
751
752
    /**
753
     * @covers FlexiPeeHP\FlexiBeeRO::getExternalID
754
     */
755
    public function testGetExternalID()
756
    {
757
        $this->assertTrue(empty($this->object->getExternalID('ext:test:10'))); //ext: does not exist
758
759
        $this->object->setDataValue('external-ids',
760
            ['ext:doe:22', 'ext:test:10']);
761
762
        $this->assertEquals('ext:doe:22', $this->object->getExternalID());
763
        $this->assertEquals('10', $this->object->getExternalID('test'));
764
    }
765
766
    /**
767
     * @covers FlexiPeeHP\FlexiBeeRO::getGlobalVersion
768
     */
769
    public function testGetGlobalVersion()
770
    {
771
        switch ($this->object->getEvidence()) {
772
            case '':
773
            case 'c':
774
            case 'hooks':
775
            case 'status':
776
            case 'changes':
777
            case 'nastaveni':
778
            case 'evidence-list':
779
                $this->object->getGlobalVersion();
780
                break;
781
            default:
782
                $this->assertInternalType("int",
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not exist on Test\FlexiPeeHP\FlexiBeeROTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

782
                $this->/** @scrutinizer ignore-call */ 
783
                       assertInternalType("int",

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
783
                    $this->object->getGlobalVersion(),
784
                    'error obtaining of GlobalVersion');
785
                break;
786
        }
787
    }
788
789
    /**
790
     * @covers FlexiPeeHP\FlexiBeeRO::getApiURL
791
     */
792
    public function testGetApiUrl()
793
    {
794
        $evidence = $this->object->getEvidence();
795
        if ($evidence) {
796
            $url = $this->object->url.'/c/'.constant('FLEXIBEE_COMPANY').'/'.$evidence;
797
        } else {
798
            $url = $this->object->url.'/c/'.constant('FLEXIBEE_COMPANY');
799
        }
800
801
        $this->assertEquals($url, $this->object->getApiURL());
802
        $this->assertEquals($url.'.html', $this->object->getApiURL('html'));
803
        $this->assertEquals($url.'.xml', $this->object->getApiURL('xml'));
804
    }
805
806
    /**
807
     * @covers FlexiPeeHP\FlexiBeeRO::getResponseFormat
808
     */
809
    public function testGetResponseFormat()
810
    {
811
        $this->object->performRequest(null, 'GET', 'json');
812
        $this->assertEquals('application/json',
813
            $this->object->getResponseFormat());
814
        $this->object->performRequest(null, 'GET', 'xml');
815
        $this->assertEquals('application/xml',
816
            $this->object->getResponseFormat());
817
        unset($this->object->curlInfo['content_type']);
818
        $this->assertNull($this->object->getResponseFormat());
819
    }
820
821
    /**
822
     * @covers FlexiPeeHP\FlexiBeeRO::getKod
823
     */
824
    public function testGetKod()
825
    {
826
        $testString = [];
827
        $this->assertEquals('code:CODE',
828
            $this->object->getKod([$this->object->keyColumn => 'code']));
829
830
        $testString[$this->object->nameColumn] = 'Fish clamp -  Úchytka pro instalaci samonosných kabelů '
831
            .'(3.5 mm)';
832
        $code0                                 = $this->object->getKod($testString);
833
        $this->assertEquals('code:FISHCLAMPUCHYTKAPR', $code0);
834
        $code1                                 = $this->object->getKod($testString,
835
            false);
836
        $this->assertEquals('code:FISHCLAMPUCHYTKAPR', $code1);
837
        $code2                                 = $this->object->getKod($testString);
838
        $this->assertEquals('code:FISHCLAMPUCHYTKAPR1', $code2);
839
        $this->object->setData($testString);
840
        $code3                                 = $this->object->getKod();
841
        $this->assertEquals('code:FISHCLAMPUCHYTKAPR2', $code3);
842
843
        $this->assertEquals('code:TEST',
844
            $this->object->getKod([$this->object->nameColumn => 'test']));
845
846
        $this->assertEquals('code:TEST1', $this->object->getKod('test'));
847
848
        $this->assertEquals('code:TEST2',
849
            $this->object->getKod(['kod' => 'test']));
850
        $this->assertEquals('code:NOTSET', $this->object->getKod(['kod' => '']));
851
    }
852
853
    /**
854
     * @covers FlexiPeeHP\FlexiBeeRO::logResult
855
     */
856
    public function testLogResult()
857
    {
858
        $this->object->cleanMessages();
859
        $success = json_decode('{"winstrom":{"@version":"1.0","success":"true",'
860
            .'"stats":{"created":"0","updated":"1","deleted":"0","skipped":"0"'
861
            .',"failed":"0"},"results":[{"id":"1","request-id":"ext:SōkoMan.item'
862
            .':5271","ref":"/c/spoje_net_s_r_o_1/skladovy-pohyb/1.json"}]}}');
863
        $this->object->logResult(current($this->object->object2array($success)),
864
            'http://test');
865
866
        $this->assertArrayHasKey('info', $this->object->getStatusMessages(true));
867
868
        $error                          = json_decode('{"winstrom":{"@version":"1.0","success":"false",'
869
            .'"stats":{"created":"0","updated":"0","deleted":"0","skipped":"0"'
870
            .',"failed":"0"},"results":[{"errors":[{"message":"cz.winstrom.'
871
            .'service.WSBusinessException: Zadaný kód není unikátní.\nZadaný'
872
            .' kód není unikátní."}]}]}}');
873
        $this->object->lastResponseCode = 500;
874
        $this->object->logResult(current($this->object->object2array($error)));
875
        $this->assertArrayHasKey('error', $this->object->getStatusMessages(true));
876
    }
877
878
    /**
879
     * @covers FlexiPeeHP\FlexiBeeRO::flexiUrl
880
     */
881
    public function testFlexiUrl()
882
    {
883
        $this->assertEquals("a eq '1' and b eq 'foo'",
884
            $this->object->flexiUrl(['a' => 1, 'b' => 'foo'], 'and'));
885
        $this->assertEquals("a eq '1' or b eq 'bar'",
886
            $this->object->flexiUrl(['a' => 1, 'b' => 'bar'], 'or'));
887
        $this->assertEquals("a eq true or b eq false",
888
            $this->object->flexiUrl(['a' => true, 'b' => false], 'or'));
889
        $this->assertEquals("a is null and b is not null",
890
            $this->object->flexiUrl(['a' => null, 'b' => '!null'], 'and'));
891
892
        $begin = new \DateTime('2018-08-01');
893
        $end   = new \DateTime('2018-08-31');
894
        $end   = $end->modify('+1 day');
895
896
        $interval  = new \DateInterval('P1D');
897
        $daterange = new \DatePeriod($begin, $interval, $end);
898
899
        $this->assertEquals("a eq '2018-10-25' and b between '2018-08-01' '2018-09-01'",
900
            $this->object->flexiUrl(['a' => new \DateTime('25-10-2018'), 'b' => $daterange]));
901
    }
902
903
    /**
904
     * @covers FlexiPeeHP\FlexiBeeRO::unifyResponseFormat
905
     */
906
    public function testunifyResponseFormat()
907
    {
908
        $this->assertNull($this->object->unifyResponseFormat(null));
909
        //One Row Test
910
911
        $responseEvidence = $this->object->getResponseEvidence();
912
        if (empty($responseEvidence)) {
913
            $responseEvidence       = $this->object->evidence = 'test';
914
        }
915
916
        $test1raw = [$responseEvidence =>
917
            ['id' => 1, 'name' => 'value']
918
        ];
919
920
        $test1expected = [$responseEvidence =>
921
            [
922
                ['id' => 1, 'name' => 'value']
923
            ]
924
        ];
925
926
        $this->assertEquals($test1expected,
927
            $this->object->unifyResponseFormat($test1raw));
928
929
        //Two Row Test
930
        $test2Raw = [$this->object->getResponseEvidence() =>
931
            [
932
                ['id' => 1, 'name' => 'value'],
933
                ['id' => 2, 'name' => 'value2']
934
            ]
935
        ];
936
937
        $test2expected = [$this->object->getResponseEvidence() =>
938
            [
939
                ['id' => 1, 'name' => 'value'],
940
                ['id' => 2, 'name' => 'value2']
941
            ]
942
        ];
943
944
        $this->assertEquals($test2expected,
945
            $this->object->unifyResponseFormat($test2Raw));
946
    }
947
948
    /**
949
     * @covers FlexiPeeHP\FlexiBeeRO::__toString
950
     */
951
    public function testtoString()
952
    {
953
        $id = '123';
954
        $this->object->setMyKey($id);
955
        $this->assertEquals($id, (string) $this->object);
956
957
        $this->object->setDataValue('kod', 'test');
958
        $this->assertEquals('code:TEST', (string) $this->object);
959
960
        $identifer = 'ext:test:123';
961
        $this->object->setMyKey($identifer);
962
        $this->assertEquals($identifer, (string) $this->object);
963
964
        $this->object->dataReset();
965
        $this->assertEquals('', $this->object->__toString());
966
    }
967
968
    /**
969
     * @covers FlexiPeeHP\FlexiBeeRO::draw
970
     */
971
    public function testDraw($whatWant = NULL)
972
    {
973
        $this->object->setDataValue('kod', 'test');
974
        $this->assertEquals('code:TEST', $this->object->draw());
975
    }
976
977
    /**
978
     * @covers FlexiPeeHP\FlexiBeeRO::getColumnsInfo
979
     */
980
    public function testgetColumnsInfo()
981
    {
982
        switch ($this->object->getEvidence()) {
983
            case '':
984
            case 'c':
985
            case 'hooks':
986
            case 'status':
987
            case 'changes':
988
            case 'evidence-list':
989
                $this->assertNull($this->object->getColumnsInfo());
990
                break;
991
            default:
992
                $this->assertNotEmpty($this->object->getColumnsInfo(),
993
                    'Cannot obtain structure for '.$this->object->getEvidence());
994
                break;
995
        }
996
    }
997
998
    /**
999
     * @covers FlexiPeeHP\FlexiBeeRO::getActionsInfo
1000
     */
1001
    public function testgetActionsInfo()
1002
    {
1003
        switch ($this->object->getEvidence()) {
1004
            case '':
1005
            case 'c':
1006
            case 'hooks':
1007
            case 'status':
1008
            case 'changes':
1009
            case 'nastaveni':
1010
            case 'evidence-list':
1011
                $this->assertNull($this->object->getActionsInfo());
1012
                $this->assertNotEmpty($this->object->getActionsInfo('faktura-vydana'),
1013
                    'Cannot obtain actions for na evidence');
1014
                break;
1015
            default:
1016
                $this->assertNotEmpty($this->object->getActionsInfo(),
1017
                    'Cannot obtain actions for '.$this->object->getEvidence());
1018
                break;
1019
        }
1020
    }
1021
1022
    /**
1023
     * @covers FlexiPeeHP\FlexiBeeRO::getRelationsInfo
1024
     */
1025
    public function testgetRelationsInfo()
1026
    {
1027
        switch ($this->object->getEvidence()) {
1028
            case '':
1029
            case 'c':
1030
            case 'hooks':
1031
            case 'status':
1032
            case 'changes':
1033
            case 'nastaveni':
1034
            case 'strom-cenik':
1035
            case 'ucetni-obdobi':
1036
            case 'evidence-list':
1037
                $this->assertNull($this->object->getRelationsInfo());
1038
                break;
1039
            default:
1040
                $this->assertNotEmpty($this->object->getRelationsInfo(),
1041
                    'Cannot obtain relations for '.$this->object->getEvidence());
1042
                break;
1043
        }
1044
    }
1045
1046
    /**
1047
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceUrl
1048
     */
1049
    public function testgetEvidenceUrl()
1050
    {
1051
        $this->assertNotEmpty($this->object->getEvidenceUrl());
1052
        $this->assertNotEmpty($this->object->getEvidenceUrl('/properties'));
0 ignored issues
show
Unused Code introduced by
The call to FlexiPeeHP\FlexiBeeRO::getEvidenceURL() has too many arguments starting with '/properties'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1052
        $this->assertNotEmpty($this->object->/** @scrutinizer ignore-call */ getEvidenceUrl('/properties'));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1053
    }
1054
1055
    /**
1056
     * @covers FlexiPeeHP\FlexiBeeRO::evidenceToClassName
1057
     */
1058
    public function testevidenceToClassName()
1059
    {
1060
        $this->assertEquals('FakturaVydana',
1061
            $this->object->evidenceToClassName('faktura-vydana'));
1062
    }
1063
1064
    /**
1065
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceInfo
1066
     */
1067
    public function testGetEvidenceInfo()
1068
    {
1069
        $eInfo = $this->object->getEvidenceInfo();
1070
        switch ($this->object->getEvidence()) {
1071
            case '':
1072
            case 'c':
1073
            case 'hooks':
1074
            case 'status':
1075
            case 'changes':
1076
            case 'nastaveni':
1077
            case 'evidence-list':
1078
                break;
1079
            default:
1080
                $this->assertArrayHasKey('evidencePath', $eInfo);
1081
                break;
1082
        }
1083
    }
1084
1085
    /**
1086
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceName
1087
     */
1088
    public function testGetEvidenceName()
1089
    {
1090
        $evidenceName = $this->object->getEvidenceName();
1091
        switch ($this->object->getEvidence()) {
1092
            case '':
1093
            case 'c':
1094
            case 'hooks':
1095
            case 'status':
1096
            case 'changes':
1097
            case 'nastaveni':
1098
            case 'evidence-list':
1099
                break;
1100
            default:
1101
                $this->assertNotEmpty($evidenceName);
1102
                break;
1103
        }
1104
    }
1105
1106
    /**
1107
     * @covers FlexiPeeHP\FlexiBeeRO::saveResponseToFile
1108
     */
1109
    public function testSaveResponseToFile()
1110
    {
1111
        $tmp = sys_get_temp_dir().'/'.tmpfile();
0 ignored issues
show
Bug introduced by
Are you sure tmpfile() of type false|resource can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1111
        $tmp = sys_get_temp_dir().'/'./** @scrutinizer ignore-type */ tmpfile();
Loading history...
1112
        $this->object->saveResponseToFile($tmp);
1113
        $this->assertFileExists($tmp);
0 ignored issues
show
Bug introduced by
The method assertFileExists() does not exist on Test\FlexiPeeHP\FlexiBeeROTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1113
        $this->/** @scrutinizer ignore-call */ 
1114
               assertFileExists($tmp);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1114
    }
1115
1116
    /**
1117
     * @covers FlexiPeeHP\FlexiBeeRO::getFirstRecordID()
1118
     */
1119
    public function testgetFirstRecordID()
1120
    {
1121
        $this->object->getFirstRecordID();
1122
        switch ($this->object->getEvidence()) {
1123
            case '':
1124
            case 'c':
1125
            case 'hooks':
1126
            case 'status':
1127
            case 'changes':
1128
            case 'nastaveni':
1129
            case 'evidence-list':
1130
                break;
1131
            default:
1132
                break;
1133
        }
1134
    }
1135
1136
    /**
1137
     * @covers FlexiPeeHP\FlexiBeeRO::getVazby
1138
     * @expectedException \Exception
1139
     */
1140
    public function testGetVazby()
1141
    {
1142
        switch ($this->object->getEvidence()) {
1143
            case '':
1144
            case 'c':
1145
            case 'hooks':
1146
            case 'status':
1147
            case 'changes':
1148
            case 'nastaveni':
1149
            case 'evidence-list':
1150
                break;
1151
            default:
1152
                $this->object->getVazby($this->object->getMyKey());
1153
                break;
1154
        }
1155
        $this->object->getVazby();
1156
    }
1157
1158
    /**
1159
     * @covers FlexiPeeHP\FlexiBeeRO::evidenceUrlWithSuffix
1160
     */
1161
    public function testEvidenceUrlWithSuffix()
1162
    {
1163
        $urlraw = $this->object->getEvidenceURL();
1164
        $lala   = $this->object->evidenceUrlWithSuffix('lala');
1165
        $this->assertEquals($urlraw.'/lala', $lala);
1166
        $lolo   = $this->object->evidenceUrlWithSuffix('?lele');
1167
        $this->assertEquals($urlraw.'?lele', $lolo);
1168
        $lulu   = $this->object->evidenceUrlWithSuffix(';lulu');
1169
        $this->assertEquals($urlraw.';lulu', $lulu);
1170
    }
1171
1172
    /**
1173
     * @covers FlexiPeeHP\FlexiBeeRO::join
1174
     * @expectedException \Ease\Exception
1175
     */
1176
    public function testJoin()
1177
    {
1178
        $ada = new FlexiBeeRO(['id' => 'A'], ['evidence' => 'adresar']);
1179
        $adb = new FlexiBeeRO(['id' => 'B'], ['evidence' => 'adresar']);
1180
        $this->assertTrue($this->object->join($ada));
1181
        $this->assertTrue($this->object->join($adb));
1182
        $ads = new \stdClass();
1183
        $this->object->join($ads);
0 ignored issues
show
Bug introduced by
$ads of type stdClass is incompatible with the type FlexiPeeHP\FlexiBeeRO expected by parameter $object of FlexiPeeHP\FlexiBeeRO::join(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1183
        $this->object->join(/** @scrutinizer ignore-type */ $ads);
Loading history...
1184
    }
1185
1186
    /**
1187
     * @covers FlexiPeeHP\FlexiBeeRO::addDefaultUrlParams
1188
     */
1189
    public function testAddDefaultUrlParams()
1190
    {
1191
        $this->object->defaultUrlParams       = [];
1192
        $this->assertEquals('http://vitexsoftware.cz?a=b',
1193
            $this->object->addDefaultUrlParams('http://vitexsoftware.cz?a=b'));
1194
        $this->object->defaultUrlParams['id'] = 1;
1195
        $this->assertEquals('http://vitexsoftware.cz/path?id=1&a=b',
1196
            $this->object->addDefaultUrlParams('http://vitexsoftware.cz/path?a=b'));
1197
    }
1198
1199
    public function testFlexiDateToDateTime()
1200
    {
1201
        $this->assertEquals(1495749600,
1202
            FlexiBeeRO::flexiDateToDateTime('2017-05-26+02:00')->getTimestamp());
1203
    }
1204
1205
    public function testFlexiDateTimeToDateTime()
1206
    {
1207
        $this->assertEquals(1506412853,
1208
            FlexiBeeRO::flexiDateTimeToDateTime('2017-09-26T10:00:53.755+02:00')->getTimestamp());
1209
    }
1210
1211
    /**
1212
     * @covers FlexiPeeHP\FlexiBeeRO::takeData
1213
     */
1214
    public function testTakeData()
1215
    {
1216
        $this->object->takeData(['id' => 1]);
1217
        $this->assertEquals(constant('FLEXIBEE_URL').'/'.constant('FLEXIBEE_COMPANY').'/1',
1218
            $this->object->getApiURL());
1219
1220
        $this->object->dataReset();
1221
        $this->object->takeData(['kod' => 'test']);
1222
        $this->assertEquals(constant('FLEXIBEE_URL').'/'.constant('FLEXIBEE_COMPANY').'/code:TEST',
1223
            $this->object->getApiURL());
1224
    }
1225
1226
    /**
1227
     * @covers FlexiPeeHP\FlexiBeeRO::setDataValue
1228
     */
1229
    public function testSetDataValue()
1230
    {
1231
        if (!empty($this->object->getColumnsInfo())) {
1232
            $this->object->setDataValue('datVyst', new \DateTime());
1233
        }
1234
        $this->object->setDataValue('test', 'test');
1235
        $this->object->setDataValue('kod', 'code:testKOD');
1236
        $this->assertEquals('testKOD', $this->object->getDataValue('kod'));
1237
    }
1238
1239
    /**
1240
     * @covers FlexiPeeHP\FlexiBeeRO::saveDebugFiles
1241
     */
1242
    public function testSaveDebugFiles()
1243
    {
1244
        $this->object->saveDebugFiles();
1245
    }
1246
1247
    /**
1248
     * @covers FlexiPeeHP\FlexiBeeRO::setPostFields
1249
     * @covers FlexiPeeHP\FlexiBeeRO::getPostFields
1250
     */
1251
    public function testSetPostFields()
1252
    {
1253
        $this->object->setPostFields('test');
1254
        $this->assertEquals($this->object->getPostFields(), 'test');
1255
    }
1256
1257
    /**
1258
     * PHP Date object to FlexiBee date format test
1259
     * 
1260
     * @covers FlexiPeeHP\FlexiBeeRO::dateToFlexiDate
1261
     */
1262
    public function testDateToFlexiDate()
1263
    {
1264
        $dater = new \DateTime();
1265
        $this->assertEquals($dater->format(FlexiBeeRO::$DateFormat),
1266
            FlexiBeeRO::dateToFlexiDate($dater));
1267
    }
1268
1269
    /**
1270
     * PHP Date object to FlexiBee dateTime format test
1271
     * 
1272
     * @covers FlexiPeeHP\FlexiBeeRO::dateToFlexiDateTime
1273
     */
1274
    public function testDateToFlexiDateTime()
1275
    {
1276
        $dater = new \DateTime();
1277
        $this->assertEquals($dater->format(FlexiBeeRO::$DateTimeFormat),
1278
            FlexiBeeRO::dateToFlexiDateTime($dater));
1279
    }
1280
1281
    public function testSetFilter()
1282
    {
1283
        $this->object->setFilter('X');
1284
        $this->object->setFilter(['a' => 'b']);
1285
    }
1286
1287
    /**
1288
     * @covers FlexiPeeHP\FlexiBeeRO::getColumnInfo
1289
     */
1290
    public function testGetColumnInfo()
1291
    {
1292
        $this->object->getColumnInfo('id');
1293
    }
1294
1295
    /**
1296
     * @covers FlexiPeeHP\FlexiBeeRO::getFlexiBeeURL
1297
     */
1298
    public function testGetFlexiBeeURL()
1299
    {
1300
        $this->object->getFlexiBeeURL();
1301
    }
1302
1303
    /**
1304
     * @covers FlexiPeeHP\FlexiBeeRO::error500Reporter
1305
     */
1306
    public function testError500Reporter()
1307
    {
1308
        $this->object->reportRecipient = '[email protected]';
1309
        $this->object->error500Reporter(['success' => 'false', 'message' => 'test']);
1310
    }
1311
1312
    /**
1313
     * @covers FlexiPeeHP\FlexiBeeRO::setMyKey
1314
     */
1315
    public function testSetMyKey()
1316
    {
1317
        $this->object->setMyKey(1);
1318
    }
1319
1320
    /**
1321
     * @covers FlexiPeeHP\FlexiBeeRO::ignore404
1322
     */
1323
    public function testIgnore404()
1324
    {
1325
        $this->object->ignore404(true);
1326
        $this->assertTrue($this->object->ignore404());
1327
    }
1328
1329
    /**
1330
     * @covers FlexiPeeHP\FlexiBeeRO::sendByMail
1331
     */
1332
    public function testSendByMail()
1333
    {
1334
        $this->object->sendByMail($this->object->reportRecipient, 'test',
1335
            'test body');
1336
    }
1337
1338
    /**
1339
     * @covers FlexiPeeHP\FlexiBeeRO::sendUnsent
1340
     */
1341
    public function testSendUnsent()
1342
    {
1343
        $this->object->sendUnsent();
1344
    }
1345
1346
    /**
1347
     * @expectedException        Ease\Exception
1348
     * @expectedExceptionMessage Unknown language ua for PDF export
1349
     * @covers FlexiPeeHP\FlexiBeeRO::getInFormat
1350
     */
1351
    public function testGetInFormat()
1352
    {
1353
        $this->object->evidence = 'test';
1354
        $this->object->getInFormat('html', 'test');
1355
        $this->object->getInFormat('pdf', 'test');
1356
        $this->object->getInFormat('pdf', 'test', 'cs', true);
1357
        $this->object->getInFormat('pdf', 'error', 'ua', false);
1358
    }
1359
1360
    /**
1361
     * @covers FlexiPeeHP\FlexiBeeRO::downloadInFormat
1362
     */
1363
    public function testDownloadInFormat()
1364
    {
1365
        $this->object->downloadInFormat('pdf', sys_get_temp_dir().'/');
1366
    }
1367
1368
    /**
1369
     * @covers FlexiPeeHP\FlexiBeeRO::getReportsInfo
1370
     */
1371
    public function testGetReportsInfo()
1372
    {
1373
        $result = $this->object->getReportsInfo();
1374
        switch ($this->object->getEvidence()) {
1375
            case '':
1376
            case 'c':
1377
            case 'hooks':
1378
            case 'status':
1379
            case 'changes':
1380
            case 'evidence-list':
1381
                break;
1382
            default:
1383
                $this->assertNotEmpty($result,
1384
                    'Cannot obtain reports for '.$this->object->getEvidence());
1385
                break;
1386
        }
1387
    }
1388
1389
    /**
1390
     * @covers FlexiPeeHP\FlexiBeeRO::code
1391
     */
1392
    public function testCode()
1393
    {
1394
        $this->assertEquals('code:TEST', FlexiBeeRO::code('test'));
1395
    }
1396
1397
    /**
1398
     * @covers FlexiPeeHP\FlexiBeeRO::uncode
1399
     */
1400
    public function testUncode()
1401
    {
1402
        $this->assertEquals('test', FlexiBeeRO::uncode('code:test'));
1403
    }
1404
1405
    /**
1406
     * @covers FlexiPeeHP\FlexiBeeRO::arrayCleanUP
1407
     */
1408
    public function testArrayCleanUP()
1409
    {
1410
        $this->assertEquals(['a' => 'b'],
1411
            FlexiBeeRO::arrayCleanUP(['a' => 'b', '@a' => 'aaa']));
1412
    }
1413
1414
    /**
1415
     * @covers FlexiPeeHP\FlexiBeeRO::__wakeup
1416
     */
1417
    public function test__wakeup()
1418
    {
1419
        $this->object->__wakeup();
1420
    }
1421
1422
    /**
1423
     * @covers FlexiPeeHP\FlexiBeeRO::__destruct
1424
     */
1425
    public function test_destruct()
1426
    {
1427
        $this->object->__destruct();
1428
    }
1429
}
1430