Test Failed
Push — master ( fa235b...71ab82 )
by Vítězslav
03:04
created

FakturaVydanaTest::getDataForInsert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 12
rs 9.4285
1
<?php
2
3
namespace Test\FlexiPeeHP;
4
5
use FlexiPeeHP\FakturaVydana;
6
7
/**
8
 * Generated by PHPUnit_SkeletonGenerator on 2016-04-27 at 17:32:11.
9
 */
10
class FakturaVydanaTest extends FlexiBeeRWTest
11
{
12
    /**
13
     * @var FakturaVydana
14
     */
15
    protected $object;
16
17
    /**
18
     * Gives You data able to insert into current evidence
19
     *
20
     * @param string $code custom record code
21
     *
22
     * @return array
23
     */
24
    public function getDataForInsert($code = 'UnitTest')
25
    {
26
        $dataForInsert               = parent::getDataForInsert($code);
27
        $dataForInsert['typDokl']    = 'code:FAKTURA';
28
        $adresar                     = new \FlexiPeeHP\Adresar();
29
        $candidates                  = $adresar->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...
30
        $candidat                    = array_rand($candidates);
31
        $dataForInsert['firma']      = $candidat['id'];
32
        $dataForInsert['sumZklZakl'] = \Ease\Sand::randomNumber(1000, 9999);
33
        $dataForInsert['bezPolozek'] = true;
34
        return $dataForInsert;
35
    }
36
37
    /**
38
     * Sets up the fixture, for example, opens a network connection.
39
     * This method is called before a test is executed.
40
     */
41
    protected function setUp()
42
    {
43
        $this->object = new FakturaVydana();
44
    }
45
46
    /**
47
     * Tears down the fixture, for example, closes a network connection.
48
     * This method is called after a test is executed.
49
     */
50
    protected function tearDown()
51
    {
52
        
53
    }
54
55
    /**
56
     * @covers FlexiPeeHP\FakturaVydana::hotovostniUhrada
57
     */
58
    public function testhotovostniUhrada()
59
    {
60
        $this->makeInvoice();
61
        $this->object->unsetDataValue('kod');
62
        $this->object->hotovostniUhrada($this->object->getDataValue('sumCelkZakl'));
63
        $this->assertEquals(201, $this->object->lastResponseCode,
64
            _('Invoice settle error'));
65
    }
66
67
    /**
68
     * @covers FlexiPeeHP\FakturaVydana::sparujPlatbu
69
     */
70
    public function testsparujPlatbu()
71
    {
72
        $this->makeInvoice();
73
        $doklad     = new \FlexiPeeHP\PokladniPohyb();
74
        $value      = $this->object->getDataValue('sumCelkZakl');
75
        $dataPohybu = [
76
            'kod' => 'FP'.time(),
77
            'typDokl' => 'code:STANDARD',
78
            'typPohybuK' => 'typPohybu.prijem',
79
            'datVyst' => date("Y-m-d", time() - 60 * 60 * 24),
80
            'jakUhrK' => 'jakUhrazeno.rucne1',
81
            'pokladna' => 'code:POKLADNA KČ',
82
            'generovatSkl' => false,
83
            'zdrojProSkl' => false,
84
            'firma' => $this->object->getDataValue('firma'),
85
            'bezPolozek' => true,
86
            'poznam' => $this->poznam,
87
            'primUcet' => 'code:013001',
88
            'sumZklCelkem' => $value
89
        ];
90
        $doklad->takeData($dataPohybu);
91
        $doklad->insertToFlexiBee();
92
        $doklad->unsetDataValue('kod');
93
        $this->object->sparujPlatbu($doklad);
94
        $this->assertEquals(201, $doklad->lastResponseCode,
95
            _('Invoice match error'));
96
    }
97
98
    /**
99
     * Crerate testing invoice
100
     * 
101
     * @param array $invoiceData
102
     */
103
    public function makeInvoice($invoiceData = [])
104
    {
105
        if (!isset($invoiceData['kod'])) {
106
            $invoiceData['kod'] = 'PeeHP'.time();
107
        }
108
        if (!isset($invoiceData['varSym'])) {
109
            $invoiceData['varSym'] = \Ease\Sand::randomNumber(1000, 99999);
110
        }
111
        if (!isset($invoiceData['datVyst'])) {
112
            $invoiceData['datVyst'] = date("Y-m-d", time() - 60 * 60 * 24);
113
        }
114
        if (!isset($invoiceData['typDokl'])) {
115
            $invoiceData['typDokl'] = 'code:FAKTURA';
116
        }
117
        if (!isset($invoiceData['zdrojProSkl'])) {
118
            $invoiceData['zdrojProSkl'] = false;
119
        }
120
        if (!isset($invoiceData['dobropisovano'])) {
121
            $invoiceData['dobropisovano'] = false;
122
        }
123
        if (!isset($invoiceData['bezPolozek'])) {
124
            $invoiceData['bezPolozek'] = false;
125
        }
126
127
        if (!isset($invoiceData['polozky']) && !$invoiceData['bezPolozek']) {
128
            $invoiceData['bezPolozek'] = true;
129
            if (!array_key_exists('sumCelkZakl', $invoiceData)) {
130
                $scale                       = pow(1000, 2);
131
                $price                       = round(mt_rand(10 * $scale,
132
                        9000 * $scale) / $scale, 2);
133
//                $invoiceData['sumCelkZakl']  = $invoiceData['castkaMen']    = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
134
                $invoiceData['sumZklCelkem'] = $price;
135
                $invoiceData['sumCelkem']    = $price;
136
                $invoiceData['sumOsv']       = $price;
137
            }
138
        } else {
139
            $invoiceData['bezPolozek'] = false;
140
        }
141
142
        if (!isset($invoiceData['firma'])) {
143
            $adresar = new \FlexiPeeHP\Adresar();
144
145
            $adresy = $adresar->getFlexiData(null,
146
                ['typVztahuK' => 'typVztahu.odberatel']);
147
            if (count($adresy)) {
148
                $dodavatel = $adresy[array_rand($adresy)];
149
150
                $invoiceData['firma'] = 'code:'.$dodavatel['kod'];
151
            } else {
152
                /**
153
                 * Make Some Address First ...
154
                 */
155
                $address              = new \FlexiPeeHP\Adresar();
156
                $address->setDataValue('nazev', \Ease\Sand::randomString());
157
                $address->setDataValue('poznam', 'Generated Unit Test Customer');
158
                $address->setDataValue('typVztahuK', 'typVztahu.odberatel');
159
                $address->insertToFlexiBee();
160
                $invoiceData['firma'] = $address;
161
            }
162
        }
163
164
        if (!isset($invoiceData['poznam'])) {
165
            $invoiceData['poznam'] = $this->poznam;
166
        }
167
168
        $this->object->takeData($invoiceData);
169
        $this->object->refresh();
170
        return $this->object;
171
    }
172
173
    /**
174
     * Provizorní zkopírování faktury
175
     *
176
     * @link https://www.flexibee.eu/podpora/Tickets/Ticket/View/28848 Chyba při Provádění akcí přes REST API JSON
177
     * @param \FlexiPeeHP\FakturaVydana $invoice
178
     * @param array $overide Hodnoty přepisující výchozí v kopii faktury
0 ignored issues
show
Documentation introduced by
There is no parameter named $overide. Did you maybe mean $override?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
179
     * @return \FlexiPeeHP\FakturaVydana
180
     */
181
    public function invoiceCopy($invoice, $override = [])
182
    {
183
        $invoice2        = new \FlexiPeeHP\FakturaVydana($invoice->getData());
184
        $invoice2->debug = true;
185
        $invoice2->unsetDataValue('id');
186
        $invoice2->unsetDataValue('kod');
187
        $polozky         = $invoice2->getDataValue('polozkyFaktury');
188
        if (is_array($polozky) && count($polozky)) {
189
            foreach ($polozky as $pid => $polozka) {
190
                unset($polozky[$pid]['id']);
191
                unset($polozky[$pid]['doklFak']);
192
                unset($polozky[$pid]['doklFak@showAs']);
193
                unset($polozky[$pid]['doklFak@ref']);
194
            }
195
            $invoice2->setDataValue('polozkyFaktury', $polozky);
196
        }
197
        if (is_null($invoice2->getDataValue('typDokl'))) {
198
            $invoice2->setDataValue('typDokl', 'code:FAKTURA');
199
        }
200
        $invoice2->unsetDataValue('external-ids');
201
202
        $today = date('Y-m-d');
203
204
        $invoice2->setDataValue('duzpPuv', $today);
205
        $invoice2->setDataValue('duzpUcto', $today);
206
        $invoice2->setDataValue('datUcto', $today);
207
        $invoice2->takeData($override);
208
        $invoice2->insertToFlexiBee();
209
210
        return $invoice2;
211
    }
212
213
    /**
214
     * @covers FlexiPeeHP\FakturaVydana::odpocetZDD
215
     */
216
    public function testodpocetZDD()
217
    {
218
        $this->markTestIncomplete('TODO: Write Test');
219
    }
220
221
    /**
222
     * @covers FlexiPeeHP\FakturaVydana::odpocetZalohy
223
     */
224
    public function testodpocetZalohy()
225
    {
226
        $itemName = \Ease\Sand::randomString();
227
228
        $polozka = [
229
            "typCenyDphK" => "typCeny.bezDph",
230
            "typSzbDphK" => "typSzbDph.dphZakl",
231
            "kopClenKonVykDph" => "true",
232
            "typPolozkyK" => "typPolozky.obecny",
233
            'zdrojProSkl' => false,
234
            'zaloha' => true,
235
            'nazev' => $itemName,
236
            'szbDph' => 19.0,
237
            'cenaMj' => 123,
238
            "mnozMj" => "1.0",
239
            'poznam' => $this->poznam,
240
        ];
241
242
        $this->makeInvoice(
243
            [
244
                'typDokl' => 'code:ZÁLOHA',
245
                'polozky' => $polozka,
246
                'bezPolozek' => false
247
            ]
248
        );
249
250
251
        $this->object->hotovostniUhrada($this->object->getDataValue('sumCelkem'));
252
253
        $invoice2 = $this->invoiceCopy($this->object,
254
            ['typDokl' => 'code:FAKTURA']);
255
        $id       = (int) $invoice2->getLastInsertedId();
256
        $invoice2->loadFromFlexiBee($id);
257
        $kod      = $invoice2->getDataValue('kod');
258
        $invoice2->dataReset();
259
        $invoice2->setDataValue('id', 'code:'.$kod);
260
261
        $invdata = $this->object->getData();
0 ignored issues
show
Unused Code introduced by
$invdata is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
262
263
//        $this->object->getDataValue('sumCelkem'); ????
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
264
//        $result = $invoice2->odpocetZalohy($this->object);
265
//        $this->assertArrayHasKey('success', $result);
266
//        $this->assertEquals('true', $result['success'], 'Matching Error');
267
    }
268
}
269