Completed
Push — master ( 90fa53...002064 )
by Vítězslav
16:43
created

FlexiBeeROTest::testSaveResponseToFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
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->evidence  = 'c';
26
        $this->object->prefix    = '';
27
        $this->object->company   = '';
28
        $this->object->nameSpace = 'companies';
29
    }
30
31
    /**
32
     * Tears down the fixture, for example, closes a network connection.
33
     * This method is called after a test is executed.
34
     */
35
    protected function tearDown()
36
    {
37
        
38
    }
39
40
    public function testConstructor()
41
    {
42
        $classname = get_class($this->object);
43
        $evidence  = $this->object->getEvidence();
44
45
        // Get mock, without the constructor being called
46
        $mock = $this->getMockBuilder($classname)
47
            ->disableOriginalConstructor()
48
            ->getMockForAbstractClass();
49
        $mock->__construct('');
50
51
        if (!isset(\FlexiPeeHP\EvidenceList::$name[$evidence])) {
52
            $evidence = 'adresar';
53
        }
54
55
        $mock->__construct('',
56
            [
57
            'company' => 'Firma_s_r_o_',
58
            'url' => 'https://flexibee.firma.cz/',
59
            'user' => 'rest',
60
            'password' => '-dj3x21xaA_',
61
            'prefix' => 'c',
62
            'evidence' => $evidence]);
63
    }
64
65
    /**
66
     * @covers FlexiPeeHP\FlexiBeeRO::curlInit
67
     */
68
    public function testCurlInit()
69
    {
70
        $this->object->curlInit();
71
        $this->assertTrue(is_resource($this->object->curl));
72
    }
73
74
    /**
75
     * @covers FlexiPeeHP\FlexiBeeRO::processInit
76
     */
77
    public function testProcessInit()
78
    {
79
        $this->object->processInit(['id' => 1]);
80
        $this->assertEquals(1, $this->object->getDataValue('id'));
81
        if (!is_null($this->object->evidence) && $this->object->evidence != 'test') {
82
            $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...
83
                ['limit' => 1]);
84
            $this->object->processInit((int) current($firstID));
85
            $this->assertNotEmpty($this->object->__toString());
86
        }
87
    }
88
89
    /**
90
     * @covers FlexiPeeHP\FlexiBeeRO::setUp
91
     */
92
    public function testSetUp()
93
    {
94
        $this->object->setUp(
95
            [
96
                'company' => 'cmp',
97
                'url' => 'url',
98
                'user' => 'usr',
99
                'password' => 'pwd',
100
                'prefix' => 'c',
101
                'evidence' => 'smlouva'
102
            ]
103
        );
104
        $this->assertEquals('cmp', $this->object->company);
105
        $this->assertEquals('url', $this->object->url);
106
        $this->assertEquals('usr', $this->object->user);
107
        $this->assertEquals('/c/', $this->object->prefix);
108
        $this->assertEquals('pwd', $this->object->password);
109
    }
110
111
    /**
112
     * @covers FlexiPeeHP\FlexiBeeRO::setPrefix
113
     * @expectedException \Exception
114
     */
115
    public function testSetPrefix()
116
    {
117
        $this->object->setPrefix('c');
118
        $this->assertEquals('/c/', $this->object->prefix);
119
        $this->object->setPrefix(null);
120
        $this->assertEquals('', $this->object->prefix);
121
        $this->object->setPrefix('fail');
122
    }
123
124
    /**
125
     * @covers FlexiPeeHP\FlexiBeeRO::setFormat
126
     * @todo   Implement testSetFormat().
127
     */
128
    public function testSetFormat()
129
    {
130
        // Remove the following lines when you implement this test.
131
        $this->markTestIncomplete(
132
            'This test has not been implemented yet.'
133
        );
134
    }
135
136
    /**
137
     * We can set only evidence defined in EvidenceList class
138
     *
139
     * @covers FlexiPeeHP\FlexiBeeRO::setEvidence
140
     * @expectedException \Exception
141
     */
142
    public function testSetEvidence()
143
    {
144
        $this->object->setEvidence('adresar');
145
        $this->assertEquals('adresar', $this->object->evidence);
146
        $this->object->setPrefix('c');
147
        $this->object->setEvidence('fail');
148
    }
149
150
    /**
151
     * @covers FlexiPeeHP\FlexiBeeRO::setCompany
152
     */
153
    public function testSetCompany()
154
    {
155
        $this->object->setCompany('test_s_r_o_');
156
        $this->assertEquals('test_s_r_o_', $this->object->company);
157
    }
158
159
    /**
160
     * @covers FlexiPeeHP\FlexiBeeRO::object2array
161
     */
162
    public function testObject2array()
163
    {
164
        $this->assertNull($this->object->object2array(new \stdClass()));
165
        $this->assertEquals(
166
            [
167
            'item' => 1,
168
            'arrItem' => ['a', 'b' => 'c']
169
            ]
170
            , $this->object->object2array(new \Test\ObjectForTesting()));
171
    }
172
173
    /**
174
     * @covers FlexiPeeHP\FlexiBeeRO::objectToID
175
     */
176
    public function testObjectToID()
177
    {
178
        $id = \Ease\Sand::randomNumber(1, 9999);
179
        $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 178 can also be of type false; however, Ease\Brick::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...
180
        $this->assertEquals([$id], $this->object->objectToID([$this->object]));
181
182
        $this->object->setDataValue('kod', 'TEST');
183
        $this->assertEquals('code:TEST',
184
            $this->object->objectToID($this->object));
185
186
        $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...
187
    }
188
189
    /**
190
     * @covers FlexiPeeHP\FlexiBeeRO::performRequest
191
     */
192
    public function testPerformRequest()
193
    {
194
        $evidence = $this->object->getEvidence();
195
        switch ($evidence) {
196
            case null:
197
            case '':
198
            case 'test':
199
            case 'c':
200
                $this->object->evidence  = 'c';
201
                $this->object->prefix    = '';
202
                $this->object->company   = '';
203
                $this->object->nameSpace = 'companies';
204
                $json                    = $this->object->performRequest();
205
                $this->assertArrayHasKey('company', $json);
206
207
                $xml = $this->object->performRequest(null, 'GET', 'xml');
208
                $this->assertArrayHasKey('company', $xml);
209
                break;
210
211
            default:
212
                $json = $this->object->performRequest($evidence.'.json');
213
                if (array_key_exists('message', $json)) {
214
                    $this->assertArrayHasKey('@version', $json);
215
                } else {
216
                    $this->assertArrayHasKey($evidence, $json);
217
                }
218
                break;
219
        }
220
221
222
        $err = $this->object->performRequest('error.json');
223
        $this->assertArrayHasKey('success', $err);
224
        $this->assertEquals('false', $err['success']);
225
    }
226
227
    /**
228
     * @covers FlexiPeeHP\FlexiBeeRO::setAction
229
     */
230
    public function testSetAction()
231
    {
232
        if (empty($this->object->evidence) || ($this->object->evidence == 'c')) {
233
            $this->markTestSkipped('no evidence set');
234
        } else {
235
            $this->assertTrue($this->object->setAction('new'));
236
            $this->object->actionsAvailable = [];
237
            $this->assertFalse($this->object->setAction('none'));
238
            $this->object->actionsAvailable = ['copy'];
239
            $this->assertFalse($this->object->setAction('none'));
240
        }
241
    }
242
243
    /**
244
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidence
245
     */
246
    public function testGetEvidence()
247
    {
248
        $this->assertEquals($this->object->evidence,
249
            $this->object->getEvidence());
250
    }
251
252
    /**
253
     * @covers FlexiPeeHP\FlexiBeeRO::getCompany
254
     */
255
    public function testGetCompany()
256
    {
257
        $this->assertEquals($this->object->company, $this->object->getCompany());
258
    }
259
260
    /**
261
     * @covers FlexiPeeHP\FlexiBeeRO::getResponseEvidence
262
     */
263
    public function testGetResponseEvidence()
264
    {
265
        switch ($this->object->getEvidence()) {
266
            case 'c':
267
                $this->assertEquals('companies',
268
                    $this->object->getResponseEvidence());
269
                break;
270
271
            default:
272
                $this->assertEquals($this->object->getEvidence(),
273
                    $this->object->getResponseEvidence());
274
                break;
275
        }
276
    }
277
278
    /**
279
     * @covers FlexiPeeHP\FlexiBeeRO::getLastInsertedId
280
     * @depends testInsertToFlexiBee
281
     */
282
    public function testGetLastInsertedId()
283
    {
284
        $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...
285
    }
286
287
    /**
288
     * @covers FlexiPeeHP\FlexiBeeRO::xml2array
289
     */
290
    public function testXml2array()
291
    {
292
        $xml = '<card xmlns="http://businesscard.org">
293
   <name>John Doe</name>
294
   <title>CEO, Widget Inc.</title>
295
   <email>[email protected]</email>
296
   <phone>(202) 456-1414</phone>
297
   <logo url="widget.gif"/>
298
   <a><b>c</b></a>
299
 </card>';
300
301
        $data = ['name' => 'John Doe', 'title' => 'CEO, Widget Inc.', 'email' => '[email protected]',
302
            'phone' => '(202) 456-1414', 'logo' => '', 'a' => [['b' => 'c']]];
303
304
305
        $this->assertEquals($data, $this->object->xml2array($xml));
306
    }
307
308
    /**
309
     * @covers FlexiPeeHP\FlexiBeeRO::disconnect
310
     *
311
     * @depends testPerformRequest
312
     * @depends testLoadFlexiData
313
     * @depends testGetFlexiRow
314
     * @depends testGetFlexiData
315
     * @depends testLoadFromFlexiBee
316
     * @depends testInsertToFlexiBee
317
     * @depends testIdExists
318
     * @depends testRecordExists
319
     * @depends testGetColumnsFromFlexibee
320
     * @depends testSearchString
321
     */
322
    public function testDisconnect()
323
    {
324
        $this->object->disconnect();
325
        $this->assertNull($this->object->curl);
326
    }
327
328
    /**
329
     * @covers FlexiPeeHP\FlexiBeeRO::__destruct
330
     * @depends testDisconnect
331
     */
332
    public function testdestruct()
333
    {
334
        $this->markTestSkipped();
335
    }
336
337
    /**
338
     * @covers FlexiPeeHP\FlexiBeeRO::getFlexiRow
339
     */
340
    public function testGetFlexiRow()
341
    {
342
        $this->object->getFlexiRow(0);
343
        $this->object->getFlexiRow(1);
344
    }
345
346
    /**
347
     * @covers FlexiPeeHP\FlexiBeeRO::getFlexiData
348
     */
349
    public function testGetFlexiData()
350
    {
351
        $evidence = $this->object->getEvidence();
352
353
        switch ($evidence) {
354
            case null:
355
                $this->markTestSkipped('Unsupported evidence');
356
                break;
357
            case 'c':
358
                $this->object->evidence  = 'c';
359
                $this->object->prefix    = '';
360
                $this->object->company   = '';
361
                $this->object->nameSpace = 'companies';
362
                $flexidata               = $this->object->getFlexiData();
363
                $this->assertArrayHasKey('company', $flexidata);
364
                break;
365
366
            default:
367
                $flexidata = $this->object->getFlexiData();
368 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...
369
                    $this->markTestSkipped('Empty evidence');
370
                } else {
371
                    $this->assertArrayHasKey(0, $flexidata);
372
                    $this->assertArrayHasKey('id', $flexidata[0]);
373
                    $filtrered = $this->object->getFlexiData(null,
374
                        "id = ".$flexidata[0]['id']);
375
                    $this->assertArrayHasKey(0, $filtrered);
376
                    $this->assertArrayHasKey('id', $filtrered[0]);
377
                }
378
                break;
379
        }
380
    }
381
382
    /**
383
     * @covers FlexiPeeHP\FlexiBeeRO::loadFromFlexiBee
384
     */
385
    public function testLoadFromFlexiBee()
386
    {
387
        $this->object->loadFromFlexiBee();
388
        $this->object->loadFromFlexiBee(222);
389
    }
390
391
    /**
392
     * @covers FlexiPeeHP\FlexiBeeRO::jsonizeData
393
     */
394
    public function testJsonizeData()
395
    {
396
        $this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"}}}',
397
            $this->object->jsonizeData(['key' => 'value']));
398
399
        if (!empty($this->object->evidence) && ($this->object->evidence != 'c')) {
400
            $this->object->setAction('copy');
401
            $this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"},"'.$this->object->evidence.'@action":"copy"}}',
402
                $this->object->jsonizeData(['key' => 'value']));
403
        }
404
    }
405
406
    /**
407
     * @covers FlexiPeeHP\FlexiBeeRO::idExists
408
     */
409
    public function testIdExists()
410
    {
411
        // Remove the following lines when you implement this test.
412
        $this->markTestIncomplete(
413
            'This test has not been implemented yet.'
414
        );
415
    }
416
417
    /**
418
     * @covers FlexiPeeHP\FlexiBeeRO::getRecordID
419
     * @todo   Implement testGetRecordID().
420
     */
421
    public function testGetRecordID()
422
    {
423
        // Remove the following lines when you implement this test.
424
        $this->markTestIncomplete(
425
            'This test has not been implemented yet.'
426
        );
427
    }
428
429
    /**
430
     * @covers FlexiPeeHP\FlexiBeeRO::recordExists
431
     */
432
    public function testRecordExists()
433
    {
434
        $evidence = $this->object->getEvidence();
435
436
        switch ($evidence) {
437
            case null:
438
            case 'c':
439
                $this->markTestSkipped('Unsupported evidence');
440
                break;
441
442
            default:
443
                $flexidata = $this->object->getFlexiData(null, ['limit' => 1]);
444
                if (is_array($flexidata) && !count($flexidata)) {
445
                    $this->markTestSkipped('Empty evidence');
446
                } else {
447
                    if (isset($flexidata['success']) && ($flexidata['success'] == 'false')) {
448
                        $this->markTestSkipped($flexidata['message']);
449
                    } else {
450
                        $this->object->setData(['id' => (int) $flexidata[0]['id']]);
451
                        $this->assertTrue($this->object->recordExists(),
452
                            'First record exists test failed');
453
                        $this->assertFalse($this->object->recordExists(['id' => 0]),
454
                            'Record ID 0 exists');
455
                        $this->assertFalse($this->object->recordExists(['unexistent' => 1]),
456
                            'Unexistent Record exist ?');
457
                    }
458
                }
459
                break;
460
        }
461
    }
462
463
    /**
464
     * @covers FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee
465
     */
466
    public function testGetColumnsFromFlexibee()
467
    {
468
        // Remove the following lines when you implement this test.
469
        $this->markTestIncomplete(
470
            'This test has not been implemented yet.'
471
        );
472
    }
473
474
    /**
475
     * @covers FlexiPeeHP\FlexiBeeRO::getExternalID
476
     * @todo   Implement testGetExternalID().
477
     */
478
    public function testGetExternalID()
479
    {
480
        // Remove the following lines when you implement this test.
481
        $this->markTestIncomplete(
482
            'This test has not been implemented yet.'
483
        );
484
    }
485
486
    /**
487
     * @covers FlexiPeeHP\FlexiBeeRO::getGlobalVersion
488
     * @todo   Implement testGetGlobalVersion().
489
     */
490
    public function testGetGlobalVersion()
491
    {
492
        // Remove the following lines when you implement this test.
493
        $this->markTestIncomplete(
494
            'This test has not been implemented yet.'
495
        );
496
    }
497
498
    /**
499
     * @covers FlexiPeeHP\FlexiBeeRO::getResponseFormat
500
     * @todo   Implement testGetResponseFormat().
501
     */
502
    public function testGetResponseFormat()
503
    {
504
        // Remove the following lines when you implement this test.
505
        $this->markTestIncomplete(
506
            'This test has not been implemented yet.'
507
        );
508
    }
509
510
    /**
511
     * @covers FlexiPeeHP\FlexiBeeRO::getKod
512
     */
513
    public function testGetKod()
514
    {
515
516
        $this->assertEquals('CODE',
517
            $this->object->getKod([$this->object->myKeyColumn => 'code']));
518
519
        $testString[$this->object->nameColumn] = 'Fish clamp -  Úchytka pro instalaci samonosných kabelů '
0 ignored issues
show
Coding Style Comprehensibility introduced by
$testString was never initialized. Although not strictly required by PHP, it is generally a good practice to add $testString = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
520
            .'(3.5 mm)';
521
        $code0                                 = $this->object->getKod($testString);
522
        $this->assertEquals('FISHCLAMPUCHYTKAPR', $code0);
523
        $code1                                 = $this->object->getKod($testString,
524
            false);
525
        $this->assertEquals('FISHCLAMPUCHYTKAPR', $code1);
526
        $code2                                 = $this->object->getKod($testString);
527
        $this->assertEquals('FISHCLAMPUCHYTKAPR1', $code2);
528
        $this->object->setData($testString);
529
        $code3                                 = $this->object->getKod();
530
        $this->assertEquals('FISHCLAMPUCHYTKAPR2', $code3);
531
532
        $this->assertEquals('TEST',
533
            $this->object->getKod([$this->object->nameColumn => 'test']));
534
535
        $this->assertEquals('TEST1', $this->object->getKod('test'));
536
537
        $this->assertEquals('TEST2', $this->object->getKod(['kod' => 'test']));
538
        $this->assertEquals('NOTSET', $this->object->getKod(['kod' => '']));
539
    }
540
541
    /**
542
     * @covers FlexiPeeHP\FlexiBeeRO::logResult
543
     */
544
    public function testLogResult()
545
    {
546
        $this->object->cleanMessages();
547
        $success = json_decode('{"winstrom":{"@version":"1.0","success":"true",'
548
            .'"stats":{"created":"0","updated":"1","deleted":"0","skipped":"0"'
549
            .',"failed":"0"},"results":[{"id":"1","request-id":"ext:SōkoMan.item'
550
            .':5271","ref":"/c/spoje_net_s_r_o_1/skladovy-pohyb/1.json"}]}}');
551
        $this->object->logResult(current($this->object->object2array($success)),
552
            'http://test');
553
554
        $this->assertArrayHasKey('info', $this->object->getStatusMessages(true));
555
556
        $error                          = json_decode('{"winstrom":{"@version":"1.0","success":"false",'
557
            .'"stats":{"created":"0","updated":"0","deleted":"0","skipped":"0"'
558
            .',"failed":"0"},"results":[{"errors":[{"message":"cz.winstrom.'
559
            .'service.WSBusinessException: Zadaný kód není unikátní.\nZadaný'
560
            .' kód není unikátní."}]}]}}');
561
        $this->object->lastResponseCode = 500;
562
        $this->object->logResult(current($this->object->object2array($error)));
563
        $this->assertArrayHasKey('error', $this->object->getStatusMessages(true));
564
    }
565
566
    /**
567
     * @covers FlexiPeeHP\FlexiBeeRO::flexiUrl
568
     */
569
    public function testFlexiUrl()
570
    {
571
        $this->assertEquals("a eq '1' and b eq 'foo'",
572
            $this->object->flexiUrl(['a' => 1, 'b' => 'foo'], 'and'));
573
        $this->assertEquals("a eq '1' or b eq 'bar'",
574
            $this->object->flexiUrl(['a' => 1, 'b' => 'bar'], 'or'));
575
        $this->assertEquals("a eq true or b eq false",
576
            $this->object->flexiUrl(['a' => true, 'b' => false], 'or'));
577
        $this->assertEquals("a is null and b is not null",
578
            $this->object->flexiUrl(['a' => null, 'b' => '!null'], 'and'));
579
    }
580
581
    /**
582
     * @covers FlexiPeeHP\FlexiBeeRO::unifyResponseFormat
583
     */
584
    public function testunifyResponseFormat()
585
    {
586
        $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...
587
        //One Row Test
588
        $test1raw = [$this->object->nameSpace =>
589
            [$this->object->getResponseEvidence() =>
590
                ['id' => 1, 'name' => 'value']
591
            ]
592
        ];
593
594
        $test1expected = [$this->object->getResponseEvidence() =>
595
            [
596
                ['id' => 1, 'name' => 'value']
597
            ]
598
        ];
599
600
        $this->assertEquals($test1expected,
601
            $this->object->unifyResponseFormat($test1raw));
602
603
        //Two Row Test
604
        $test2Raw      = [$this->object->nameSpace =>
605
            [$this->object->getResponseEvidence() =>
606
                [
607
                    ['id' => 1, 'name' => 'value'],
608
                    ['id' => 2, 'name' => 'value2']
609
                ]
610
            ]
611
        ];
612
        $test2expected = [$this->object->getResponseEvidence() =>
613
            [
614
                ['id' => 1, 'name' => 'value'],
615
                ['id' => 2, 'name' => 'value2']
616
            ]
617
        ];
618
619
        $this->assertEquals($test2expected,
620
            $this->object->unifyResponseFormat($test2Raw));
621
    }
622
623
    /**
624
     * @covers FlexiPeeHP\FlexiBeeRO::__toString
625
     */
626
    public function testtoString()
627
    {
628
629
        $identifer = 'ext:test:123';
630
        $this->object->setDataValue('id', $identifer);
631
        $this->assertEquals($identifer, (string) $this->object);
632
633
        $code = 'test';
634
        $this->object->setDataValue('kod', $code);
635
        $this->assertEquals('code:'.$code, (string) $this->object);
636
637
        $this->object->dataReset();
638
        $this->assertEquals('', $this->object->__toString());
639
    }
640
641
    /**
642
     * @covers FlexiPeeHP\FlexiBeeRO::draw
643
     */
644
    public function testDraw($whatWant = NULL)
645
    {
646
        $this->object->setDataValue('kod', 'test');
647
        $this->assertEquals('code:test', $this->object->draw());
648
    }
649
650
    /**
651
     * @covers FlexiPeeHP\FlexiBeeRO::getColumnsInfo
652
     */
653 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...
654
    {
655
        switch ($this->object->getEvidence()) {
656
            case '':
657
            case 'c':
658
            case 'hooks':
659
            case 'changes':
660
            case 'nastaveni':
661
                $this->assertNull($this->object->getColumnsInfo());
662
                $this->assertNotEmpty($this->object->getColumnsInfo('faktura-vydana'),
663
                    'Cannot obtain structure for na evidence');
664
                break;
665
            default:
666
                $this->assertNotEmpty($this->object->getColumnsInfo(),
667
                    'Cannot obtain structure for '.$this->object->getEvidence());
668
                break;
669
        }
670
    }
671
672
    /**
673
     * @covers FlexiPeeHP\FlexiBeeRO::getActionsInfo
674
     */
675 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...
676
    {
677
        switch ($this->object->getEvidence()) {
678
            case '':
679
            case 'c':
680
            case 'hooks':
681
            case 'changes':
682
            case 'nastaveni':
683
                $this->assertNull($this->object->getActionsInfo());
684
                $this->assertNotEmpty($this->object->getActionsInfo('faktura-vydana'),
685
                    'Cannot obtain actions for na evidence');
686
                break;
687
            default:
688
                $this->assertNotEmpty($this->object->getActionsInfo(),
689
                    'Cannot obtain actions for '.$this->object->getEvidence());
690
                break;
691
        }
692
    }
693
694
    /**
695
     * @covers FlexiPeeHP\FlexiBeeRO::getRelationsInfo
696
     */
697 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...
698
    {
699
        switch ($this->object->getEvidence()) {
700
            case '':
701
            case 'c':
702
            case 'hooks':
703
            case 'changes':
704
            case 'nastaveni':
705
                $this->assertNull($this->object->getRelationsInfo());
706
                $this->assertNotEmpty($this->object->getRelationsInfo('faktura-vydana'),
707
                    'Cannot obtain relations for na evidence');
708
                break;
709
            default:
710
                $this->assertNotEmpty($this->object->getRelationsInfo(),
711
                    'Cannot obtain relations for '.$this->object->getEvidence());
712
                break;
713
        }
714
    }
715
716
    /**
717
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceUrl
718
     */
719
    public function testgetEvidenceUrl()
720
    {
721
        $this->assertNotEmpty($this->object->getEvidenceUrl());
722
        $this->assertNotEmpty($this->object->getEvidenceUrl('/properties'));
723
    }
724
725
    /**
726
     * @covers FlexiPeeHP\FlexiBeeRO::evidenceToClassName
727
     */
728
    public function testevidenceToClassName()
729
    {
730
        $this->assertEquals('FakturaVydana',
731
            $this->object->evidenceToClassName('faktura-vydana'));
732
    }
733
734
    /**
735
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceInfo
736
     * @todo   Implement testGetEvidenceInfo().
737
     */
738
    public function testGetEvidenceInfo()
739
    {
740
        // Remove the following lines when you implement this test.
741
        $this->markTestIncomplete(
742
            'This test has not been implemented yet.'
743
        );
744
    }
745
746
    /**
747
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceName
748
     * @todo   Implement testGetEvidenceName().
749
     */
750
    public function testGetEvidenceName()
751
    {
752
        // Remove the following lines when you implement this test.
753
        $this->markTestIncomplete(
754
            'This test has not been implemented yet.'
755
        );
756
    }
757
758
    /**
759
     * @covers FlexiPeeHP\FlexiBeeRO::performAction
760
     * @todo   Implement testPerformAction().
761
     */
762
    public function testPerformAction()
763
    {
764
        // Remove the following lines when you implement this test.
765
        $this->markTestIncomplete(
766
            'This test has not been implemented yet.'
767
        );
768
    }
769
770
    /**
771
     * @covers FlexiPeeHP\FlexiBeeRO::saveResponseToFile
772
     * @todo   Implement testSaveResponseToFile().
773
     */
774
    public function testSaveResponseToFile()
775
    {
776
        // Remove the following lines when you implement this test.
777
        $this->markTestIncomplete(
778
            'This test has not been implemented yet.'
779
        );
780
    }
781
782
    /**
783
     * @covers FlexiPeeHP\FlexiBeeRO::getVazby
784
     * @todo   Implement testGetVazby().
785
     */
786
    public function testGetVazby()
787
    {
788
        // Remove the following lines when you implement this test.
789
        $this->markTestIncomplete(
790
            'This test has not been implemented yet.'
791
        );
792
    }
793
794
}
795