Test Failed
Push — master ( 99a915...bca16c )
by Vítězslav
07:03
created

FlexiBeeRWTest::testInsertToFlexiBee()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
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\FlexiBeeRW;
6
7
/**
8
 * Generated by PHPUnit_SkeletonGenerator on 2016-05-04 at 10:08:36.
9
 */
10
class FlexiBeeRWTest extends FlexiBeeROTest
11
{
12
    /**
13
     * Poznámka vkládaná do záznamů vytvářených během testů
14
     * @var strig 
15
     */
16
    public $poznam = 'Generováno UnitTestem PHP Knihovny https://github.com/Spoje-NET/FlexiPeeHP';
17
18
    /**
19
     *
20
     * @var array
21
     */
22
    public $insertableData = [];
23
24
    /**
25
     * @var FlexiBeeRW
26
     */
27
    protected $object;
28
29
    /**
30
     * Gives You data able to insert into current evidence
31
     *
32
     * @param string $code custom record code
33
     *
34
     * @return array
35
     */
36
    public function getDataForInsert($code = 'UnitTest')
37
    {
38
        $dataForInsert = [];
39
        $structure     = $this->object->getColumnsInfo();
40
        if (count($structure) && array_key_exists('typDokl', $structure)) {
41
            if ($structure['typDokl']['type'] == 'relation') {
42
                $relatedEvidence          = basename($structure['typDokl']['url']);
43
                $loader                   = new \FlexiPeeHP\FlexiBeeRO(null,
44
                    ['evidence' => $relatedEvidence]);
45
                $typDoklRaw               = $loader->getColumnsFromFlexibee([
46
                    'kod'], ['limit' => 1]);
47
                $dataForInsert['typDokl'] = \FlexiPeeHP\FlexiBeeRO::code($typDoklRaw[0]['kod']);
48
            }
49
50
            if (array_key_exists('poznam', $structure)) {
51
                $dataForInsert['poznam'] = $this->poznam;
52
            }
53
54
            if (array_key_exists('kod', $structure)) {
55
                $dataForInsert['kod'] = \FlexiPeeHP\FlexiBeeRO::uncode($this->object->getKod($code));
56
            }
57
        }
58
        return $dataForInsert;
59
    }
60
61
    /**
62
     * Sets up the fixture, for example, opens a network connection.
63
     * This method is called before a test is executed.
64
     * @covers FlexiPeeHP\FlexiBeeRW::__construct
65
     */
66
    protected function setUp()
67
    {
68
        $this->object = new FlexiBeeRW();
69
    }
70
71
    /**
72
     * Tears down the fixture, for example, closes a network connection.
73
     * This method is called after a test is executed.
74
     */
75
    protected function tearDown()
76
    {
77
        
78
    }
79
80
    /**
81
     * @covers FlexiPeeHP\FlexiBeeRW::getLastInsertedId
82
     * @depends testInsertToFlexiBee
83
     */
84
    public function testGetLastInsertedId()
85
    {
86
        $this->assertNotEmpty($this->object->getLastInsertedId());
87
    }
88
89
    /**
90
     * @covers FlexiPeeHP\FlexiBeeRW::insertToFlexiBee
91
     */
92
    public function testInsertToFlexiBee()
93
    {
94
        if (empty($this->insertableData)) {
95
            $this->insertableData = $this->getDataForInsert('INSERTTEST'.time());
96
        }
97
98
        $this->object->insertToFlexiBee($this->insertableData);
99
    }
100
101
    /**
102
     * @covers FlexiPeeHP\FlexiBeeRW::performAction
103
     * @expectedException \Exception
104
     */
105
    public function testPerformAction()
106
    {
107
        $actions = $this->object->getActionsInfo();
108
109
        if (count($actions)) {
110
            if (array_key_exists('new', $actions)) {
111
                $this->object->performAction('new', 'ext');
112
            }
113
114
            if (array_key_exists('storno', $actions)) {
115
                $this->object->insertToFlexiBee($this->getDataForInsert('StornoTest_'.time()));
116
                $this->object->performAction('storno', 'int');
117
            }
118
        }
119
        $this->object->performAction('nonexitst');
120
    }
121
122
    /**
123
     * @covers FlexiPeeHP\FlexiBeeRWRW::deleteFromFlexiBee
124
     */
125
    public function testDeleteFromFlexiBee()
126
    {
127
        // Remove the following lines when you implement this test.
128
        $this->markTestIncomplete(
129
            'This test has not been implemented yet.'
130
        );
131
    }
132
133
    /**
134
     * @covers FlexiPeeHP\FlexiBeeRW::timestampToFlexiDate
135
     */
136
    public function testTimestampToFlexiDate()
137
    {
138
        $this->assertNull($this->object->timestampToFlexiDate());
139
        $this->assertEquals('2016-09-16',
140
            $this->object->timestampToFlexiDate('1474040506'));
141
    }
142
143
    /**
144
     * @covers FlexiPeeHP\FlexiBeeRW::timestampToFlexiDateTime
145
     */
146
    public function testTimestampToFlexiDateTime()
147
    {
148
        $this->assertNull($this->object->timestampToFlexiDateTime());
149
        $this->assertEquals('2016-09-16UTC15:41:46',
150
            $this->object->timestampToFlexiDateTime('1474040506'));
151
    }
152
153
    /**
154
     * @covers FlexiPeeHP\FlexiBeeRW::objectToID
155
     */
156
    public function testObjectToID()
157
    {
158
        $id = \Ease\Sand::randomNumber(1, 9999);
159
        $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 158 can also be of type false; however, FlexiPeeHP\FlexiBeeRO::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...
160
        $this->assertEquals([$id], $this->object->objectToID([$this->object]));
161
        parent::testObjectToID();
162
    }
163
164
    /**
165
     * @covers FlexiPeeHP\FlexiBeeRW::getRecordID
166
     */
167
    public function testGetRecordID()
168
    {
169
        parent::testGetRecordID();
170
        $structure = $this->object->getEvidenceInfo();
171
        if (count($structure) && array_key_exists('kod', $structure)) {
172
            $this->object->setData(['kod' => 'KOD']);
173
            $this->assertEquals('code:KOD', $this->object->getRecordID());
174
        }
175
    }
176
}
177