Completed
Push — master ( 14dc45...6a7b8b )
by Vítězslav
08:50
created

FakturaVydanaTest::makeInvoice()   F

Complexity

Conditions 12
Paths 1536

Size

Total Lines 64
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 64
rs 2.7469
cc 12
eloc 40
nc 1536
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
     * Sets up the fixture, for example, opens a network connection.
19
     * This method is called before a test is executed.
20
     */
21
    protected function setUp()
22
    {
23
        $this->object = new FakturaVydana();
24
    }
25
26
    /**
27
     * Tears down the fixture, for example, closes a network connection.
28
     * This method is called after a test is executed.
29
     */
30
    protected function tearDown()
31
    {
32
33
    }
34
35
    /**
36
     * @covers FlexiPeeHP\FakturaVydana::hotovostniUhrada
37
     */
38
    public function testhotovostniUhrada()
39
    {
40
        $this->makeInvoice();
41
        $this->object->unsetDataValue('kod');
42
        $this->object->hotovostniUhrada($this->object->getDataValue('sumCelkZakl'));
43
        $this->assertEquals(201, $this->object->lastResponseCode,
44
            _('Invoice settle error'));
45
    }
46
47
    /**
48
     * @covers FlexiPeeHP\FakturaVydana::sparujPlatbu
49
     */
50
    public function testsparujPlatbu()
51
    {
52
        $this->makeInvoice();
53
        $doklad     = new \FlexiPeeHP\PokladniPohyb();
54
        $value      = $this->object->getDataValue('sumCelkZakl');
55
        $dataPohybu = [
56
            'kod' => 'FP'.time(),
57
            'typDokl' => 'code:STANDARD',
58
            'typPohybuK' => 'typPohybu.prijem',
59
            'datVyst' => date("Y-m-d", time() - 60 * 60 * 24),
60
            'jakUhrK' => 'jakUhrazeno.rucne1',
61
            'pokladna' => 'code:POKLADNA KČ',
62
            'generovatSkl' => false,
63
            'zdrojProSkl' => false,
64
            'firma' => $this->object->getDataValue('firma'),
65
            'bezPolozek' => true,
66
            'poznam' => $this->poznam,
67
            'primUcet' => 'code:013001',
68
            'sumZklCelkem' => $value
69
        ];
70
        $doklad->takeData($dataPohybu);
71
        $doklad->insertToFlexiBee();
72
        $doklad->unsetDataValue('kod');
73
        $this->object->sparujPlatbu($doklad);
74
        $this->assertEquals(201, $doklad->lastResponseCode,
75
            _('Invoice match error'));
76
    }
77
78
    /**
79
     * Crerate testing invoice
80
     * 
81
     * @param array $invoiceData
82
     */
83
    public function makeInvoice($invoiceData = [])
84
    {
85
        if (!isset($invoiceData['kod'])) {
86
            $invoiceData['kod'] = 'PeeHP'.time();
87
        }
88
        if (!isset($invoiceData['varSym'])) {
89
            $invoiceData['varSym'] = \Ease\Sand::randomNumber(1000, 99999);
90
        }
91
        if (!isset($invoiceData['datVyst'])) {
92
            $invoiceData['datVyst'] = date("Y-m-d", time() - 60 * 60 * 24);
93
        }
94
        if (!isset($invoiceData['typDokl'])) {
95
            $invoiceData['typDokl'] = 'code:FAKTURA';
96
        }
97
        if (!isset($invoiceData['zdrojProSkl'])) {
98
            $invoiceData['zdrojProSkl'] = false;
99
        }
100
        if (!isset($invoiceData['dobropisovano'])) {
101
            $invoiceData['dobropisovano'] = false;
102
        }
103
104
        if (!isset($invoiceData['polozky'])) {
105
            $invoiceData['bezPolozek'] = true;
106
        }
107
108
        if (!isset($invoiceData['sumCelkZakl'])) {
109
            $scale                      = pow(1000, 2);
110
            $invoiceData['sumCelkZakl'] = round(mt_rand(10 * $scale,
111
                    9000 * $scale) / $scale, 2);
112
        }
113
114
        if (!isset($invoiceData['firma'])) {
115
            $adresar = new \FlexiPeeHP\Adresar();
116
117
            $adresy = $adresar->getFlexiData(null,
118
                ['typVztahuK' => 'typVztahu.odberatel']);
119
            if (count($adresy)) {
120
                $dodavatel = $adresy[array_rand($adresy)];
121
122
                $invoiceData['firma'] = 'code:'.$dodavatel['kod'];
123
            } else {
124
                /**
125
                 * Make Some Address First ...
126
                 */
127
                $address = new \FlexiPeeHP\Adresar();
128
                $address->setDataValue('nazev', \Ease\Sand::randomString());
129
                $address->setDataValue('poznam', 'Generated Unit Test Customrt');
130
                $address->setDataValue('typVztahuK', 'typVztahu.odberatel');
131
                $address->insertToFlexiBee();
132
                $invoiceData['firma'] = $address;
133
            }
134
        }
135
136
        if (!isset($invoiceData['poznam'])) {
137
            $invoiceData['poznam'] = $this->poznam;
138
        }
139
140
        $this->object->takeData($invoiceData);
141
        $this->object->insertToFlexiBee();
142
143
        $id = $this->object->getLastInsertedId();
144
        $this->object->setDataValue('id', $id);
145
        return $id;
146
    }
147
148
}
149