Completed
Push — master ( 000b3f...c99034 )
by Vítězslav
09:15
created

FlexiBeeROTest::testunifyResponseFormat()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 0
dl 0
loc 38
rs 8.8571
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
        $mock->__construct('',
52
            [
53
            'company' => 'Firma_s_r_o_',
54
            'url' => 'https://flexibee.firma.cz/',
55
            'user' => 'rest',
56
            'password' => '-dj3x21xaA_', 'evidence' => $evidence]);
57
    }
58
59
    /**
60
     * @covers FlexiPeeHP\FlexiBeeRO::curlInit
61
     */
62
    public function testCurlInit()
63
    {
64
        $this->object->curlInit();
65
        $this->assertTrue(is_resource($this->object->curl));
66
    }
67
68
    /**
69
     * @covers FlexiPeeHP\FlexiBeeRO::processInit
70
     */
71
    public function testProcessInit()
72
    {
73
        $this->object->processInit(['id' => 1]);
74
        $this->assertEquals(1, $this->object->getDataValue('id'));
75
        if (!is_null($this->object->evidence) && $this->object->evidence != 'test') {
76
            $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...
77
                ['limit' => 1]);
78
            $this->object->processInit((int) current($firstID));
79
            $this->assertNotEmpty($this->object->__toString());
80
        }
81
    }
82
83
    /**
84
     * @covers FlexiPeeHP\FlexiBeeRO::setUp
85
     */
86
    public function testSetUp()
87
    {
88
        $this->object->setUp(
89
            [
90
                'company' => 'cmp',
91
                'url' => 'url',
92
                'user' => 'usr',
93
                'password' => 'pwd',
94
                'evidence' => 'smlouva'
95
            ]
96
        );
97
        $this->assertEquals('cmp', $this->object->company);
98
        $this->assertEquals('url', $this->object->url);
99
        $this->assertEquals('usr', $this->object->user);
100
        $this->assertEquals('pwd', $this->object->password);
101
    }
102
103
    /**
104
     * @covers FlexiPeeHP\FlexiBeeRO::setEvidence
105
     */
106
    public function testSetEvidence()
107
    {
108
        $this->object->setEvidence('nastaveni');
109
        $this->assertEquals('nastaveni', $this->object->evidence);
110
    }
111
112
    /**
113
     * @covers FlexiPeeHP\FlexiBeeRO::setCompany
114
     */
115
    public function testSetCompany()
116
    {
117
        $this->object->setCompany('test_s_r_o_');
118
        $this->assertEquals('test_s_r_o_', $this->object->company);
119
    }
120
121
    /**
122
     * @covers FlexiPeeHP\FlexiBeeRO::object2array
123
     */
124
    public function testObject2array()
125
    {
126
        $this->assertNull($this->object->object2array(new \stdClass()));
127
        $this->assertEquals(
128
            [
129
            'item' => 1,
130
            'arrItem' => ['a', 'b' => 'c']
131
            ]
132
            , $this->object->object2array(new \Test\ObjectForTesting()));
133
    }
134
135
    /**
136
     * @covers FlexiPeeHP\FlexiBeeRO::objectToID
137
     */
138
    public function testObjectToID()
139
    {
140
        $id = \Ease\Sand::randomNumber(1, 9999);
141
        $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 140 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...
142
        $this->assertEquals([$id], $this->object->objectToID([$this->object]));
143
144
        $this->object->setDataValue('kod', 'TEST');
145
        $this->assertEquals('code:TEST',
146
            $this->object->objectToID($this->object));
147
148
        $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...
149
    }
150
151
    /**
152
     * @covers FlexiPeeHP\FlexiBeeRO::performRequest
153
     */
154
    public function testPerformRequest()
155
    {
156
        $evidence = $this->object->getEvidence();
157
        switch ($evidence) {
158
            case null:
159
            case '':
160
            case 'test':
161
            case 'c':
162
                $this->object->evidence  = 'c';
163
                $this->object->prefix    = '';
164
                $this->object->company   = '';
165
                $this->object->nameSpace = 'companies';
166
                $json                    = $this->object->performRequest();
167
                $this->assertArrayHasKey('company', $json);
168
169
                $xml = $this->object->performRequest(null, 'GET', 'xml');
170
                $this->assertArrayHasKey('company', $xml);
171
                break;
172
173
            default:
174
                $json = $this->object->performRequest($evidence.'.json');
175
                if (array_key_exists('message', $json)) {
176
                    $this->assertArrayHasKey('@version', $json);
177
                } else {
178
                    $this->assertArrayHasKey($evidence, $json);
179
                }
180
                break;
181
        }
182
183
184
        $err = $this->object->performRequest('error.json');
185
        $this->assertArrayHasKey('success', $err);
186
        $this->assertEquals('false', $err['success']);
187
    }
188
189
    /**
190
     * @covers FlexiPeeHP\FlexiBeeRO::setAction
191
     */
192
    public function testSetAction()
193
    {
194
        $this->assertTrue($this->object->setAction('none'));
195
        $this->object->actionsAvailable = [];
196
        $this->assertFalse($this->object->setAction('none'));
197
        $this->object->actionsAvailable = ['copy'];
198
        $this->assertFalse($this->object->setAction('none'));
199
    }
200
201
    /**
202
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidence
203
     */
204
    public function testGetEvidence()
205
    {
206
        $this->assertEquals($this->object->evidence,
207
            $this->object->getEvidence());
208
    }
209
210
    /**
211
     * @covers FlexiPeeHP\FlexiBeeRO::getCompany
212
     */
213
    public function testGetCompany()
214
    {
215
        $this->assertEquals($this->object->company, $this->object->getCompany());
216
    }
217
218
    /**
219
     * @covers FlexiPeeHP\FlexiBeeRO::getResponseEvidence
220
     */
221
    public function testGetResponseEvidence()
222
    {
223
        switch ($this->object->getEvidence()) {
224
            case 'c':
225
                $this->assertEquals('companies',
226
                    $this->object->getResponseEvidence());
227
                break;
228
229
            default:
230
                $this->assertEquals($this->object->getEvidence(),
231
                    $this->object->getResponseEvidence());
232
                break;
233
        }
234
    }
235
236
    /**
237
     * @covers FlexiPeeHP\FlexiBeeRO::getLastInsertedId
238
     * @depends testInsertToFlexiBee
239
     */
240
    public function testGetLastInsertedId()
241
    {
242
        $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\RadaPokladniPohyb, 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...
243
    }
244
245
    /**
246
     * @covers FlexiPeeHP\FlexiBeeRO::xml2array
247
     */
248
    public function testXml2array()
249
    {
250
        $xml = '<card xmlns="http://businesscard.org">
251
   <name>John Doe</name>
252
   <title>CEO, Widget Inc.</title>
253
   <email>[email protected]</email>
254
   <phone>(202) 456-1414</phone>
255
   <logo url="widget.gif"/>
256
   <a><b>c</b></a>
257
 </card>';
258
259
        $data = ['name' => 'John Doe', 'title' => 'CEO, Widget Inc.', 'email' => '[email protected]',
260
            'phone' => '(202) 456-1414', 'logo' => '', 'a' => [['b' => 'c']]];
261
262
263
        $this->assertEquals($data, $this->object->xml2array($xml));
264
    }
265
266
    /**
267
     * @covers FlexiPeeHP\FlexiBeeRO::disconnect
268
     *
269
     * @depends testPerformRequest
270
     * @depends testLoadFlexiData
271
     * @depends testGetFlexiRow
272
     * @depends testGetFlexiData
273
     * @depends testLoadFromFlexiBee
274
     * @depends testInsertToFlexiBee
275
     * @depends testIdExists
276
     * @depends testRecordExists
277
     * @depends testGetColumnsFromFlexibee
278
     * @depends testSearchString
279
     */
280
    public function testDisconnect()
281
    {
282
        $this->object->disconnect();
283
        $this->assertNull($this->object->curl);
284
    }
285
286
    /**
287
     * @covers FlexiPeeHP\FlexiBeeRO::__destruct
288
     * @depends testDisconnect
289
     */
290
    public function testdestruct()
291
    {
292
        $this->markTestSkipped();
293
    }
294
295
    /**
296
     * @covers FlexiPeeHP\FlexiBeeRO::getFlexiRow
297
     */
298
    public function testGetFlexiRow()
299
    {
300
        $this->object->getFlexiRow(0);
301
        $this->object->getFlexiRow(1);
302
    }
303
304
    /**
305
     * @covers FlexiPeeHP\FlexiBeeRO::getFlexiData
306
     */
307
    public function testGetFlexiData()
308
    {
309
        $evidence = $this->object->getEvidence();
310
311
        switch ($evidence) {
312
            case null:
313
                $this->markTestSkipped('Unsupported evidence');
314
                break;
315
            case 'c':
316
                $this->object->evidence  = 'c';
317
                $this->object->prefix    = '';
318
                $this->object->company   = '';
319
                $this->object->nameSpace = 'companies';
320
                $flexidata               = $this->object->getFlexiData();
321
                $this->assertArrayHasKey('company', $flexidata);
322
                break;
323
324
            default:
325
                $flexidata = $this->object->getFlexiData();
326 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...
327
                    $this->markTestSkipped('Empty evidence');
328
                } else {
329
                    $this->assertArrayHasKey(0, $flexidata);
330
                    $this->assertArrayHasKey('id', $flexidata[0]);
331
                    $filtrered = $this->object->getFlexiData(null,
332
                        "id = ".$flexidata[0]['id']);
333
                    $this->assertArrayHasKey(0, $filtrered);
334
                    $this->assertArrayHasKey('id', $filtrered[0]);
335
                }
336
                break;
337
        }
338
    }
339
340
    /**
341
     * @covers FlexiPeeHP\FlexiBeeRO::loadFromFlexiBee
342
     */
343
    public function testLoadFromFlexiBee()
344
    {
345
        $this->object->loadFromFlexiBee();
346
        $this->object->loadFromFlexiBee(222);
347
    }
348
349
    /**
350
     * @covers FlexiPeeHP\FlexiBeeRO::jsonizeData
351
     */
352
    public function testJsonizeData()
353
    {
354
        $this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"}}}',
355
            $this->object->jsonizeData(['key' => 'value']));
356
        $this->object->setAction('copy');
357
        $this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"},"'.$this->object->evidence.'@action":"copy"}}',
358
            $this->object->jsonizeData(['key' => 'value']));
359
    }
360
361
    /**
362
     * @covers FlexiPeeHP\FlexiBeeRO::idExists
363
     */
364
    public function testIdExists()
365
    {
366
        // Remove the following lines when you implement this test.
367
        $this->markTestIncomplete(
368
            'This test has not been implemented yet.'
369
        );
370
    }
371
372
    /**
373
     * @covers FlexiPeeHP\FlexiBeeRO::recordExists
374
     */
375
    public function testRecordExists()
376
    {
377
        $evidence = $this->object->getEvidence();
378
379
        switch ($evidence) {
380
            case null:
381
            case 'c':
382
                $this->markTestSkipped('Unsupported evidence');
383
                break;
384
385
            default:
386
                $flexidata = $this->object->getFlexiData(null, ['limit' => 1]);
387
                if (is_array($flexidata) && !count($flexidata)) {
388
                    $this->markTestSkipped('Empty evidence');
389
                } else {
390
                    if (isset($flexidata['success']) && ($flexidata['success'] == 'false')) {
391
                        $this->markTestSkipped($flexidata['message']);
392
                    } else {
393
                        $this->object->setData(['id' => (int) $flexidata[0]['id']]);
394
                        $this->assertTrue($this->object->recordExists());
395
                        $this->assertFalse($this->object->recordExists(['id' => 0]));
396
                        $this->assertFalse($this->object->recordExists(['unexistent' => 1]));
397
                    }
398
                }
399
                break;
400
        }
401
    }
402
403
    /**
404
     * @covers FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee
405
     */
406
    public function testGetColumnsFromFlexibee()
407
    {
408
        // Remove the following lines when you implement this test.
409
        $this->markTestIncomplete(
410
            'This test has not been implemented yet.'
411
        );
412
    }
413
414
    /**
415
     * @covers FlexiPeeHP\FlexiBeeRO::getKod
416
     */
417
    public function testGetKod()
418
    {
419
420
        $this->assertEquals('CODE',
421
            $this->object->getKod([$this->object->myKeyColumn => 'code']));
422
423
        $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...
424
            .'(3.5 mm)';
425
        $code0                                 = $this->object->getKod($testString);
426
        $this->assertEquals('FISHCLAMPUCHYTKAPR', $code0);
427
        $code1                                 = $this->object->getKod($testString,
428
            false);
429
        $this->assertEquals('FISHCLAMPUCHYTKAPR', $code1);
430
        $code2                                 = $this->object->getKod($testString);
431
        $this->assertEquals('FISHCLAMPUCHYTKAPR1', $code2);
432
        $this->object->setData($testString);
433
        $code3                                 = $this->object->getKod();
434
        $this->assertEquals('FISHCLAMPUCHYTKAPR2', $code3);
435
436
        $this->assertEquals('TEST',
437
            $this->object->getKod([$this->object->nameColumn => 'test']));
438
439
        $this->assertEquals('TEST1', $this->object->getKod('test'));
440
441
        $this->assertEquals('TEST2', $this->object->getKod(['kod' => 'test']));
442
        $this->assertEquals('NOTSET', $this->object->getKod(['kod' => '']));
443
    }
444
445
    /**
446
     * @covers FlexiPeeHP\FlexiBeeRO::logResult
447
     */
448
    public function testLogResult()
449
    {
450
        $this->object->cleanMessages();
451
        $success = json_decode('{"winstrom":{"@version":"1.0","success":"true",'
452
            .'"stats":{"created":"0","updated":"1","deleted":"0","skipped":"0"'
453
            .',"failed":"0"},"results":[{"id":"1","request-id":"ext:SōkoMan.item'
454
            .':5271","ref":"/c/spoje_net_s_r_o_1/skladovy-pohyb/1.json"}]}}');
455
        $this->object->logResult(current($this->object->object2array($success)),
456
            'http://test');
457
458
        $this->assertArrayHasKey('info', $this->object->getStatusMessages(true));
459
460
        $error                          = json_decode('{"winstrom":{"@version":"1.0","success":"false",'
461
            .'"stats":{"created":"0","updated":"0","deleted":"0","skipped":"0"'
462
            .',"failed":"0"},"results":[{"errors":[{"message":"cz.winstrom.'
463
            .'service.WSBusinessException: Zadaný kód není unikátní.\nZadaný'
464
            .' kód není unikátní."}]}]}}');
465
        $this->object->lastResponseCode = 500;
466
        $this->object->logResult(current($this->object->object2array($error)));
467
        $this->assertArrayHasKey('error', $this->object->getStatusMessages(true));
468
    }
469
470
    /**
471
     * @covers FlexiPeeHP\FlexiBeeRO::flexiUrl
472
     */
473
    public function testFlexiUrl()
474
    {
475
        $this->assertEquals("a eq '1' and b eq 'foo'",
476
            $this->object->flexiUrl(['a' => 1, 'b' => 'foo'], 'and'));
477
        $this->assertEquals("a eq '1' or b eq 'bar'",
478
            $this->object->flexiUrl(['a' => 1, 'b' => 'bar'], 'or'));
479
        $this->assertEquals("a eq true or b eq false",
480
            $this->object->flexiUrl(['a' => true, 'b' => false], 'or'));
481
        $this->assertEquals("a is null and b is not null",
482
            $this->object->flexiUrl(['a' => null, 'b' => '!null'], 'and'));
483
    }
484
485
    /**
486
     * @covers FlexiPeeHP\FlexiBeeRO::unifyResponseFormat
487
     */
488
    public function testunifyResponseFormat()
489
    {
490
        $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...
491
        //One Row Test
492
        $test1raw = [$this->object->nameSpace =>
493
            [$this->object->getResponseEvidence() =>
494
                ['id' => 1, 'name' => 'value']
495
            ]
496
        ];
497
498
        $test1expected = [$this->object->getResponseEvidence() =>
499
            [
500
                ['id' => 1, 'name' => 'value']
501
            ]
502
        ];
503
504
        $this->assertEquals($test1expected,
505
            $this->object->unifyResponseFormat($test1raw));
506
507
        //Two Row Test
508
        $test2Raw      = [$this->object->nameSpace =>
509
            [$this->object->getResponseEvidence() =>
510
                [
511
                    ['id' => 1, 'name' => 'value'],
512
                    ['id' => 2, 'name' => 'value2']
513
                ]
514
            ]
515
        ];
516
        $test2expected = [$this->object->getResponseEvidence() =>
517
            [
518
                ['id' => 1, 'name' => 'value'],
519
                ['id' => 2, 'name' => 'value2']
520
            ]
521
        ];
522
523
        $this->assertEquals($test2expected,
524
            $this->object->unifyResponseFormat($test2Raw));
525
    }
526
527
    /**
528
     * @covers FlexiPeeHP\FlexiBeeRO::__toString
529
     */
530
    public function testtoString()
531
    {
532
533
        $identifer = 'ext:test:123';
534
        $this->object->setDataValue('id', $identifer);
535
        $this->assertEquals($identifer, (string) $this->object);
536
537
        $code = 'test';
538
        $this->object->setDataValue('kod', $code);
539
        $this->assertEquals('code:'.$code, (string) $this->object);
540
541
        $this->object->dataReset();
542
        $this->assertNull($this->object->__toString());
543
    }
544
545
    /**
546
     * @covers FlexiPeeHP\FlexiBeeRO::draw
547
     */
548
    public function testDraw($whatWant = NULL)
549
    {
550
        $this->object->setDataValue('kod', 'test');
551
        $this->assertEquals('code:test', $this->object->draw());
552
    }
553
554
    /**
555
     * @covers FlexiPeeHP\FlexiBeeRO::getColumnsInfo
556
     */
557 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...
558
    {
559
        switch ($this->object->getEvidence()) {
560
            case '':
561
            case 'c':
562
            case 'hooks':
563
            case 'changes':
564
            case 'nastaveni':
565
                $this->assertNull($this->object->getColumnsInfo());
566
                $this->assertNotEmpty($this->object->getColumnsInfo('faktura-vydana'),
567
                    'Cannot obtain structure for na evidence');
568
                break;
569
            default:
570
                $this->assertNotEmpty($this->object->getColumnsInfo(),
571
                    'Cannot obtain structure for '.$this->object->getEvidence());
572
                break;
573
        }
574
    }
575
576
    /**
577
     * @covers FlexiPeeHP\FlexiBeeRO::getActionsInfo
578
     */
579 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...
580
    {
581
        switch ($this->object->getEvidence()) {
582
            case '':
583
            case 'c':
584
            case 'hooks':
585
            case 'changes':
586
            case 'nastaveni':
587
                $this->assertNull($this->object->getActionsInfo());
588
                $this->assertNotEmpty($this->object->getActionsInfo('faktura-vydana'),
589
                    'Cannot obtain actions for na evidence');
590
                break;
591
            default:
592
                $this->assertNotEmpty($this->object->getActionsInfo(),
593
                    'Cannot obtain actions for '.$this->object->getEvidence());
594
                break;
595
        }
596
    }
597
598
    /**
599
     * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceUrl
600
     */
601
    public function testgetEvidenceUrl()
602
    {
603
        $this->assertNotEmpty($this->object->getEvidenceUrl());
604
        $this->assertNotEmpty($this->object->getEvidenceUrl('/properties'));
605
    }
606
607
    /**
608
     * @covers FlexiPeeHP\FlexiBeeRO::evidenceToClassName
609
     */
610
    public function testevidenceToClassName()
611
    {
612
        $this->assertEquals('FakturaVydana',
613
            $this->object->evidenceToClassName('faktura-vydana'));
614
    }
615
616
}
617