Completed
Push — master ( 1ef83c...516478 )
by Vítězslav
13:51
created

FlexiBeeROTest::testSetPrefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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