Completed
Push — master ( 8c919d...88350d )
by Vítězslav
20:23
created

FlexiBeeROTest::testGetGlobalVersion()   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
     * We can set only evidence defined in EvidenceList class
126
     *
127
     * @covers FlexiPeeHP\FlexiBeeRO::setEvidence
128
     * @expectedException \Exception
129
     */
130
    public function testSetEvidence()
131
    {
132
        $this->object->setEvidence('adresar');
133
        $this->assertEquals('adresar', $this->object->evidence);
134
        $this->object->setPrefix('c');
135
        $this->object->setEvidence('fail');
136
    }
137
138
    /**
139
     * @covers FlexiPeeHP\FlexiBeeRO::setCompany
140
     */
141
    public function testSetCompany()
142
    {
143
        $this->object->setCompany('test_s_r_o_');
144
        $this->assertEquals('test_s_r_o_', $this->object->company);
145
    }
146
147
    /**
148
     * @covers FlexiPeeHP\FlexiBeeRO::object2array
149
     */
150
    public function testObject2array()
151
    {
152
        $this->assertNull($this->object->object2array(new \stdClass()));
153
        $this->assertEquals(
154
            [
155
            'item' => 1,
156
            'arrItem' => ['a', 'b' => 'c']
157
            ]
158
            , $this->object->object2array(new \Test\ObjectForTesting()));
159
    }
160
161
    /**
162
     * @covers FlexiPeeHP\FlexiBeeRO::objectToID
163
     */
164
    public function testObjectToID()
165
    {
166
        $id = \Ease\Sand::randomNumber(1, 9999);
167
        $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 166 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...
168
        $this->assertEquals([$id], $this->object->objectToID([$this->object]));
169
170
        $this->object->setDataValue('kod', 'TEST');
171
        $this->assertEquals('code:TEST',
172
            $this->object->objectToID($this->object));
173
174
        $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...
175
    }
176
177
    /**
178
     * @covers FlexiPeeHP\FlexiBeeRO::performRequest
179
     */
180
    public function testPerformRequest()
181
    {
182
        $evidence = $this->object->getEvidence();
183
        switch ($evidence) {
184
            case null:
185
            case '':
186
            case 'test':
187
            case 'c':
188
                $this->object->evidence  = 'c';
189
                $this->object->prefix    = '';
190
                $this->object->company   = '';
191
                $this->object->nameSpace = 'companies';
192
                $json                    = $this->object->performRequest();
193
                $this->assertArrayHasKey('company', $json);
194
195
                $xml = $this->object->performRequest(null, 'GET', 'xml');
196
                $this->assertArrayHasKey('company', $xml);
197
                break;
198
199
            default:
200
                $json = $this->object->performRequest($evidence.'.json');
201
                if (array_key_exists('message', $json)) {
202
                    $this->assertArrayHasKey('@version', $json);
203
                } else {
204
                    $this->assertArrayHasKey($evidence, $json);
205
                }
206
                break;
207
        }
208
209
210
        $err = $this->object->performRequest('error.json');
211
        $this->assertArrayHasKey('success', $err);
212
        $this->assertEquals('false', $err['success']);
213
    }
214
215
    /**
216
     * @covers FlexiPeeHP\FlexiBeeRO::setAction
217
     */
218
    public function testSetAction()
219
    {
220
        if (empty($this->object->evidence) || ($this->object->evidence == 'c')) {
221
            $this->markTestSkipped('no evidence set');
222
        } else {
223
            $this->assertTrue($this->object->setAction('new'));
224
            $this->object->actionsAvailable = [];
225
            $this->assertFalse($this->object->setAction('none'));
226
            $this->object->actionsAvailable = ['copy'];
227
            $this->assertFalse($this->object->setAction('none'));
228
        }
229
    }
230
231
    /**
232
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidence
233
     */
234
    public function testGetEvidence()
235
    {
236
        $this->assertEquals($this->object->evidence,
237
            $this->object->getEvidence());
238
    }
239
240
    /**
241
     * @covers FlexiPeeHP\FlexiBeeRO::getCompany
242
     */
243
    public function testGetCompany()
244
    {
245
        $this->assertEquals($this->object->company, $this->object->getCompany());
246
    }
247
248
    /**
249
     * @covers FlexiPeeHP\FlexiBeeRO::getResponseEvidence
250
     */
251
    public function testGetResponseEvidence()
252
    {
253
        switch ($this->object->getEvidence()) {
254
            case 'c':
255
                $this->assertEquals('companies',
256
                    $this->object->getResponseEvidence());
257
                break;
258
259
            default:
260
                $this->assertEquals($this->object->getEvidence(),
261
                    $this->object->getResponseEvidence());
262
                break;
263
        }
264
    }
265
266
    /**
267
     * @covers FlexiPeeHP\FlexiBeeRO::getLastInsertedId
268
     * @depends testInsertToFlexiBee
269
     */
270
    public function testGetLastInsertedId()
271
    {
272
        $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...
273
    }
274
275
    /**
276
     * @covers FlexiPeeHP\FlexiBeeRO::xml2array
277
     */
278
    public function testXml2array()
279
    {
280
        $xml = '<card xmlns="http://businesscard.org">
281
   <name>John Doe</name>
282
   <title>CEO, Widget Inc.</title>
283
   <email>[email protected]</email>
284
   <phone>(202) 456-1414</phone>
285
   <logo url="widget.gif"/>
286
   <a><b>c</b></a>
287
 </card>';
288
289
        $data = ['name' => 'John Doe', 'title' => 'CEO, Widget Inc.', 'email' => '[email protected]',
290
            'phone' => '(202) 456-1414', 'logo' => '', 'a' => [['b' => 'c']]];
291
292
293
        $this->assertEquals($data, $this->object->xml2array($xml));
294
    }
295
296
    /**
297
     * @covers FlexiPeeHP\FlexiBeeRO::disconnect
298
     *
299
     * @depends testPerformRequest
300
     * @depends testLoadFlexiData
301
     * @depends testGetFlexiRow
302
     * @depends testGetFlexiData
303
     * @depends testLoadFromFlexiBee
304
     * @depends testInsertToFlexiBee
305
     * @depends testIdExists
306
     * @depends testRecordExists
307
     * @depends testGetColumnsFromFlexibee
308
     * @depends testSearchString
309
     */
310
    public function testDisconnect()
311
    {
312
        $this->object->disconnect();
313
        $this->assertNull($this->object->curl);
314
    }
315
316
    /**
317
     * @covers FlexiPeeHP\FlexiBeeRO::__destruct
318
     * @depends testDisconnect
319
     */
320
    public function testdestruct()
321
    {
322
        $this->markTestSkipped();
323
    }
324
325
    /**
326
     * @covers FlexiPeeHP\FlexiBeeRO::getFlexiRow
327
     */
328
    public function testGetFlexiRow()
329
    {
330
        $this->object->getFlexiRow(0);
331
        $this->object->getFlexiRow(1);
332
    }
333
334
    /**
335
     * @covers FlexiPeeHP\FlexiBeeRO::getFlexiData
336
     */
337
    public function testGetFlexiData()
338
    {
339
        $evidence = $this->object->getEvidence();
340
341
        switch ($evidence) {
342
            case null:
343
                $this->markTestSkipped('Unsupported evidence');
344
                break;
345
            case 'c':
346
                $this->object->evidence  = 'c';
347
                $this->object->prefix    = '';
348
                $this->object->company   = '';
349
                $this->object->nameSpace = 'companies';
350
                $flexidata               = $this->object->getFlexiData();
351
                $this->assertArrayHasKey('company', $flexidata);
352
                break;
353
354
            default:
355
                $flexidata = $this->object->getFlexiData();
356 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...
357
                    $this->markTestSkipped('Empty evidence');
358
                } else {
359
                    $this->assertArrayHasKey(0, $flexidata);
360
                    $this->assertArrayHasKey('id', $flexidata[0]);
361
                    $filtrered = $this->object->getFlexiData(null,
362
                        "id = ".$flexidata[0]['id']);
363
                    $this->assertArrayHasKey(0, $filtrered);
364
                    $this->assertArrayHasKey('id', $filtrered[0]);
365
                }
366
                break;
367
        }
368
    }
369
370
    /**
371
     * @covers FlexiPeeHP\FlexiBeeRO::loadFromFlexiBee
372
     */
373
    public function testLoadFromFlexiBee()
374
    {
375
        $this->object->loadFromFlexiBee();
376
        $this->object->loadFromFlexiBee(222);
377
    }
378
379
    /**
380
     * @covers FlexiPeeHP\FlexiBeeRO::jsonizeData
381
     */
382
    public function testJsonizeData()
383
    {
384
        $this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"}}}',
385
            $this->object->jsonizeData(['key' => 'value']));
386
387
        if (!empty($this->object->evidence) && ($this->object->evidence != 'c')) {
388
            $this->object->setAction('copy');
389
            $this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"},"'.$this->object->evidence.'@action":"copy"}}',
390
                $this->object->jsonizeData(['key' => 'value']));
391
        }
392
    }
393
394
    /**
395
     * @covers FlexiPeeHP\FlexiBeeRO::idExists
396
     */
397
    public function testIdExists()
398
    {
399
        // Remove the following lines when you implement this test.
400
        $this->markTestIncomplete(
401
            'This test has not been implemented yet.'
402
        );
403
    }
404
405
    /**
406
     * @covers FlexiPeeHP\FlexiBeeRO::recordExists
407
     */
408
    public function testRecordExists()
409
    {
410
        $evidence = $this->object->getEvidence();
411
412
        switch ($evidence) {
413
            case null:
414
            case 'c':
415
                $this->markTestSkipped('Unsupported evidence');
416
                break;
417
418
            default:
419
                $flexidata = $this->object->getFlexiData(null, ['limit' => 1]);
420
                if (is_array($flexidata) && !count($flexidata)) {
421
                    $this->markTestSkipped('Empty evidence');
422
                } else {
423
                    if (isset($flexidata['success']) && ($flexidata['success'] == 'false')) {
424
                        $this->markTestSkipped($flexidata['message']);
425
                    } else {
426
                        $this->object->setData(['id' => (int) $flexidata[0]['id']]);
427
                        $this->assertTrue($this->object->recordExists(),
428
                            'First record exists test failed');
429
                        $this->assertFalse($this->object->recordExists(['id' => 0]),
430
                            'Record ID 0 exists');
431
                        $this->assertFalse($this->object->recordExists(['unexistent' => 1]),
432
                            'Unexistent Record exist ?');
433
                    }
434
                }
435
                break;
436
        }
437
    }
438
439
    /**
440
     * @covers FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee
441
     */
442
    public function testGetColumnsFromFlexibee()
443
    {
444
        // Remove the following lines when you implement this test.
445
        $this->markTestIncomplete(
446
            'This test has not been implemented yet.'
447
        );
448
    }
449
450
    /**
451
     * @covers FlexiPeeHP\FlexiBeeRO::getExternalID
452
     * @todo   Implement testGetExternalID().
453
     */
454
    public function testGetExternalID()
455
    {
456
        // Remove the following lines when you implement this test.
457
        $this->markTestIncomplete(
458
            'This test has not been implemented yet.'
459
        );
460
    }
461
462
    /**
463
     * @covers FlexiPeeHP\FlexiBeeRO::getGlobalVersion
464
     * @todo   Implement testGetGlobalVersion().
465
     */
466
    public function testGetGlobalVersion()
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::getResponseFormat
476
     * @todo   Implement testGetResponseFormat().
477
     */
478
    public function testGetResponseFormat()
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::getKod
488
     */
489
    public function testGetKod()
490
    {
491
492
        $this->assertEquals('CODE',
493
            $this->object->getKod([$this->object->myKeyColumn => 'code']));
494
495
        $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...
496
            .'(3.5 mm)';
497
        $code0                                 = $this->object->getKod($testString);
498
        $this->assertEquals('FISHCLAMPUCHYTKAPR', $code0);
499
        $code1                                 = $this->object->getKod($testString,
500
            false);
501
        $this->assertEquals('FISHCLAMPUCHYTKAPR', $code1);
502
        $code2                                 = $this->object->getKod($testString);
503
        $this->assertEquals('FISHCLAMPUCHYTKAPR1', $code2);
504
        $this->object->setData($testString);
505
        $code3                                 = $this->object->getKod();
506
        $this->assertEquals('FISHCLAMPUCHYTKAPR2', $code3);
507
508
        $this->assertEquals('TEST',
509
            $this->object->getKod([$this->object->nameColumn => 'test']));
510
511
        $this->assertEquals('TEST1', $this->object->getKod('test'));
512
513
        $this->assertEquals('TEST2', $this->object->getKod(['kod' => 'test']));
514
        $this->assertEquals('NOTSET', $this->object->getKod(['kod' => '']));
515
    }
516
517
    /**
518
     * @covers FlexiPeeHP\FlexiBeeRO::logResult
519
     */
520
    public function testLogResult()
521
    {
522
        $this->object->cleanMessages();
523
        $success = json_decode('{"winstrom":{"@version":"1.0","success":"true",'
524
            .'"stats":{"created":"0","updated":"1","deleted":"0","skipped":"0"'
525
            .',"failed":"0"},"results":[{"id":"1","request-id":"ext:SōkoMan.item'
526
            .':5271","ref":"/c/spoje_net_s_r_o_1/skladovy-pohyb/1.json"}]}}');
527
        $this->object->logResult(current($this->object->object2array($success)),
528
            'http://test');
529
530
        $this->assertArrayHasKey('info', $this->object->getStatusMessages(true));
531
532
        $error                          = json_decode('{"winstrom":{"@version":"1.0","success":"false",'
533
            .'"stats":{"created":"0","updated":"0","deleted":"0","skipped":"0"'
534
            .',"failed":"0"},"results":[{"errors":[{"message":"cz.winstrom.'
535
            .'service.WSBusinessException: Zadaný kód není unikátní.\nZadaný'
536
            .' kód není unikátní."}]}]}}');
537
        $this->object->lastResponseCode = 500;
538
        $this->object->logResult(current($this->object->object2array($error)));
539
        $this->assertArrayHasKey('error', $this->object->getStatusMessages(true));
540
    }
541
542
    /**
543
     * @covers FlexiPeeHP\FlexiBeeRO::flexiUrl
544
     */
545
    public function testFlexiUrl()
546
    {
547
        $this->assertEquals("a eq '1' and b eq 'foo'",
548
            $this->object->flexiUrl(['a' => 1, 'b' => 'foo'], 'and'));
549
        $this->assertEquals("a eq '1' or b eq 'bar'",
550
            $this->object->flexiUrl(['a' => 1, 'b' => 'bar'], 'or'));
551
        $this->assertEquals("a eq true or b eq false",
552
            $this->object->flexiUrl(['a' => true, 'b' => false], 'or'));
553
        $this->assertEquals("a is null and b is not null",
554
            $this->object->flexiUrl(['a' => null, 'b' => '!null'], 'and'));
555
    }
556
557
    /**
558
     * @covers FlexiPeeHP\FlexiBeeRO::unifyResponseFormat
559
     */
560
    public function testunifyResponseFormat()
561
    {
562
        $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...
563
        //One Row Test
564
        $test1raw = [$this->object->nameSpace =>
565
                [$this->object->getResponseEvidence() =>
566
                    ['id' => 1, 'name' => 'value']
567
            ]
568
        ];
569
570
        $test1expected = [$this->object->getResponseEvidence() =>
571
                [
572
                    ['id' => 1, 'name' => 'value']
573
            ]
574
        ];
575
576
        $this->assertEquals($test1expected,
577
            $this->object->unifyResponseFormat($test1raw));
578
579
        //Two Row Test
580
        $test2Raw      = [$this->object->nameSpace =>
581
                [$this->object->getResponseEvidence() =>
582
                    [
583
                        ['id' => 1, 'name' => 'value'],
584
                        ['id' => 2, 'name' => 'value2']
585
                ]
586
            ]
587
        ];
588
        $test2expected = [$this->object->getResponseEvidence() =>
589
                [
590
                    ['id' => 1, 'name' => 'value'],
591
                    ['id' => 2, 'name' => 'value2']
592
            ]
593
        ];
594
595
        $this->assertEquals($test2expected,
596
            $this->object->unifyResponseFormat($test2Raw));
597
    }
598
599
    /**
600
     * @covers FlexiPeeHP\FlexiBeeRO::__toString
601
     */
602
    public function testtoString()
603
    {
604
605
        $identifer = 'ext:test:123';
606
        $this->object->setDataValue('id', $identifer);
607
        $this->assertEquals($identifer, (string) $this->object);
608
609
        $code = 'test';
610
        $this->object->setDataValue('kod', $code);
611
        $this->assertEquals('code:'.$code, (string) $this->object);
612
613
        $this->object->dataReset();
614
        $this->assertEquals('', $this->object->__toString());
615
    }
616
617
    /**
618
     * @covers FlexiPeeHP\FlexiBeeRO::draw
619
     */
620
    public function testDraw($whatWant = NULL)
621
    {
622
        $this->object->setDataValue('kod', 'test');
623
        $this->assertEquals('code:test', $this->object->draw());
624
    }
625
626
    /**
627
     * @covers FlexiPeeHP\FlexiBeeRO::getColumnsInfo
628
     */
629 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...
630
    {
631
        switch ($this->object->getEvidence()) {
632
            case '':
633
            case 'c':
634
            case 'hooks':
635
            case 'changes':
636
            case 'nastaveni':
637
                $this->assertNull($this->object->getColumnsInfo());
638
                $this->assertNotEmpty($this->object->getColumnsInfo('faktura-vydana'),
639
                    'Cannot obtain structure for na evidence');
640
                break;
641
            default:
642
                $this->assertNotEmpty($this->object->getColumnsInfo(),
643
                    'Cannot obtain structure for '.$this->object->getEvidence());
644
                break;
645
        }
646
    }
647
648
    /**
649
     * @covers FlexiPeeHP\FlexiBeeRO::getActionsInfo
650
     */
651 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...
652
    {
653
        switch ($this->object->getEvidence()) {
654
            case '':
655
            case 'c':
656
            case 'hooks':
657
            case 'changes':
658
            case 'nastaveni':
659
                $this->assertNull($this->object->getActionsInfo());
660
                $this->assertNotEmpty($this->object->getActionsInfo('faktura-vydana'),
661
                    'Cannot obtain actions for na evidence');
662
                break;
663
            default:
664
                $this->assertNotEmpty($this->object->getActionsInfo(),
665
                    'Cannot obtain actions for '.$this->object->getEvidence());
666
                break;
667
        }
668
    }
669
670
    /**
671
     * @covers FlexiPeeHP\FlexiBeeRO::getRelationsInfo
672
     */
673 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...
674
    {
675
        switch ($this->object->getEvidence()) {
676
            case '':
677
            case 'c':
678
            case 'hooks':
679
            case 'changes':
680
            case 'nastaveni':
681
                $this->assertNull($this->object->getRelationsInfo());
682
                $this->assertNotEmpty($this->object->getRelationsInfo('faktura-vydana'),
683
                    'Cannot obtain relations for na evidence');
684
                break;
685
            default:
686
                $this->assertNotEmpty($this->object->getRelationsInfo(),
687
                    'Cannot obtain relations for '.$this->object->getEvidence());
688
                break;
689
        }
690
    }
691
692
    /**
693
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceUrl
694
     */
695
    public function testgetEvidenceUrl()
696
    {
697
        $this->assertNotEmpty($this->object->getEvidenceUrl());
698
        $this->assertNotEmpty($this->object->getEvidenceUrl('/properties'));
699
    }
700
701
    /**
702
     * @covers FlexiPeeHP\FlexiBeeRO::evidenceToClassName
703
     */
704
    public function testevidenceToClassName()
705
    {
706
        $this->assertEquals('FakturaVydana',
707
            $this->object->evidenceToClassName('faktura-vydana'));
708
    }
709
710
    /**
711
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceInfo
712
     * @todo   Implement testGetEvidenceInfo().
713
     */
714
    public function testGetEvidenceInfo()
715
    {
716
        // Remove the following lines when you implement this test.
717
        $this->markTestIncomplete(
718
            'This test has not been implemented yet.'
719
        );
720
    }
721
    /**
722
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceName
723
     * @todo   Implement testGetEvidenceName().
724
     */
725
    public function testGetEvidenceName()
726
    {
727
        // Remove the following lines when you implement this test.
728
        $this->markTestIncomplete(
729
            'This test has not been implemented yet.'
730
        );
731
    }
732
733
    /**
734
     * @covers FlexiPeeHP\FlexiBeeRO::performAction
735
     * @todo   Implement testPerformAction().
736
     */
737
    public function testPerformAction()
738
    {
739
        // Remove the following lines when you implement this test.
740
        $this->markTestIncomplete(
741
            'This test has not been implemented yet.'
742
        );
743
    }
744
}
745