Passed
Push — master ( 9ff5a0...cb011f )
by Carsten
02:00
created

ItemTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Tests;
4
5
/*
6
 * This file is part of Lenius Basket, a PHP package to handle
7
 * your shopping basket.
8
 *
9
 * Copyright (c) 2017 Lenius.
10
 * http://github.com/lenius/basket
11
 *
12
 * For the full copyright and license information, please view the LICENSE
13
 * file that was distributed with this source code.
14
 *
15
 * @author Carsten Jonstrup<[email protected]>
16
 * @copyright 2017 Lenius.
17
 *
18
 * @version production
19
 *
20
 * @link http://github.com/lenius/basket
21
 */
22
use Lenius\Basket\Basket;
23
use Lenius\Basket\Identifier\Runtime as RuntimeIdentifier;
24
use Lenius\Basket\Item;
25
use Lenius\Basket\Storage\Runtime as RuntimeStore;
26
use PHPUnit\Framework\TestCase;
27
28
class ItemTest extends TestCase
29
{
30
    private $item;
31
32
    public function setUp()
33
    {
34
35
    }
36
37
    public function tearDown()
38
    {
39
        $this->item = null;
40
    }
41
42
    public function testTaxUpdate()
43
    {
44
        $identifier = 1;
45
46
        $item = [
47
            'id'       => 'foo',
48
            'name'     => 'bar',
49
            'price'    => 100,
50
            'quantity' => 1,
51
            'weight'   => 200,
52
        ];
53
54
55
        $this->item = new Item($identifier, $item, new RuntimeStore());
56
57
        $this->item->update('tax', 0);
58
        $this->assertEquals(100, $this->item->total());
59
        $this->assertEquals(100, $this->item->total(false));
60
61
        $this->item->update('tax', 20);
62
        $this->assertEquals(120, $this->item->total());
63
        $this->assertEquals(100, $this->item->total(false));
64
    }
65
66
    public function testWeight()
67
    {
68
        $identifier = 1;
69
70
        $weight = rand(200, 300);
71
        $quantity = rand(1, 10);
72
73
        $item = [
74
            'id'       => 'foo',
75
            'name'     => 'bar',
76
            'price'    => 100,
77
            'quantity' => $quantity,
78
            'weight'   => $weight,
79
        ];
80
81
        $this->item = new Item($identifier, $item, new RuntimeStore());
82
        $this->assertEquals(($weight * $quantity), $this->item->weight());
83
    }
84
85
    public function testWeightWithOption()
86
    {
87
        $identifier = 1;
88
89
        $weight = rand(200, 300);
90
        $weight_option = rand(50, 800);
91
        $quantity = rand(1, 10);
92
93
        $item = [
94
            'id'       => 'foo',
95
            'name'     => 'bar',
96
            'price'    => 100,
97
            'quantity' => $quantity,
98
            'weight'   => $weight,
99
            'options'  => [
100
                [
101
                    'name'   => 'Size',
102
                    'value'  => 'L',
103
                    'weight' => $weight_option,
104
                    'price'  => 100,
105
                ],
106
            ],
107
        ];
108
109
        $this->item = new Item($identifier, $item, new RuntimeStore());
110
        $this->assertEquals(($weight + $weight_option) * $quantity, $this->item->weight());
111
    }
112
113 View Code Duplication
    public function testHasOption()
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...
114
    {
115
        $identifier = 1;
116
117
        $item = [
118
            'id'       => 'foo',
119
            'name'     => 'bar',
120
            'price'    => 100,
121
            'quantity' => 1,
122
            'weight'   => 200,
123
            'options'  => [
124
                [
125
                    'name'   => 'Size',
126
                    'value'  => 'L',
127
                    'weight' => 50,
128
                    'price'  => 100,
129
                ],
130
            ],
131
        ];
132
133
        $this->item = new Item($identifier, $item, new RuntimeStore());
134
        $this->assertTrue($this->item->hasOptions());
135
136
    }
137
138 View Code Duplication
    public function testHasNotOption()
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...
139
    {
140
        $identifier = 1;
141
142
        $item = [
143
            'id'       => 'foo',
144
            'name'     => 'bar',
145
            'price'    => 100,
146
            'quantity' => 1,
147
            'weight'   => 200,
148
            'options'  => [
149
                [
150
                    'name'   => 'Size',
151
                    'value'  => 'L',
152
                    'weight' => 50,
153
                    'price'  => 100,
154
                ],
155
            ],
156
        ];
157
158
        $this->item = new Item($identifier, $item, new RuntimeStore());
159
        $this->assertEquals(250, $this->item->weight());
160
    }
161
162
}
163