Test Failed
Push — master ( 111789...8ec047 )
by Vítězslav
05:58
created

FlexiBeeROTest::testgetFirstRecordID()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
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\BrickTest
11
{
12
    /**
13
     * @var FlexiBeeRO
14
     */
15
    protected $object;
16
17
    /**
18
     * Sets up the fixture, for example, opens a network connection.
19
     * This method is called before a test is executed.
20
     * @covers FlexiPeeHP\FlexiBeeRO::__construct
21
     */
22
    protected function setUp()
23
    {
24
        $this->object          = new FlexiBeeRO();
25
        $this->object->prefix  = '';
26
        $this->object->company = '';
27
        $this->object->debug   = true;
28
    }
29
30
    /**
31
     * Tears down the fixture, for example, closes a network connection.
32
     * This method is called after a test is executed.
33
     */
34
    protected function tearDown()
35
    {
36
        
37
    }
38
39
    public function testConstructor()
40
    {
41
        $classname = get_class($this->object);
42
        $evidence  = $this->object->getEvidence();
43
44
        // Get mock, without the constructor being called
45
        $mock = $this->getMockBuilder($classname)
46
            ->disableOriginalConstructor()
47
            ->getMockForAbstractClass();
48
        $mock->__construct(1, ['debug' => false]);
49
50
        if (!isset(\FlexiPeeHP\EvidenceList::$name[$evidence])) {
51
            $evidence = 'adresar';
52
        }
53
54
        $mock->__construct('',
55
            [
56
            'company' => 'Firma_s_r_o_',
57
            'url' => 'https://flexibee.firma.cz/',
58
            'user' => 'rest',
59
            'password' => '-dj3x21xaA_',
60
            'debug' => true,
61
            'prefix' => 'c',
62
            'evidence' => $evidence]);
63
    }
64
65
    /**
66
     * @covers FlexiPeeHP\FlexiBeeRO::curlInit
67
     */
68
    public function testSetupProperty()
69
    {
70
        $properties = ['debug' => true];
71
        $this->object->setupProperty($properties, 'debug');
72
        $this->assertTrue($this->object->debug);
73
        $this->object->setupProperty($properties, 'url', 'FLEXIBEE_URL');
74
    }
75
76
    /**
77
     * @covers FlexiPeeHP\FlexiBeeRO::curlInit
78
     */
79
    public function testCurlInit()
80
    {
81
        $this->object->curlInit();
82
        $this->assertTrue(is_resource($this->object->curl));
83
    }
84
85
    /**
86
     * @covers FlexiPeeHP\FlexiBeeRO::processInit
87
     */
88
    public function testProcessInit()
89
    {
90
        $this->object->processInit(['id' => 1]);
91
        $this->assertEquals(1, $this->object->getDataValue('id'));
92
        if (!is_null($this->object->evidence) && $this->object->evidence != 'test') {
93
            $firstID = $this->object->getColumnsFromFlexibee('id',
0 ignored issues
show
Documentation introduced by
'id' is of type string, but the function expects a array<integer,string>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
94
                ['limit' => 1]);
95
96
            if (count($firstID)) {
97
98
                $this->object->processInit((int) current($firstID));
99
                $this->assertNotEmpty($this->object->__toString());
100
101
                if (isset($firstID[0]['kod'])) {
102
                    $this->object->processInit('code:'.$firstID[0]['kod']);
103
                    $this->assertNotEmpty($this->object->__toString());
104
                }
105
            } else {
106
                $this->markTestSkipped(sprintf('Evidence %s doed not contain first record',
107
                        $this->object->getEvidence()));
108
            }
109
        }
110
    }
111
112
    /**
113
     * @covers FlexiPeeHP\FlexiBeeRO::setUp
114
     */
115
    public function testSetUp()
116
    {
117
        $this->object->setUp(
118
            [
119
                'company' => 'cmp',
120
                'url' => 'url',
121
                'user' => 'usr',
122
                'password' => 'pwd',
123
                'prefix' => 'c',
124
                'debug' => true,
125
                'defaultUrlParams' => ['limit' => 10],
126
                'evidence' => 'smlouva'
127
            ]
128
        );
129
        $this->assertEquals('cmp', $this->object->company);
130
        $this->assertEquals('url', $this->object->url);
131
        $this->assertEquals('usr', $this->object->user);
132
        $this->assertEquals('/c/', $this->object->prefix);
133
        $this->assertEquals('pwd', $this->object->password);
134
    }
135
136
    /**
137
     * @covers FlexiPeeHP\FlexiBeeRO::setPrefix
138
     * @expectedException \Exception
139
     */
140
    public function testSetPrefix()
141
    {
142
        $this->object->setPrefix('c');
143
        $this->assertEquals('/c/', $this->object->prefix);
144
        $this->object->setPrefix(null);
145
        $this->assertEquals('', $this->object->prefix);
146
        $this->object->setPrefix('fail');
147
    }
148
149
    /**
150
     * @covers FlexiPeeHP\FlexiBeeRO::setFormat
151
     */
152
    public function testSetFormat()
153
    {
154
        $this->object->setFormat('xml');
155
        $this->assertEquals('xml', $this->object->format);
156
    }
157
158
    /**
159
     * We can set only evidence defined in EvidenceList class
160
     *
161
     * @covers FlexiPeeHP\FlexiBeeRO::setEvidence
162
     * @expectedException \Exception
163
     */
164
    public function testSetEvidence()
165
    {
166
        $this->object->setEvidence('adresar');
167
        $this->assertEquals('adresar', $this->object->evidence);
168
        $this->object->setPrefix('c');
169
        $this->object->setEvidence('fail');
170
    }
171
172
    /**
173
     * @covers FlexiPeeHP\FlexiBeeRO::setCompany
174
     */
175
    public function testSetCompany()
176
    {
177
        $this->object->setCompany('test_s_r_o_');
178
        $this->assertEquals('test_s_r_o_', $this->object->company);
179
    }
180
181
    /**
182
     * @covers FlexiPeeHP\FlexiBeeRO::object2array
183
     */
184
    public function testObject2array()
185
    {
186
        $this->assertNull($this->object->object2array(new \stdClass()));
187
        $this->assertEquals(
188
            [
189
            'item' => 1,
190
            'arrItem' => ['a', 'b' => 'c']
191
            ]
192
            , $this->object->object2array(new \Test\ObjectForTesting()));
193
    }
194
195
    /**
196
     * @covers FlexiPeeHP\FlexiBeeRO::objectToID
197
     */
198
    public function testObjectToID()
199
    {
200
        $id = \Ease\Sand::randomNumber(1, 9999);
201
        $this->object->setMyKey($id);
0 ignored issues
show
Security Bug introduced by
It seems like $id defined by \Ease\Sand::randomNumber(1, 9999) on line 200 can also be of type false; however, FlexiPeeHP\FlexiBeeRO::setMyKey() does only seem to accept integer|string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
202
        $this->assertEquals([$id], $this->object->objectToID([$this->object]));
203
204
        $this->object->setDataValue('kod', 'TEST');
205
        $this->assertEquals('code:TEST',
206
            $this->object->objectToID($this->object));
207
208
        $this->assertEquals('TEST', $this->object->objectToID('TEST'));
0 ignored issues
show
Documentation introduced by
'TEST' is of type string, but the function expects a object|array.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
209
    }
210
211
    /**
212
     * @covers FlexiPeeHP\FlexiBeeRO::performRequest
213
     */
214
    public function testPerformRequest()
215
    {
216
        $evidence = $this->object->getEvidence();
217
        switch ($evidence) {
218
            case null:
219
            case '':
220
            case 'test':
221
            case 'c':
222
                $this->markTestSkipped('Evidence not set');
223
                break;
224
225
            default:
226
                $json = $this->object->performRequest(null, 'GET', 'json');
227
                if (array_key_exists('message', $json)) {
228
                    $this->assertArrayHasKey('@version', $json);
229
                } else {
230
                    $this->assertArrayHasKey($this->object->getResponseEvidence(),
231
                        $json);
232
                }
233
234
                $xml = $this->object->performRequest(null, 'GET', 'xml');
235
                $this->assertArrayHasKey($this->object->getResponseEvidence(),
236
                    $xml);
237
238
                break;
239
        }
240
241
        //404 Test
242
        $this->assertNull($this->object->performRequest('error404.json'));
243
    }
244
245
    /**
246
     * @covers FlexiPeeHP\FlexiBeeRO::setAction
247
     */
248
    public function testSetAction()
249
    {
250
        if (empty($this->object->evidence) || ($this->object->evidence == 'c')) {
251
            $this->markTestSkipped('no evidence set');
252
        } else {
253
            $this->assertTrue($this->object->setAction('new'));
254
            $this->object->actionsAvailable = [];
255
            $this->assertFalse($this->object->setAction('none'));
256
            $this->object->actionsAvailable = ['copy'];
257
            $this->assertFalse($this->object->setAction('none'));
258
        }
259
    }
260
261
    /**
262
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidence
263
     */
264
    public function testGetEvidence()
265
    {
266
        $this->assertEquals($this->object->evidence,
267
            $this->object->getEvidence());
268
    }
269
270
    /**
271
     * @covers FlexiPeeHP\FlexiBeeRO::getCompany
272
     */
273
    public function testGetCompany()
274
    {
275
        $this->assertEquals($this->object->company, $this->object->getCompany());
276
    }
277
278
    /**
279
     * @covers FlexiPeeHP\FlexiBeeRO::getResponseEvidence
280
     */
281
    public function testGetResponseEvidence()
282
    {
283
        $this->assertEquals($this->object->getEvidence(),
284
            $this->object->getResponseEvidence());
285
    }
286
287
    /**
288
     * @covers FlexiPeeHP\FlexiBeeRO::getLastInsertedId
289
     * @depends testInsertToFlexiBee
290
     */
291
    public function testGetLastInsertedId()
292
    {
293
        $this->assertNotEmpty($this->object->getLastInsertedId());
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class FlexiPeeHP\FlexiBeeRO as the method getLastInsertedId() does only exist in the following sub-classes of FlexiPeeHP\FlexiBeeRO: FlexiPeeHP\Adresar, FlexiPeeHP\Banka, FlexiPeeHP\Cenik, FlexiPeeHP\DodavatelskaSmlouva, FlexiPeeHP\FakturaPrijata, FlexiPeeHP\FakturaVydana, FlexiPeeHP\FakturaVydanaPolozka, FlexiPeeHP\FlexiBeeRW, FlexiPeeHP\Hooks, FlexiPeeHP\Kontakt, FlexiPeeHP\Pokladna, FlexiPeeHP\PokladniPohyb, FlexiPeeHP\Priloha, FlexiPeeHP\RadaPokladniPohyb, FlexiPeeHP\SkladovaKarta, FlexiPeeHP\SkladovyPohyb, FlexiPeeHP\SkladovyPohybPolozka, FlexiPeeHP\SkupinaFirem, FlexiPeeHP\Stitek, FlexiPeeHP\Strom, FlexiPeeHP\StromCenik, FlexiPeeHP\UcetniObdobi, FlexiPeeHP\VyrobniCislo. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
294
    }
295
296
    /**
297
     * @covers FlexiPeeHP\FlexiBeeRO::xml2array
298
     */
299
    public function testXml2array()
300
    {
301
        $xml = '<card xmlns="http://businesscard.org">
302
   <name>John Doe</name>
303
   <title>CEO, Widget Inc.</title>
304
   <email>[email protected]</email>
305
   <phone>(202) 456-1414</phone>
306
   <logo url="widget.gif"/>
307
   <a><b>c</b></a>
308
 </card>';
309
310
        $data = ['name' => 'John Doe', 'title' => 'CEO, Widget Inc.', 'email' => '[email protected]',
311
            'phone' => '(202) 456-1414', 'logo' => '', 'a' => [['b' => 'c']]];
312
313
314
        $this->assertEquals($data, $this->object->xml2array($xml));
315
    }
316
317
    /**
318
     * @covers FlexiPeeHP\FlexiBeeRO::disconnect
319
     *
320
     * @depends testPerformRequest
321
     * @depends testLoadFlexiData
322
     * @depends testGetFlexiRow
323
     * @depends testGetFlexiData
324
     * @depends testLoadFromFlexiBee
325
     * @depends testInsertToFlexiBee
326
     * @depends testIdExists
327
     * @depends testRecordExists
328
     * @depends testGetColumnsFromFlexibee
329
     * @depends testSearchString
330
     */
331
    public function testDisconnect()
332
    {
333
        $this->object->disconnect();
334
        $this->assertNull($this->object->curl);
335
    }
336
337
    /**
338
     * @covers FlexiPeeHP\FlexiBeeRO::__destruct
339
     * @depends testDisconnect
340
     */
341
    public function testdestruct()
342
    {
343
        $this->markTestSkipped();
344
    }
345
346
    /**
347
     * @covers FlexiPeeHP\FlexiBeeRO::getFlexiRow
348
     */
349
    public function testGetFlexiRow()
350
    {
351
        $this->object->getFlexiRow(0);
352
        $this->object->getFlexiRow(1);
353
    }
354
355
    /**
356
     * @covers FlexiPeeHP\FlexiBeeRO::getFlexiData
357
     */
358
    public function testGetFlexiData()
359
    {
360
        $evidence = $this->object->getEvidence();
361
362
        switch ($evidence) {
363
            case null:
364
                $this->markTestSkipped('Unsupported evidence');
365
                break;
366
            case 'c':
367
                $this->object->evidence  = 'c';
368
                $this->object->prefix    = '';
369
                $this->object->company   = '';
370
                $this->object->nameSpace = 'companies';
371
                $flexidata               = $this->object->getFlexiData();
372
                $this->assertArrayHasKey('company', $flexidata);
373
                break;
374
375
            default:
376
                $flexidata = $this->object->getFlexiData();
377 View Code Duplication
                if (is_array($flexidata) && !count($flexidata)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
378
                    $this->markTestSkipped('Empty evidence');
379
                } else {
380
                    $this->assertArrayHasKey(0, $flexidata);
381
                    $this->assertArrayHasKey('id', $flexidata[0]);
382
                    $filtrered = $this->object->getFlexiData(null,
383
                        "id = ".$flexidata[0]['id']);
384
                    $this->assertArrayHasKey(0, $filtrered);
385
                    $this->assertArrayHasKey('id', $filtrered[0]);
386
                }
387
                break;
388
        }
389
    }
390
391
    /**
392
     * @covers FlexiPeeHP\FlexiBeeRO::loadFromFlexiBee
393
     */
394
    public function testLoadFromFlexiBee()
395
    {
396
        $this->object->loadFromFlexiBee();
397
        $this->object->loadFromFlexiBee(222);
398
    }
399
400
    /**
401
     * @covers FlexiPeeHP\FlexiBeeRO::jsonizeData
402
     */
403
    public function testJsonizeData()
404
    {
405
        $this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"}}}',
406
            $this->object->jsonizeData(['key' => 'value']));
407
408
        if (!empty($this->object->evidence) && ($this->object->evidence != 'c')) {
409
            $this->object->setAction('copy');
410
            $this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"},"'.$this->object->evidence.'@action":"copy"}}',
411
                $this->object->jsonizeData(['key' => 'value']));
412
        }
413
    }
414
415
    /**
416
     * @covers FlexiPeeHP\FlexiBeeRO::idExists
417
     */
418
    public function testIdExists()
419
    {
420
        $this->assertFalse($this->object->idExists('nonexistent'));
421
        $first = $this->object->getColumnsFromFlexibee(['id'], ['limit' => 1],
422
            'id');
423
        $this->object->setData($first);
424
        $this->assertTrue($this->object->idExists());
425
    }
426
427
    /**
428
     * @covers FlexiPeeHP\FlexiBeeRO::getRecordID
429
     */
430
    public function testGetRecordID()
431
    {
432
        $this->object->setData(['id' => 10]);
433
        $this->assertEquals(10, $this->object->getRecordID());
434
        $this->object->setData(['kod' => 'KOD']);
435
        $this->assertEquals('code:KOD', $this->object->getRecordID());
436
    }
437
438
    /**
439
     * @covers FlexiPeeHP\FlexiBeeRO::recordExists
440
     */
441
    public function testRecordExists()
442
    {
443
        $evidence = $this->object->getEvidence();
444
445
        switch ($evidence) {
446
            case null:
447
            case 'c':
448
            case 'evidence-list':
449
                $this->markTestSkipped('Unsupported evidence');
450
                break;
451
452
            default:
453
                $flexidata = $this->object->getFlexiData(null, ['limit' => 1]);
454
                if (is_array($flexidata) && !count($flexidata)) {
455
                    $this->markTestSkipped('Empty evidence');
456
                } else {
457
                    if (isset($flexidata['success']) && ($flexidata['success'] == 'false')) {
458
                        $this->markTestSkipped($flexidata['message']);
459
                    } else {
460
                        $this->object->setData(['id' => (int) $flexidata[0]['id']]);
461
                        $this->assertTrue($this->object->recordExists(),
462
                            'First record exists test failed');
463
                        $this->assertFalse($this->object->recordExists(['id' => 0]),
464
                            'Record ID 0 exists');
465
                        $this->assertFalse($this->object->recordExists(['unexistent' => 1]),
466
                            'Unexistent Record exist ?');
467
                    }
468
                }
469
                break;
470
        }
471
    }
472
473
    /**
474
     * @covers FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee
475
     */
476
    public function testGetColumnsFromFlexibee()
477
    {
478
        $columns = $this->object->getColumnsFromFlexibee(['id'], ['limit' => 1],
479
            'id');
480
        $this->assertNotEmpty($columns);
481
    }
482
483
    /**
484
     * @covers FlexiPeeHP\FlexiBeeRO::getExternalID
485
     */
486
    public function testGetExternalID()
487
    {
488
        $this->assertEquals('test:10',
489
            $this->object->getExternalID('ext:test:10'));
490
    }
491
492
    /**
493
     * @covers FlexiPeeHP\FlexiBeeRO::getGlobalVersion
494
     */
495
    public function testGetGlobalVersion()
496
    {
497
        $this->assertNotEmpty($this->object->getGlobalVersion());
498
    }
499
500
    /**
501
     * @covers FlexiPeeHP\FlexiBeeRO::getResponseFormat
502
     */
503
    public function testGetResponseFormat()
504
    {
505
        $this->object->performRequest(null, 'GET', 'json');
506
        $this->assertEquals('application/json',
507
            $this->object->getResponseFormat());
508
        $this->object->performRequest(null, 'GET', 'xml');
509
        $this->assertEquals('application/xml',
510
            $this->object->getResponseFormat());
511
    }
512
513
    /**
514
     * @covers FlexiPeeHP\FlexiBeeRO::getKod
515
     */
516
    public function testGetKod()
517
    {
518
        $testString = [];
519
        $this->assertEquals('CODE',
520
            $this->object->getKod([$this->object->myKeyColumn => 'code']));
521
522
        $testString[$this->object->nameColumn] = 'Fish clamp -  Úchytka pro instalaci samonosných kabelů '
523
            .'(3.5 mm)';
524
        $code0                                 = $this->object->getKod($testString);
525
        $this->assertEquals('FISHCLAMPUCHYTKAPR', $code0);
526
        $code1                                 = $this->object->getKod($testString,
527
            false);
528
        $this->assertEquals('FISHCLAMPUCHYTKAPR', $code1);
529
        $code2                                 = $this->object->getKod($testString);
530
        $this->assertEquals('FISHCLAMPUCHYTKAPR1', $code2);
531
        $this->object->setData($testString);
532
        $code3                                 = $this->object->getKod();
533
        $this->assertEquals('FISHCLAMPUCHYTKAPR2', $code3);
534
535
        $this->assertEquals('TEST',
536
            $this->object->getKod([$this->object->nameColumn => 'test']));
537
538
        $this->assertEquals('TEST1', $this->object->getKod('test'));
539
540
        $this->assertEquals('TEST2', $this->object->getKod(['kod' => 'test']));
541
        $this->assertEquals('NOTSET', $this->object->getKod(['kod' => '']));
542
    }
543
544
    /**
545
     * @covers FlexiPeeHP\FlexiBeeRO::logResult
546
     */
547
    public function testLogResult()
548
    {
549
        $this->object->cleanMessages();
550
        $success = json_decode('{"winstrom":{"@version":"1.0","success":"true",'
551
            .'"stats":{"created":"0","updated":"1","deleted":"0","skipped":"0"'
552
            .',"failed":"0"},"results":[{"id":"1","request-id":"ext:SōkoMan.item'
553
            .':5271","ref":"/c/spoje_net_s_r_o_1/skladovy-pohyb/1.json"}]}}');
554
        $this->object->logResult(current($this->object->object2array($success)),
555
            'http://test');
556
557
        $this->assertArrayHasKey('info', $this->object->getStatusMessages(true));
558
559
        $error                          = json_decode('{"winstrom":{"@version":"1.0","success":"false",'
560
            .'"stats":{"created":"0","updated":"0","deleted":"0","skipped":"0"'
561
            .',"failed":"0"},"results":[{"errors":[{"message":"cz.winstrom.'
562
            .'service.WSBusinessException: Zadaný kód není unikátní.\nZadaný'
563
            .' kód není unikátní."}]}]}}');
564
        $this->object->lastResponseCode = 500;
565
        $this->object->logResult(current($this->object->object2array($error)));
566
        $this->assertArrayHasKey('error', $this->object->getStatusMessages(true));
567
    }
568
569
    /**
570
     * @covers FlexiPeeHP\FlexiBeeRO::flexiUrl
571
     */
572
    public function testFlexiUrl()
573
    {
574
        $this->assertEquals("a eq '1' and b eq 'foo'",
575
            $this->object->flexiUrl(['a' => 1, 'b' => 'foo'], 'and'));
576
        $this->assertEquals("a eq '1' or b eq 'bar'",
577
            $this->object->flexiUrl(['a' => 1, 'b' => 'bar'], 'or'));
578
        $this->assertEquals("a eq true or b eq false",
579
            $this->object->flexiUrl(['a' => true, 'b' => false], 'or'));
580
        $this->assertEquals("a is null and b is not null",
581
            $this->object->flexiUrl(['a' => null, 'b' => '!null'], 'and'));
582
    }
583
584
    /**
585
     * @covers FlexiPeeHP\FlexiBeeRO::unifyResponseFormat
586
     */
587
    public function testunifyResponseFormat()
588
    {
589
        $this->assertNull($this->object->unifyResponseFormat(null));
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
590
        //One Row Test
591
592
        $responseEvidence = $this->object->getResponseEvidence();
593
        if (empty($responseEvidence)) {
594
            $responseEvidence       = $this->object->evidence = 'test';
595
        }
596
597
        $test1raw = [$responseEvidence =>
598
            ['id' => 1, 'name' => 'value']
599
        ];
600
601
        $test1expected = [$responseEvidence =>
602
            [
603
                ['id' => 1, 'name' => 'value']
604
            ]
605
        ];
606
607
        $this->assertEquals($test1expected,
608
            $this->object->unifyResponseFormat($test1raw));
609
610
        //Two Row Test
611
        $test2Raw = [$this->object->getResponseEvidence() =>
612
            [
613
                ['id' => 1, 'name' => 'value'],
614
                ['id' => 2, 'name' => 'value2']
615
            ]
616
        ];
617
618
        $test2expected = [$this->object->getResponseEvidence() =>
619
            [
620
                ['id' => 1, 'name' => 'value'],
621
                ['id' => 2, 'name' => 'value2']
622
            ]
623
        ];
624
625
        $this->assertEquals($test2expected,
626
            $this->object->unifyResponseFormat($test2Raw));
627
    }
628
629
    /**
630
     * @covers FlexiPeeHP\FlexiBeeRO::__toString
631
     */
632
    public function testtoString()
633
    {
634
635
        $identifer = 'ext:test:123';
636
        $this->object->setDataValue('id', $identifer);
637
        $this->assertEquals($identifer, (string) $this->object);
638
639
        $code = 'test';
640
        $this->object->setDataValue('kod', $code);
641
        $this->assertEquals('code:'.$code, (string) $this->object);
642
643
        $this->object->dataReset();
644
        $this->assertEquals('', $this->object->__toString());
645
    }
646
647
    /**
648
     * @covers FlexiPeeHP\FlexiBeeRO::draw
649
     */
650
    public function testDraw($whatWant = NULL)
651
    {
652
        $this->object->setDataValue('kod', 'test');
653
        $this->assertEquals('code:test', $this->object->draw());
654
    }
655
656
    /**
657
     * @covers FlexiPeeHP\FlexiBeeRO::getColumnsInfo
658
     */
659 View Code Duplication
    public function testgetColumnsInfo()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
660
    {
661
        switch ($this->object->getEvidence()) {
662
            case '':
663
            case 'c':
664
            case 'hooks':
665
            case 'changes':
666
            case 'nastaveni':
667
                $this->assertNull($this->object->getColumnsInfo());
668
                $this->assertNotEmpty($this->object->getColumnsInfo('faktura-vydana'),
669
                    'Cannot obtain structure for na evidence');
670
                break;
671
            default:
672
                $this->assertNotEmpty($this->object->getColumnsInfo(),
673
                    'Cannot obtain structure for '.$this->object->getEvidence());
674
                break;
675
        }
676
    }
677
678
    /**
679
     * @covers FlexiPeeHP\FlexiBeeRO::getActionsInfo
680
     */
681 View Code Duplication
    public function testgetActionsInfo()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
682
    {
683
        switch ($this->object->getEvidence()) {
684
            case '':
685
            case 'c':
686
            case 'hooks':
687
            case 'changes':
688
            case 'nastaveni':
689
                $this->assertNull($this->object->getActionsInfo());
690
                $this->assertNotEmpty($this->object->getActionsInfo('faktura-vydana'),
691
                    'Cannot obtain actions for na evidence');
692
                break;
693
            default:
694
                $this->assertNotEmpty($this->object->getActionsInfo(),
695
                    'Cannot obtain actions for '.$this->object->getEvidence());
696
                break;
697
        }
698
    }
699
700
    /**
701
     * @covers FlexiPeeHP\FlexiBeeRO::getRelationsInfo
702
     */
703 View Code Duplication
    public function testgetRelationsInfo()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
704
    {
705
        switch ($this->object->getEvidence()) {
706
            case '':
707
            case 'c':
708
            case 'hooks':
709
            case 'changes':
710
            case 'nastaveni':
711
                $this->assertNull($this->object->getRelationsInfo());
712
                $this->assertNotEmpty($this->object->getRelationsInfo('faktura-vydana'),
713
                    'Cannot obtain relations for na evidence');
714
                break;
715
            default:
716
                $this->assertNotEmpty($this->object->getRelationsInfo(),
717
                    'Cannot obtain relations for '.$this->object->getEvidence());
718
                break;
719
        }
720
    }
721
722
    /**
723
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceUrl
724
     */
725
    public function testgetEvidenceUrl()
726
    {
727
        $this->assertNotEmpty($this->object->getEvidenceUrl());
728
        $this->assertNotEmpty($this->object->getEvidenceUrl('/properties'));
0 ignored issues
show
Unused Code introduced by
The call to FlexiBeeRO::getEvidenceURL() has too many arguments starting with '/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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
729
    }
730
731
    /**
732
     * @covers FlexiPeeHP\FlexiBeeRO::evidenceToClassName
733
     */
734
    public function testevidenceToClassName()
735
    {
736
        $this->assertEquals('FakturaVydana',
737
            $this->object->evidenceToClassName('faktura-vydana'));
738
    }
739
740
    /**
741
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceInfo
742
     */
743
    public function testGetEvidenceInfo()
744
    {
745
        $this->assertArrayHasKey('evidencePath',
746
            $this->object->getEvidenceInfo());
747
    }
748
749
    /**
750
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceName
751
     */
752
    public function testGetEvidenceName()
753
    {
754
        $this->assertNotEmpty($this->object->getEvidenceName());
755
    }
756
757
    /**
758
     * @covers FlexiPeeHP\FlexiBeeRO::performAction
759
     */
760
    public function testPerformAction()
761
    {
762
        $actions = $this->object->getActionsInfo();
763
        $this->assertTrue($this->object->performAction(key($actions)));
764
        $this->object->performAction(next($actions), 'ext');
765
766
        $this->expectException($this->object->performAction('nonexitst'));
767
    }
768
769
    /**
770
     * @covers FlexiPeeHP\FlexiBeeRO::saveResponseToFile
771
     */
772
    public function testSaveResponseToFile()
773
    {
774
        $tmp = sys_get_temp_dir().'/'.tmpfile();
775
        $this->object->saveResponseToFile($tmp);
776
        $this->assertFileExists($tmp);
777
    }
778
779
    /**
780
     * @covers FlexiPeeHP\FlexiBeeRO::getFirstRecordID()
781
     */
782
    public function testgetFirstRecordID()
783
    {
784
        $firstID = $this->object->getFirstRecordID();
785
        if (is_null($firstID)) {
786
            $this->markTestSkipped('Empty evidence');
787
        } else {
788
            $this->assertFalse(empty($firstID));
789
        }
790
    }
791
792
    /**
793
     * @covers FlexiPeeHP\Adresar::getVazby
794
     */
795
    public function testGetVazby()
796
    {
797
        //       $this->expectException($this->object->getVazby());
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
798
        $this->object->setMyKey($this->object->getFirstRecordID());
799
        $vazby = $this->object->getVazby();
800
        if (is_null($vazby)) {
801
            $this->markAsSkipped();
0 ignored issues
show
Bug introduced by
The method markAsSkipped() does not seem to exist on object<Test\FlexiPeeHP\FlexiBeeROTest>.

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...
802
        } else {
803
            $this->assertTrue(is_array($vazby));
804
        }
805
    }
806
}
807