CartTest::testGetStorage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace yii2mod\cart\tests;
4
5
use Yii;
6
use yii2mod\cart\storage\StorageInterface;
7
use yii2mod\cart\tests\data\Product;
8
9
/**
10
 * Class CartTest
11
 *
12
 * @package yii2mod\cart\tests
13
 */
14
class CartTest extends TestCase
15
{
16
    public function testEmptyCart()
17
    {
18
        $this->assertEmpty(Yii::$app->cart->getItems());
19
    }
20
21
    public function testAddItem()
22
    {
23
        $cart = Yii::$app->cart;
24
        $product = Product::findOne(1);
25
        $cart->add($product);
26
27
        $this->assertContains($product, $cart->getItems());
28
    }
29
30 View Code Duplication
    public function testRemoveItem()
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...
31
    {
32
        $cart = Yii::$app->cart;
33
        $product = Product::findOne(1);
34
        $cart->add($product);
35
36
        $this->assertContains($product, $cart->getItems());
37
38
        $cart->remove($product->getUniqueId());
39
        $this->assertEmpty($cart->getItems());
40
    }
41
42 View Code Duplication
    public function testClearCart()
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...
43
    {
44
        $cart = Yii::$app->cart;
45
        $product = Product::findOne(1);
46
        $cart->add($product);
47
48
        $this->assertEquals(1, $cart->getCount());
49
50
        $cart->clear();
51
        $this->assertEmpty($cart->getItems());
52
    }
53
54
    public function testGetAttributeTotalValue()
55
    {
56
        $cart = Yii::$app->cart;
57
        $product = Product::findOne(1);
58
        $cart->add($product);
59
60
        $this->assertEquals(100, $cart->getAttributeTotal('price'));
61
    }
62
63
    public function testGetItems()
64
    {
65
        $cart = Yii::$app->cart;
66
        $product = Product::findOne(1);
67
        $cart->add($product);
68
69
        $items = $cart->getItems();
70
71
        $this->assertCount(1, $items);
72
        $this->assertEquals('Amazon Kindle', $items[1]['name']);
73
    }
74
75
    public function testGetStorage()
76
    {
77
        $this->assertInstanceOf(StorageInterface::class, Yii::$app->cart->getStorage());
78
    }
79
}
80