Completed
Push — master ( 9f37b9...417a27 )
by Vítězslav
08:08
created

FlexiBeeROTest::testgetRelationsInfo()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 18
Code Lines 15

Duplication

Lines 18
Ratio 100 %

Importance

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