Test Failed
Push — master ( b5725b...c73c28 )
by Vítězslav
02:40
created

FakturaVydanaTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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 new testng invoice
19
     */
20
    static public function getNew($code = 'UnitTest')
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
21
    {
22
        $helper = new FakturaVydanaTest();
23
        $helper->setUp();
24
        $helper->object->sync( $helper->getDataForInsert($code) );
25
        return $helper->object;
26
    }
27
    
28
    /**
29
     * Gives You data able to insert into current evidence
30
     *
31
     * @param string $code custom record code
32
     *
33
     * @return array
34
     */
35
    public function getDataForInsert($code = 'UnitTest')
36
    {
37
        $dataForInsert               = parent::getDataForInsert($code);
38
        $dataForInsert['typDokl']    = 'code:FAKTURA';
39
        $adresar                     = new \FlexiPeeHP\Adresar();
40
        $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...
41
        $dataForInsert['firma']      = $candidates[array_rand($candidates)]['id'];
42
        $dataForInsert['sumZklZakl'] = \Ease\Sand::randomNumber(1000, 9999);
43
        $dataForInsert['varSym']     = $dataForInsert['kod']        = time();
44
        $dataForInsert['bezPolozek'] = true;
45
        return $dataForInsert;
46
    }
47
48
    /**
49
     * Sets up the fixture, for example, opens a network connection.
50
     * This method is called before a test is executed.
51
     */
52
    protected function setUp()
53
    {
54
        $this->object = new FakturaVydana();
55
    }
56
57
    /**
58
     * Tears down the fixture, for example, closes a network connection.
59
     * This method is called after a test is executed.
60
     */
61
    protected function tearDown()
62
    {
63
        
64
    }
65
66
    /**
67
     * @covers FlexiPeeHP\FakturaVydana::hotovostniUhrada
68
     */
69
    public function testhotovostniUhrada()
70
    {
71
        $this->makeInvoice();
72
        $this->object->unsetDataValue('kod');
73
        $this->object->hotovostniUhrada($this->object->getDataValue('sumCelkZakl'));
74
        $this->assertEquals(201, $this->object->lastResponseCode,
75
            _('Invoice settle error'));
76
    }
77
78
    /**
79
     * @covers FlexiPeeHP\FakturaVydana::sparujPlatbu
80
     */
81
    public function testsparujPlatbu()
82
    {
83
        $this->makeInvoice();
84
        $doklad     = new \FlexiPeeHP\PokladniPohyb();
85
        $value      = $this->object->getDataValue('sumCelkZakl');
86
        $dataPohybu = [
87
            'kod' => 'FP'.time(),
88
            'typDokl' => 'code:STANDARD',
89
            'typPohybuK' => 'typPohybu.prijem',
90
            'datVyst' => date("Y-m-d", time() - 60 * 60 * 24),
91
            'jakUhrK' => 'jakUhrazeno.rucne1',
92
            'pokladna' => 'code:POKLADNA KČ',
93
            'generovatSkl' => false,
94
            'zdrojProSkl' => false,
95
            'firma' => $this->object->getDataValue('firma'),
96
            'bezPolozek' => true,
97
            'poznam' => $this->poznam,
98
            'primUcet' => 'code:013001',
99
            'sumZklCelkem' => $value
100
        ];
101
        $doklad->takeData($dataPohybu);
102
        $doklad->insertToFlexiBee();
103
        $doklad->unsetDataValue('kod');
104
        $this->object->sparujPlatbu($doklad);
105
        $this->assertEquals(201, $doklad->lastResponseCode,
106
            _('Invoice match error'));
107
    }
108
109
    /**
110
     * Crerate testing invoice
111
     * 
112
     * @param array $invoiceData
113
     */
114
    public function makeInvoice($invoiceData = [])
115
    {
116
        if (!isset($invoiceData['kod'])) {
117
            $invoiceData['kod'] = 'PeeHP'.time();
118
        }
119
        if (!isset($invoiceData['varSym'])) {
120
            $invoiceData['varSym'] = \Ease\Sand::randomNumber(1000, 99999);
121
        }
122
        if (!isset($invoiceData['datVyst'])) {
123
            $invoiceData['datVyst'] = date("Y-m-d", time() - 60 * 60 * 24);
124
        }
125
        if (!isset($invoiceData['typDokl'])) {
126
            $invoiceData['typDokl'] = 'code:FAKTURA';
127
        }
128
        if (!isset($invoiceData['zdrojProSkl'])) {
129
            $invoiceData['zdrojProSkl'] = false;
130
        }
131
        if (!isset($invoiceData['dobropisovano'])) {
132
            $invoiceData['dobropisovano'] = false;
133
        }
134
        if (!isset($invoiceData['bezPolozek'])) {
135
            $invoiceData['bezPolozek'] = false;
136
        }
137
138
        if (!isset($invoiceData['polozky']) && !$invoiceData['bezPolozek']) {
139
            $invoiceData['bezPolozek'] = true;
140
            if (!array_key_exists('sumCelkZakl', $invoiceData)) {
141
                $scale                       = pow(1000, 2);
142
                $price                       = round(mt_rand(10 * $scale,
143
                        9000 * $scale) / $scale, 2);
144
//                $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...
145
                $invoiceData['sumZklCelkem'] = $price;
146
                $invoiceData['sumCelkem']    = $price;
147
                $invoiceData['sumOsv']       = $price;
148
            }
149
        } else {
150
            $invoiceData['bezPolozek'] = false;
151
        }
152
153
        if (!isset($invoiceData['firma'])) {
154
            $adresar = new \FlexiPeeHP\Adresar();
155
156
            $adresy = $adresar->getFlexiData(null,
157
                ['typVztahuK' => 'typVztahu.odberatel']);
158
            if (count($adresy)) {
159
                $dodavatel = $adresy[array_rand($adresy)];
160
161
                $invoiceData['firma'] = 'code:'.$dodavatel['kod'];
162
            } else {
163
                /**
164
                 * Make Some Address First ...
165
                 */
166
                $address              = new \FlexiPeeHP\Adresar();
167
                $address->setDataValue('nazev', \Ease\Sand::randomString());
168
                $address->setDataValue('poznam', 'Generated Unit Test Customer');
169
                $address->setDataValue('typVztahuK', 'typVztahu.odberatel');
170
                $address->insertToFlexiBee();
171
                $invoiceData['firma'] = $address;
172
            }
173
        }
174
175
        if (!isset($invoiceData['poznam'])) {
176
            $invoiceData['poznam'] = $this->poznam;
177
        }
178
179
        $this->object->takeData($invoiceData);
180
        $this->object->refresh();
0 ignored issues
show
Deprecated Code introduced by
The method FlexiPeeHP\FlexiBeeRW::refresh() has been deprecated with message: since version 1.8.9

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
181
        return $this->object;
182
    }
183
184
    /**
185
     * Provizorní zkopírování faktury
186
     *
187
     * @link https://www.flexibee.eu/podpora/Tickets/Ticket/View/28848 Chyba při Provádění akcí přes REST API JSON
188
     * @param \FlexiPeeHP\FakturaVydana $invoice
189
     * @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...
190
     * @return \FlexiPeeHP\FakturaVydana
191
     */
192
    public function invoiceCopy($invoice, $override = [])
193
    {
194
        $invoice2        = new \FlexiPeeHP\FakturaVydana($invoice->getData());
195
        $invoice2->debug = true;
196
        $invoice2->unsetDataValue('id');
197
        $invoice2->unsetDataValue('kod');
198
        $polozky         = $invoice2->getDataValue('polozkyFaktury');
199
        if (is_array($polozky) && count($polozky)) {
200
            foreach ($polozky as $pid => $polozka) {
201
                unset($polozky[$pid]['id']);
202
                unset($polozky[$pid]['doklFak']);
203
                unset($polozky[$pid]['doklFak@showAs']);
204
                unset($polozky[$pid]['doklFak@ref']);
205
            }
206
            $invoice2->setDataValue('polozkyFaktury', $polozky);
207
        }
208
        if (is_null($invoice2->getDataValue('typDokl'))) {
209
            $invoice2->setDataValue('typDokl', 'code:FAKTURA');
210
        }
211
        $invoice2->unsetDataValue('external-ids');
212
213
        $today = date('Y-m-d');
214
215
        $invoice2->setDataValue('duzpPuv', $today);
216
        $invoice2->setDataValue('duzpUcto', $today);
217
        $invoice2->setDataValue('datUcto', $today);
218
        $invoice2->takeData($override);
219
        $invoice2->insertToFlexiBee();
220
221
        return $invoice2;
222
    }
223
224
    /**
225
     * @covers FlexiPeeHP\FakturaVydana::odpocetZDD
226
     */
227
    public function testodpocetZDD()
228
    {
229
        $this->markTestIncomplete('TODO: Write Test');
230
    }
231
232
    /**
233
     * @covers FlexiPeeHP\FakturaVydana::odpocetZalohy
234
     */
235
    public function testodpocetZalohy()
236
    {
237
        $itemName = \Ease\Sand::randomString();
238
239
        $polozka = [
240
            "typCenyDphK" => "typCeny.bezDph",
241
            "typSzbDphK" => "typSzbDph.dphZakl",
242
            "kopClenKonVykDph" => "true",
243
            "typPolozkyK" => "typPolozky.obecny",
244
            'zdrojProSkl' => false,
245
            'zaloha' => true,
246
            'nazev' => $itemName,
247
            'szbDph' => 19.0,
248
            'cenaMj' => 123,
249
            "mnozMj" => "1.0",
250
            'poznam' => $this->poznam,
251
        ];
252
253
        $this->makeInvoice(
254
            [
255
                'typDokl' => 'code:ZÁLOHA',
256
                'polozky' => $polozka,
257
                'bezPolozek' => false
258
            ]
259
        );
260
261
262
        $this->object->hotovostniUhrada($this->object->getDataValue('sumCelkem'));
263
264
        $invoice2 = $this->invoiceCopy($this->object,
265
            ['typDokl' => 'code:FAKTURA']);
266
        $id       = (int) $invoice2->getLastInsertedId();
267
        $invoice2->loadFromFlexiBee($id);
268
        $kod      = $invoice2->getDataValue('kod');
269
        $invoice2->dataReset();
270
        $invoice2->setDataValue('id', 'code:'.$kod);
271
272
        $invdata = $this->object->getData();
273
274
        $this->assertArrayHasKey('id', $invdata);
275
276
//        $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...
277
//        $result = $invoice2->odpocetZalohy($this->object);
278
//        $this->assertArrayHasKey('success', $result);
279
//        $this->assertEquals('true', $result['success'], 'Matching Error');
280
    }
281
282
    /**
283
     * @covers FlexiPeeHP\FakturaVydana::addArrayToBranch
284
     */
285
    public function testAddArrayToBranch()
286
    {
287
        $this->object->setDataValue('typDokl', 'FAKTURA');
288
        $this->object->addArrayToBranch(['nazev' => 'faktura'], 'polozkyDokladu');
289
        $this->object->setDataValue('typDokl', 'ZALOHA');
290
        $this->object->addArrayToBranch(['nazev' => 'zaloha'], 'polozkyDokladu');
291
    }
292
293
    /**
294
     * @covers FlexiPeeHP\FakturaVydana::vytvorVazbuZDD
295
     */
296
    public function testVytvorVazbuZDD()
297
    {
298
        $vs     = \Ease\Sand::randomNumber();
299
        $this->object->setDataValue('typDokl', 'code:ZÁLOHA');
300
        $this->object->setDataValue('varSym', $vs);
301
        $this->object->setDataValue('duzpPuv', '2018-02-10T23:47:10.510+01:00');
302
        $this->object->refresh();
0 ignored issues
show
Deprecated Code introduced by
The method FlexiPeeHP\FlexiBeeRW::refresh() has been deprecated with message: since version 1.8.9

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
303
        $this->object->setDataValue('typDokl', 'code:ZDD');
304
        $this->object->refresh();
0 ignored issues
show
Deprecated Code introduced by
The method FlexiPeeHP\FlexiBeeRW::refresh() has been deprecated with message: since version 1.8.9

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
305
        $income = new \FlexiPeeHP\Banka();
306
        $income->setDataValue('typDokl', 'code:STANDARD');
307
        $income->setDataValue('kod', $vs);
308
        $income->setDataValue('banka', 'code:BANKOVNÍ ÚČET');
309
        $income->setDataValue('varSym', $vs);
310
        $income->refresh();
0 ignored issues
show
Deprecated Code introduced by
The method FlexiPeeHP\FlexiBeeRW::refresh() has been deprecated with message: since version 1.8.9

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
311
        $this->object->vytvorVazbuZDD($income);
312
    }
313
}
314