Test Failed
Push — master ( 83f818...9d7760 )
by Vítězslav
10:30
created

FlexiBeeROTest::testObject2array()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 0
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('', ['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\Flexi/home/vitex/Projects/Spoje.Net/flexipeehp/testing/src/FlexiPeeHP/FlexiBeeROTest.php:86BeeRO::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($evidence.'.json');
227
                if (array_key_exists('message', $json)) {
228
                    $this->assertArrayHasKey('@version', $json);
229
                } else {
230
                    $this->assertArrayHasKey($evidence, $json);
231
                }
232
233
                $xml = $this->object->performRequest(null, 'GET', 'xml');
234
                $this->assertArrayHasKey('companies', $xml);
235
236
                break;
237
        }
238
239
        //404 Test
240
        $this->assertNull($this->object->performRequest('error404.json'));
241
    }
242
243
    /**
244
     * @covers FlexiPeeHP\FlexiBeeRO::setAction
245
     */
246
    public function testSetAction()
247
    {
248
        if (empty($this->object->evidence) || ($this->object->evidence == 'c')) {
249
            $this->markTestSkipped('no evidence set');
250
        } else {
251
            $this->assertTrue($this->object->setAction('new'));
252
            $this->object->actionsAvailable = [];
253
            $this->assertFalse($this->object->setAction('none'));
254
            $this->object->actionsAvailable = ['copy'];
255
            $this->assertFalse($this->object->setAction('none'));
256
        }
257
    }
258
259
    /**
260
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidence
261
     */
262
    public function testGetEvidence()
263
    {
264
        $this->assertEquals($this->object->evidence,
265
            $this->object->getEvidence());
266
    }
267
268
    /**
269
     * @covers FlexiPeeHP\FlexiBeeRO::getCompany
270
     */
271
    public function testGetCompany()
272
    {
273
        $this->assertEquals($this->object->company, $this->object->getCompany());
274
    }
275
276
    /**
277
     * @covers FlexiPeeHP\FlexiBeeRO::getResponseEvidence
278
     */
279
    public function testGetResponseEvidence()
280
    {
281
        $this->assertEquals($this->object->getEvidence(),
282
            $this->object->getResponseEvidence());
283
    }
284
285
    /**
286
     * @covers FlexiPeeHP\FlexiBeeRO::getLastInsertedId
287
     * @depends testInsertToFlexiBee
288
     */
289
    public function testGetLastInsertedId()
290
    {
291
        $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...
292
    }
293
294
    /**
295
     * @covers FlexiPeeHP\FlexiBeeRO::xml2array
296
     */
297
    public function testXml2array()
298
    {
299
        $xml = '<card xmlns="http://businesscard.org">
300
   <name>John Doe</name>
301
   <title>CEO, Widget Inc.</title>
302
   <email>[email protected]</email>
303
   <phone>(202) 456-1414</phone>
304
   <logo url="widget.gif"/>
305
   <a><b>c</b></a>
306
 </card>';
307
308
        $data = ['name' => 'John Doe', 'title' => 'CEO, Widget Inc.', 'email' => '[email protected]',
309
            'phone' => '(202) 456-1414', 'logo' => '', 'a' => [['b' => 'c']]];
310
311
312
        $this->assertEquals($data, $this->object->xml2array($xml));
313
    }
314
315
    /**
316
     * @covers FlexiPeeHP\FlexiBeeRO::disconnect
317
     *
318
     * @depends testPerformRequest
319
     * @depends testLoadFlexiData
320
     * @depends testGetFlexiRow
321
     * @depends testGetFlexiData
322
     * @depends testLoadFromFlexiBee
323
     * @depends testInsertToFlexiBee
324
     * @depends testIdExists
325
     * @depends testRecordExists
326
     * @depends testGetColumnsFromFlexibee
327
     * @depends testSearchString
328
     */
329
    public function testDisconnect()
330
    {
331
        $this->object->disconnect();
332
        $this->assertNull($this->object->curl);
333
    }
334
335
    /**
336
     * @covers FlexiPeeHP\FlexiBeeRO::__destruct
337
     * @depends testDisconnect
338
     */
339
    public function testdestruct()
340
    {
341
        $this->markTestSkipped();
342
    }
343
344
    /**
345
     * @covers FlexiPeeHP\FlexiBeeRO::getFlexiRow
346
     */
347
    public function testGetFlexiRow()
348
    {
349
        $this->object->getFlexiRow(0);
350
        $this->object->getFlexiRow(1);
351
    }
352
353
    /**
354
     * @covers FlexiPeeHP\FlexiBeeRO::getFlexiData
355
     */
356
    public function testGetFlexiData()
357
    {
358
        $evidence = $this->object->getEvidence();
359
360
        switch ($evidence) {
361
            case null:
362
                $this->markTestSkipped('Unsupported evidence');
363
                break;
364
            case 'c':
365
                $this->object->evidence  = 'c';
366
                $this->object->prefix    = '';
367
                $this->object->company   = '';
368
                $this->object->nameSpace = 'companies';
369
                $flexidata               = $this->object->getFlexiData();
370
                $this->assertArrayHasKey('company', $flexidata);
371
                break;
372
373
            default:
374
                $flexidata = $this->object->getFlexiData();
375 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...
376
                    $this->markTestSkipped('Empty evidence');
377
                } else {
378
                    $this->assertArrayHasKey(0, $flexidata);
379
                    $this->assertArrayHasKey('id', $flexidata[0]);
380
                    $filtrered = $this->object->getFlexiData(null,
381
                        "id = ".$flexidata[0]['id']);
382
                    $this->assertArrayHasKey(0, $filtrered);
383
                    $this->assertArrayHasKey('id', $filtrered[0]);
384
                }
385
                break;
386
        }
387
    }
388
389
    /**
390
     * @covers FlexiPeeHP\FlexiBeeRO::loadFromFlexiBee
391
     */
392
    public function testLoadFromFlexiBee()
393
    {
394
        $this->object->loadFromFlexiBee();
395
        $this->object->loadFromFlexiBee(222);
396
    }
397
398
    /**
399
     * @covers FlexiPeeHP\FlexiBeeRO::jsonizeData
400
     */
401
    public function testJsonizeData()
402
    {
403
        $this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"}}}',
404
            $this->object->jsonizeData(['key' => 'value']));
405
406
        if (!empty($this->object->evidence) && ($this->object->evidence != 'c')) {
407
            $this->object->setAction('copy');
408
            $this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"},"'.$this->object->evidence.'@action":"copy"}}',
409
                $this->object->jsonizeData(['key' => 'value']));
410
        }
411
    }
412
413
    /**
414
     * @covers FlexiPeeHP\FlexiBeeRO::idExists
415
     */
416
    public function testIdExists()
417
    {
418
        // Remove the following lines when you implement this test.
419
        $this->markTestIncomplete(
420
            'This test has not been implemented yet.'
421
        );
422
    }
423
424
    /**
425
     * @covers FlexiPeeHP\FlexiBeeRO::getRecordID
426
     * @todo   Implement testGetRecordID().
427
     */
428
    public function testGetRecordID()
429
    {
430
        // Remove the following lines when you implement this test.
431
        $this->markTestIncomplete(
432
            'This test has not been implemented yet.'
433
        );
434
    }
435
436
    /**
437
     * @covers FlexiPeeHP\FlexiBeeRO::recordExists
438
     */
439
    public function testRecordExists()
440
    {
441
        $evidence = $this->object->getEvidence();
442
443
        switch ($evidence) {
444
            case null:
445
            case 'c':
446
                $this->markTestSkipped('Unsupported evidence');
447
                break;
448
449
            default:
450
                $flexidata = $this->object->getFlexiData(null, ['limit' => 1]);
451
                if (is_array($flexidata) && !count($flexidata)) {
452
                    $this->markTestSkipped('Empty evidence');
453
                } else {
454
                    if (isset($flexidata['success']) && ($flexidata['success'] == 'false')) {
455
                        $this->markTestSkipped($flexidata['message']);
456
                    } else {
457
                        $this->object->setData(['id' => (int) $flexidata[0]['id']]);
458
                        $this->assertTrue($this->object->recordExists(),
459
                            'First record exists test failed');
460
                        $this->assertFalse($this->object->recordExists(['id' => 0]),
461
                            'Record ID 0 exists');
462
                        $this->assertFalse($this->object->recordExists(['unexistent' => 1]),
463
                            'Unexistent Record exist ?');
464
                    }
465
                }
466
                break;
467
        }
468
    }
469
470
    /**
471
     * @covers FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee
472
     */
473
    public function testGetColumnsFromFlexibee()
474
    {
475
        // Remove the following lines when you implement this test.
476
        $this->markTestIncomplete(
477
            'This test has not been implemented yet.'
478
        );
479
    }
480
481
    /**
482
     * @covers FlexiPeeHP\FlexiBeeRO::getExternalID
483
     * @todo   Implement testGetExternalID().
484
     */
485
    public function testGetExternalID()
486
    {
487
        // Remove the following lines when you implement this test.
488
        $this->markTestIncomplete(
489
            'This test has not been implemented yet.'
490
        );
491
    }
492
493
    /**
494
     * @covers FlexiPeeHP\FlexiBeeRO::getGlobalVersion
495
     * @todo   Implement testGetGlobalVersion().
496
     */
497
    public function testGetGlobalVersion()
498
    {
499
        // Remove the following lines when you implement this test.
500
        $this->markTestIncomplete(
501
            'This test has not been implemented yet.'
502
        );
503
    }
504
505
    /**
506
     * @covers FlexiPeeHP\FlexiBeeRO::getResponseFormat
507
     * @todo   Implement testGetResponseFormat().
508
     */
509
    public function testGetResponseFormat()
510
    {
511
        // Remove the following lines when you implement this test.
512
        $this->markTestIncomplete(
513
            'This test has not been implemented yet.'
514
        );
515
    }
516
517
    /**
518
     * @covers FlexiPeeHP\FlexiBeeRO::getKod
519
     */
520
    public function testGetKod()
521
    {
522
        $testString = [];
523
        $this->assertEquals('CODE',
524
            $this->object->getKod([$this->object->myKeyColumn => 'code']));
525
526
        $testString[$this->object->nameColumn] = 'Fish clamp -  Úchytka pro instalaci samonosných kabelů '
527
            .'(3.5 mm)';
528
        $code0                                 = $this->object->getKod($testString);
529
        $this->assertEquals('FISHCLAMPUCHYTKAPR', $code0);
530
        $code1                                 = $this->object->getKod($testString,
531
            false);
532
        $this->assertEquals('FISHCLAMPUCHYTKAPR', $code1);
533
        $code2                                 = $this->object->getKod($testString);
534
        $this->assertEquals('FISHCLAMPUCHYTKAPR1', $code2);
535
        $this->object->setData($testString);
536
        $code3                                 = $this->object->getKod();
537
        $this->assertEquals('FISHCLAMPUCHYTKAPR2', $code3);
538
539
        $this->assertEquals('TEST',
540
            $this->object->getKod([$this->object->nameColumn => 'test']));
541
542
        $this->assertEquals('TEST1', $this->object->getKod('test'));
543
544
        $this->assertEquals('TEST2', $this->object->getKod(['kod' => 'test']));
545
        $this->assertEquals('NOTSET', $this->object->getKod(['kod' => '']));
546
    }
547
548
    /**
549
     * @covers FlexiPeeHP\FlexiBeeRO::logResult
550
     */
551
    public function testLogResult()
552
    {
553
        $this->object->cleanMessages();
554
        $success = json_decode('{"winstrom":{"@version":"1.0","success":"true",'
555
            .'"stats":{"created":"0","updated":"1","deleted":"0","skipped":"0"'
556
            .',"failed":"0"},"results":[{"id":"1","request-id":"ext:SōkoMan.item'
557
            .':5271","ref":"/c/spoje_net_s_r_o_1/skladovy-pohyb/1.json"}]}}');
558
        $this->object->logResult(current($this->object->object2array($success)),
559
            'http://test');
560
561
        $this->assertArrayHasKey('info', $this->object->getStatusMessages(true));
562
563
        $error                          = json_decode('{"winstrom":{"@version":"1.0","success":"false",'
564
            .'"stats":{"created":"0","updated":"0","deleted":"0","skipped":"0"'
565
            .',"failed":"0"},"results":[{"errors":[{"message":"cz.winstrom.'
566
            .'service.WSBusinessException: Zadaný kód není unikátní.\nZadaný'
567
            .' kód není unikátní."}]}]}}');
568
        $this->object->lastResponseCode = 500;
569
        $this->object->logResult(current($this->object->object2array($error)));
570
        $this->assertArrayHasKey('error', $this->object->getStatusMessages(true));
571
    }
572
573
    /**
574
     * @covers FlexiPeeHP\FlexiBeeRO::flexiUrl
575
     */
576
    public function testFlexiUrl()
577
    {
578
        $this->assertEquals("a eq '1' and b eq 'foo'",
579
            $this->object->flexiUrl(['a' => 1, 'b' => 'foo'], 'and'));
580
        $this->assertEquals("a eq '1' or b eq 'bar'",
581
            $this->object->flexiUrl(['a' => 1, 'b' => 'bar'], 'or'));
582
        $this->assertEquals("a eq true or b eq false",
583
            $this->object->flexiUrl(['a' => true, 'b' => false], 'or'));
584
        $this->assertEquals("a is null and b is not null",
585
            $this->object->flexiUrl(['a' => null, 'b' => '!null'], 'and'));
586
    }
587
588
    /**
589
     * @covers FlexiPeeHP\FlexiBeeRO::unifyResponseFormat
590
     */
591
    public function testunifyResponseFormat()
592
    {
593
        $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...
594
        //One Row Test
595
596
        $responseEvidence = $this->object->getResponseEvidence();
597
        if (empty($responseEvidence)) {
598
            $responseEvidence       = $this->object->evidence = 'test';
599
        }
600
601
        $test1raw = [$responseEvidence =>
602
            ['id' => 1, 'name' => 'value']
603
        ];
604
605
        $test1expected = [$responseEvidence =>
606
            [
607
                ['id' => 1, 'name' => 'value']
608
            ]
609
        ];
610
611
        $this->assertEquals($test1expected,
612
            $this->object->unifyResponseFormat($test1raw));
613
614
        //Two Row Test
615
        $test2Raw = [$this->object->getResponseEvidence() =>
616
            [
617
                ['id' => 1, 'name' => 'value'],
618
                ['id' => 2, 'name' => 'value2']
619
            ]
620
        ];
621
622
        $test2expected = [$this->object->getResponseEvidence() =>
623
            [
624
                ['id' => 1, 'name' => 'value'],
625
                ['id' => 2, 'name' => 'value2']
626
            ]
627
        ];
628
629
        $this->assertEquals($test2expected,
630
            $this->object->unifyResponseFormat($test2Raw));
631
    }
632
633
    /**
634
     * @covers FlexiPeeHP\FlexiBeeRO::__toString
635
     */
636
    public function testtoString()
637
    {
638
639
        $identifer = 'ext:test:123';
640
        $this->object->setDataValue('id', $identifer);
641
        $this->assertEquals($identifer, (string) $this->object);
642
643
        $code = 'test';
644
        $this->object->setDataValue('kod', $code);
645
        $this->assertEquals('code:'.$code, (string) $this->object);
646
647
        $this->object->dataReset();
648
        $this->assertEquals('', $this->object->__toString());
649
    }
650
651
    /**
652
     * @covers FlexiPeeHP\FlexiBeeRO::draw
653
     */
654
    public function testDraw($whatWant = NULL)
655
    {
656
        $this->object->setDataValue('kod', 'test');
657
        $this->assertEquals('code:test', $this->object->draw());
658
    }
659
660
    /**
661
     * @covers FlexiPeeHP\FlexiBeeRO::getColumnsInfo
662
     */
663 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...
664
    {
665
        switch ($this->object->getEvidence()) {
666
            case '':
667
            case 'c':
668
            case 'hooks':
669
            case 'changes':
670
            case 'nastaveni':
671
                $this->assertNull($this->object->getColumnsInfo());
672
                $this->assertNotEmpty($this->object->getColumnsInfo('faktura-vydana'),
673
                    'Cannot obtain structure for na evidence');
674
                break;
675
            default:
676
                $this->assertNotEmpty($this->object->getColumnsInfo(),
677
                    'Cannot obtain structure for '.$this->object->getEvidence());
678
                break;
679
        }
680
    }
681
682
    /**
683
     * @covers FlexiPeeHP\FlexiBeeRO::getActionsInfo
684
     */
685 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...
686
    {
687
        switch ($this->object->getEvidence()) {
688
            case '':
689
            case 'c':
690
            case 'hooks':
691
            case 'changes':
692
            case 'nastaveni':
693
                $this->assertNull($this->object->getActionsInfo());
694
                $this->assertNotEmpty($this->object->getActionsInfo('faktura-vydana'),
695
                    'Cannot obtain actions for na evidence');
696
                break;
697
            default:
698
                $this->assertNotEmpty($this->object->getActionsInfo(),
699
                    'Cannot obtain actions for '.$this->object->getEvidence());
700
                break;
701
        }
702
    }
703
704
    /**
705
     * @covers FlexiPeeHP\FlexiBeeRO::getRelationsInfo
706
     */
707 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...
708
    {
709
        switch ($this->object->getEvidence()) {
710
            case '':
711
            case 'c':
712
            case 'hooks':
713
            case 'changes':
714
            case 'nastaveni':
715
                $this->assertNull($this->object->getRelationsInfo());
716
                $this->assertNotEmpty($this->object->getRelationsInfo('faktura-vydana'),
717
                    'Cannot obtain relations for na evidence');
718
                break;
719
            default:
720
                $this->assertNotEmpty($this->object->getRelationsInfo(),
721
                    'Cannot obtain relations for '.$this->object->getEvidence());
722
                break;
723
        }
724
    }
725
726
    /**
727
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceUrl
728
     */
729
    public function testgetEvidenceUrl()
730
    {
731
        $this->assertNotEmpty($this->object->getEvidenceUrl());
732
        $this->assertNotEmpty($this->object->getEvidenceUrl('/properties'));
733
    }
734
735
    /**
736
     * @covers FlexiPeeHP\FlexiBeeRO::evidenceToClassName
737
     */
738
    public function testevidenceToClassName()
739
    {
740
        $this->assertEquals('FakturaVydana',
741
            $this->object->evidenceToClassName('faktura-vydana'));
742
    }
743
744
    /**
745
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceInfo
746
     * @todo   Implement testGetEvidenceInfo().
747
     */
748
    public function testGetEvidenceInfo()
749
    {
750
        // Remove the following lines when you implement this test.
751
        $this->markTestIncomplete(
752
            'This test has not been implemented yet.'
753
        );
754
    }
755
756
    /**
757
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceName
758
     * @todo   Implement testGetEvidenceName().
759
     */
760
    public function testGetEvidenceName()
761
    {
762
        // Remove the following lines when you implement this test.
763
        $this->markTestIncomplete(
764
            'This test has not been implemented yet.'
765
        );
766
    }
767
768
    /**
769
     * @covers FlexiPeeHP\FlexiBeeRO::performAction
770
     * @todo   Implement testPerformAction().
771
     */
772
    public function testPerformAction()
773
    {
774
        // Remove the following lines when you implement this test.
775
        $this->markTestIncomplete(
776
            'This test has not been implemented yet.'
777
        );
778
    }
779
780
    /**
781
     * @covers FlexiPeeHP\FlexiBeeRO::saveResponseToFile
782
     * @todo   Implement testSaveResponseToFile().
783
     */
784
    public function testSaveResponseToFile()
785
    {
786
        // Remove the following lines when you implement this test.
787
        $this->markTestIncomplete(
788
            'This test has not been implemented yet.'
789
        );
790
    }
791
792
    /**
793
     * @covers FlexiPeeHP\FlexiBeeRO::getVazby
794
     * @todo   Implement testGetVazby().
795
     */
796
    public function testGetVazby()
797
    {
798
        // Remove the following lines when you implement this test.
799
        $this->markTestIncomplete(
800
            'This test has not been implemented yet.'
801
        );
802
    }
803
804
}
805