Passed
Pull Request — master (#14)
by Matthew
14:12
created

FoxyStripeOptionInventoryManagerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\FoxyStripe\Test;
4
5
use Dynamic\FoxyStripe\Model\OptionItem;
6
use Dynamic\FoxyStripe\Model\Order;
7
use Dynamic\FoxyStripe\Model\OrderDetail;
8
use Dynamic\FoxyStripe\ORM\FoxyStripeOptionInventoryManager;
9
use Dynamic\FoxyStripe\Test\TestOnly\TestOption;
10
use Dynamic\FoxyStripe\Test\TestOnly\TestProduct;
11
use SilverStripe\Dev\SapphireTest;
12
use SilverStripe\Forms\FieldList;
13
14
class FoxyStripeOptionInventoryManagerTest extends SapphireTest
15
{
16
    /**
17
     * @var array
18
     */
19
    protected static $fixture_file = array(
20
        '../fixtures.yml',
21
    );
22
23
    /**
24
     * @var array
25
     */
26
    protected static $extra_dataobjects = [
27
        TestProduct::class,
28
        TestOption::class,
29
    ];
30
31
    /**
32
     *
33
     */
34
    public function setUp()
35
    {
36
        OptionItem::add_extension(FoxyStripeOptionInventoryManager::class);
37
        return parent::setUp();
38
    }
39
40
    /**
41
     *
42
     */
43
    public function tearDown()
44
    {
45
        OptionItem::remove_extension(FoxyStripeOptionInventoryManager::class);
46
        parent::tearDown();
47
    }
48
49
    /**
50
     *
51
     */
52
    public function testUpdateCMSFields()
53
    {
54
        $object = $this->objFromFixture(TestOption::class, 'one');
55
        $fields = $object->getCMSFields();
56
        $this->assertInstanceOf(FieldList::class, $fields);
57
    }
58
59
    /**
60
     *
61
     */
62
    public function testGetHasInventory()
63
    {
64
        /** @var TestOption $option */
65
        $option = OptionItem::create();
66
        //$option = $this->objFromFixture(TestOption::class, 'one');
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
67
68
        $option->ControlInventory = false;
0 ignored issues
show
Bug Best Practice introduced by
The property ControlInventory does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __set, consider adding a @property annotation.
Loading history...
69
        $option->PurchaseLimit = 0;
0 ignored issues
show
Bug Best Practice introduced by
The property PurchaseLimit does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __set, consider adding a @property annotation.
Loading history...
70
        $this->assertFalse($option->getHasInventory());
0 ignored issues
show
Bug introduced by
The method getHasInventory() does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
        $this->assertFalse($option->/** @scrutinizer ignore-call */ getHasInventory());
Loading history...
71
72
        $option->ControlInventory = true;
73
        $option->PurchaseLimit = 0;
74
        $this->assertFalse($option->getHasInventory());
75
76
        $option->ControlInventory = false;
77
        $option->PurchaseLimit = 10;
78
        $this->assertFalse($option->getHasInventory());
79
80
        $option->ControlInventory = true;
81
        $option->PurchaseLimit = 10;
82
        $this->assertTrue($option->getHasInventory());
83
    }
84
85
    /**
86
     *
87
     */
88
    public function testGetIsOptionAvailable()
89
    {
90
        /** @var TestOption $option */
91
        $option = OptionItem::create();
92
        $option->write();
93
        //$option = $this->objFromFixture(TestOption::class, 'one');
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
94
95
        // no inventory control
96
        $option->ControlInventory = false;
0 ignored issues
show
Bug Best Practice introduced by
The property ControlInventory does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __set, consider adding a @property annotation.
Loading history...
97
        $option->PurchaseLimit = 0;
0 ignored issues
show
Bug Best Practice introduced by
The property PurchaseLimit does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __set, consider adding a @property annotation.
Loading history...
98
        $this->assertTrue($option->getIsOptionAvailable());
0 ignored issues
show
Bug introduced by
The method getIsOptionAvailable() does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

98
        $this->assertTrue($option->/** @scrutinizer ignore-call */ getIsOptionAvailable());
Loading history...
99
100
        // inventory control, no inventory
101
        $option->ControlInventory = true;
102
        $option->PurchaseLimit = 0;
103
        $this->assertFalse($option->getIsOptionAvailable());
104
105
        // inventory control, with inventory
106
        $option->ControlInventory = true;
107
        $option->PurchaseLimit = 10;
108
        $this->assertTrue($option->getIsOptionAvailable());
109
110
        $detail = OrderDetail::create();
111
        $detail->Quantity = 10;
112
        $detail->write();
113
        $detail->OrderOptions()->add($option);
114
115
        // inventory control, no inventory left
116
        $option->ControlInventory = true;
117
        $option->PurchaseLimit = 10;
118
        $this->assertFalse($option->getIsOptionAvailable());
119
    }
120
121
    /**
122
     *
123
     */
124
    public function testGetNumberPurchased()
125
    {
126
        /** @var TestOption $option */
127
        $option = OptionItem::create();
128
        $option->write();
129
        //$option = $this->objFromFixture(TestOption::class, 'one');
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
130
131
        $this->assertEquals(0, $option->getNumberPurchased());
0 ignored issues
show
Bug introduced by
The method getNumberPurchased() does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

131
        $this->assertEquals(0, $option->/** @scrutinizer ignore-call */ getNumberPurchased());
Loading history...
132
133
        $detail = OrderDetail::create();
134
        $detail->Quantity = 10;
135
        $detail->write();
136
        $detail->OrderOptions()->add($option);
137
138
        $this->assertEquals(10, $option->getNumberPurchased());
139
    }
140
141
    /**
142
     *
143
     */
144
    public function testGetOrders()
145
    {
146
        /** @var TestOption $option */
147
        $option = OptionItem::create();
148
        $option->write();
149
        //$option = $this->objFromFixture(TestOption::class, 'one');
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
150
151
        $this->assertEquals(0, $option->getOrders()->Count());
0 ignored issues
show
Bug introduced by
The method getOrders() does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

151
        $this->assertEquals(0, $option->/** @scrutinizer ignore-call */ getOrders()->Count());
Loading history...
152
153
        $detail = OrderDetail::create();
154
        $detail->Quantity = 10;
155
        $detail->write();
156
        $detail->OrderOptions()->add($option);
157
158
        $this->assertEquals(1, $option->getOrders()->Count());
159
    }
160
}
161