Completed
Push — master ( 61756c...9c4d64 )
by Antony
02:56
created

SilvershopJsonResponseTest::testRemoveFromCart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 67
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 67
rs 9.2815
cc 1
eloc 47
nc 1
nop 0

How to fix   Long Method   

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
 * Functional tests of json responses for shopping cart of Silverstripe Shop
4
 *
5
 * @package shop
6
 * @subpackage tests
7
 */
8
class SilvershopJsonResponseTest extends FunctionalTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    protected static $fixture_file = 'silvershop/tests/fixtures/shop.yml';
11
12
    public function setUpOnce()
13
    {
14
        if (!ShoppingCart_Controller::has_extension('SilvershopJsonResponse')) {
15
            ShoppingCart_Controller::add_extension('SilvershopJsonResponse');
16
        }
17
        if (!VariationForm::has_extension('SilvershopJsonResponse')) {
18
            VariationForm::add_extension('SilvershopJsonResponse');
19
        }
20
        parent::setUpOnce();
21
    }
22
23
    public function setUp()
24
    {
25
        parent::setUp();
26
        ShopTest::setConfiguration(); //reset config
27
        Order::config()->modifiers = array(
28
            "FlatTaxModifier"
29
        );
30
31
        $this->mp3player = $this->objFromFixture('Product', 'mp3player');
0 ignored issues
show
Bug introduced by
The property mp3player does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
        $this->socks = $this->objFromFixture('Product', 'socks');
0 ignored issues
show
Bug introduced by
The property socks does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
34
        //publish some product categories and products
35
        $this->objFromFixture('ProductCategory', 'products')->publish('Stage', 'Live');
36
        $this->objFromFixture('ProductCategory', 'clothing')->publish('Stage', 'Live');
37
        $this->objFromFixture('ProductCategory', 'clearance')->publish('Stage', 'Live');
38
39
        $this->mp3player->publish('Stage', 'Live');
40
        $this->socks->publish('Stage', 'Live');
41
42
        $this->cart = ShoppingCart::singleton();
0 ignored issues
show
Bug introduced by
The property cart does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
        $this->cart->clear();
44
    }
45
46
    public function testAddToCart()
47
    {
48
        // test ajax request (Product Category page)
49
        $response = $this->get(ShoppingCart_Controller::add_item_link($this->mp3player) . "?ajax=1");
50
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
            200,
52
            $response->getStatusCode(),
53
            "Response status code is 200"
54
        );
55
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
            "application/json; charset=utf-8",
57
            $response->getHeader("Content-Type"),
58
            "Json response header"
59
        );
60
        $this->assertJson(
0 ignored issues
show
Bug introduced by
The method assertJson() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
            $response->getBody(),
62
            "Contains json in the body of the response"
63
        );
64
65
        $this->assertContains(
66
            "addLink",
67
            $response->getBody(),
68
            "response contains a link to add additional quantities of an item in the cart"
69
        );
70
        $this->assertContains(
71
            "removeLink",
72
            $response->getBody(),
73
            "response contains a link to reduce the quantity of an item in a cart"
74
        );
75
        $this->assertContains(
76
            "removeallLink",
77
            $response->getBody(),
78
            "response contains a link to remove all of an item from a cart"
79
        );
80
        $this->assertContains(
81
            "setquantityLink",
82
            $response->getBody(),
83
            "response contains a link to set the quantity of an item in a cart"
84
        );
85
        $this->assertContains(
86
            "unitPrice",
87
            $response->getBody(),
88
            "response contains the unit price of items in a cart"
89
        );
90
        $this->assertContains(
91
            "subTotal",
92
            $response->getBody(),
93
            "response contains a subTotal when include_totals is set to true"
94
        );
95
96
        // See what's in the cart
97
        $items = ShoppingCart::curr()->Items();
98
        $this->assertNotNull($items);
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
99
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
            $items->Count(),
101
            1,
102
            'There is 1 item in the cart'
103
        );
104
    }
105
106
    public function testRemoveFromCart()
107
    {
108
109
        // add items via url to setup
110
        $this->get(ShoppingCart_Controller::set_quantity_item_link($this->mp3player, array('quantity' => 5)));
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...array('quantity' => 5)) targeting ShoppingCart_Controller::set_quantity_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
111
        $this->get(ShoppingCart_Controller::add_item_link($this->socks));
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...item_link($this->socks) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
112
        ShoppingCart::curr()->calculate();  // recalculate the shopping cart
113
114
        $cart = $this->get("shoppingcart/get" . "?ajax=1");
115
        $this->assertContains(
116
            '"id":"10"',
117
            $cart->getBody(),
118
            "Contains the mp3 player"
119
        );
120
        $this->assertContains(
121
            '"id":"6"',
122
            $cart->getBody(),
123
            "Contains the socks"
124
        );
125
126
        // remove the one of the mp3 players via url making the total 4
127
        $response = $this->get(ShoppingCart_Controller::remove_item_link($this->mp3player) . "?ajax=1");
128
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
129
            200,
130
            $response->getStatusCode(),
131
            "Response status code is 200"
132
        );
133
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
134
            "application/json; charset=utf-8",
135
            $response->getHeader("Content-Type"),
136
            "Json response header"
137
        );
138
        $this->assertJson(
0 ignored issues
show
Bug introduced by
The method assertJson() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
139
            $response->getBody(),
140
            "Contains json in the body of the response"
141
        );
142
        $this->assertContains(
143
            '{"id":"10"', $response->getBody(),
144
            "Contains json in the body of the response and id of the mp3 player"
145
        );
146
147
        // remove the one of the socks via url making the total NIL so it is fully removed
148
        $response = $this->get(ShoppingCart_Controller::remove_item_link($this->socks) . "?ajax=1");
149
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
150
            200,
151
            $response->getStatusCode(),
152
            "Response status code is 200"
153
        );
154
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
155
            "application/json; charset=utf-8",
156
            $response->getHeader("Content-Type"),
157
            "Json response header"
158
        );
159
        $this->assertJson(
0 ignored issues
show
Bug introduced by
The method assertJson() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
160
            $response->getBody(),
161
            "Contains json in the body of the response"
162
        );
163
        $this->assertFalse(
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
164
            $this->cart->get($this->socks),
165
            "socks completely removed"
166
        );
167
        $this->assertContains(
168
            '{"id":"6"',
169
            $response->getBody(),
170
            "id of Socks returned"
171
        );
172
    }
173
174
    public function testRemoveAllFromCart()
175
    {
176
        // add items via url to setup
177
        $this->get(ShoppingCart_Controller::set_quantity_item_link($this->mp3player, array('quantity' => 5)));
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...array('quantity' => 5)) targeting ShoppingCart_Controller::set_quantity_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
178
        $this->get(ShoppingCart_Controller::add_item_link($this->socks));
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...item_link($this->socks) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
179
180
        // remove items from cart via url
181
        $response = $this->get(ShoppingCart_Controller::remove_all_item_link($this->mp3player) . "?ajax=1");
182
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
183
            200,
184
            $response->getStatusCode(),
185
            "Response status code is 200"
186
        );
187
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
188
            "application/json; charset=utf-8",
189
            $response->getHeader("Content-Type"),
190
            "Json response header"
191
        );
192
        $this->assertJson(
0 ignored issues
show
Bug introduced by
The method assertJson() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
193
            $response->getBody(),
194
            "Contains json in the body of the response"
195
        );
196
        $this->assertContains(
197
            '{"id":"10"',
198
            $response->getBody(),
199
            "Contains json in the body of the response and id of item removed"
200
        );
201
        $this->assertFalse(
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
202
            $this->cart->get($this->mp3player),
203
            "Mp3 Players are not in the cart"
204
        );
205
    }
206
207
    public function testSetQuantityInCart()
208
    {
209
        // add items via url to setup
210
        $this->get(ShoppingCart_Controller::set_quantity_item_link($this->mp3player, array('quantity' => 5)));
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...array('quantity' => 5)) targeting ShoppingCart_Controller::set_quantity_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
211
        $this->get(ShoppingCart_Controller::add_item_link($this->socks));
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...item_link($this->socks) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
212
213
        // set items via url
214
        $response = $this->get(
215
            ShoppingCart_Controller::set_quantity_item_link($this->mp3player, array('quantity' => 3, 'ajax' => 1))
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...ty' => 3, 'ajax' => 1)) targeting ShoppingCart_Controller::set_quantity_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
216
        );
217
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
218
            200,
219
            $response->getStatusCode(),
220
            "Response status code is 200"
221
        );
222
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
223
            "application/json; charset=utf-8",
224
            $response->getHeader("Content-Type"),
225
            "Json response header"
226
        );
227
        $this->assertJson(
0 ignored issues
show
Bug introduced by
The method assertJson() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
228
            $response->getBody(),
229
            "Contains json in the body of the response"
230
        );
231
232
        $this->assertContains(
233
            'Quantity has been set',
234
            $response->getBody(),
235
            "Contains a confirmation message that the quantity has been set to a new value"
236
        );
237
    }
238
239
    public function testClearAllItemsFromTheCart()
240
    {
241
        // add items via url to setup
242
        $this->get(ShoppingCart_Controller::set_quantity_item_link($this->mp3player, array('quantity' => 5)));
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...array('quantity' => 5)) targeting ShoppingCart_Controller::set_quantity_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
243
        $this->get(ShoppingCart_Controller::add_item_link($this->socks));
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...item_link($this->socks) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
244
245
        // remove items via url
246
        $response = $this->get("shoppingcart/clear?ajax=1");
247
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
248
            200,
249
            $response->getStatusCode(),
250
            "Response status code is 200"
251
        );
252
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
253
            "application/json; charset=utf-8",
254
            $response->getHeader("Content-Type"),
255
            "Json response header"
256
        );
257
        $this->assertJson(
0 ignored issues
show
Bug introduced by
The method assertJson() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
258
            $response->getBody(),
259
            "Contains json in the body of the response"
260
        );
261
262
        $this->assertContains(
263
            'Cart was successfully cleared',
264
            $response->getBody(),
265
            "Contains a message that the cart has been cleared"
266
        );
267
    }
268
269
    public function testVariations()
270
    {
271
        $this->loadFixture('silvershop/tests/fixtures/variations.yml');
272
        $ballRoot = $this->objFromFixture('Product', 'ball');
273
        
274
        // add parent for categories in JSON response
275
        $parent = $this->objFromFixture('ProductCategory', 'products');
276
        $ballRoot->ParentID = $parent->ID;
277
        $ballRoot->write();
278
279
        $ballRoot->publish('Stage', 'Live');
280
        $ball1 = $this->objFromFixture('ProductVariation', 'redlarge');
281
        $ball2 = $this->objFromFixture('ProductVariation', 'redsmall');
282
283
        // Add the two variation items
284
        $response = $this->get(ShoppingCart_Controller::add_item_link($ball1) . "?ajax=1");
0 ignored issues
show
Documentation introduced by
$ball1 is of type object<DataObject>|null, but the function expects a object<Buyable>.

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...
285
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
286
            200,
287
            $response->getStatusCode(),
288
            "Response status code is 200"
289
        );
290
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
291
            "application/json; charset=utf-8",
292
            $response->getHeader("Content-Type"),
293
            "Json response header"
294
        );
295
        $this->assertJson(
0 ignored issues
show
Bug introduced by
The method assertJson() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
296
            $response->getBody(),
297
            "Contains json in the body of the response"
298
        );
299
        $this->assertContains(
300
            "Size:Large, Color:Red",
301
            $response->getBody(),
302
            "Contains json in the body of the cart id"
303
        );
304
305
        $response = $this->get(ShoppingCart_Controller::add_item_link($ball2) . "?ajax=1");
0 ignored issues
show
Documentation introduced by
$ball2 is of type object<DataObject>|null, but the function expects a object<Buyable>.

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...
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
306
        $items = ShoppingCart::curr()->Items();
307
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
308
            $items->Count(),
309
            2,
310
            "There are 2 items in the cart"
311
        );
312
313
        // Remove one and see what happens
314
        $response = $this->get(ShoppingCart_Controller::remove_all_item_link($ball1) . "?ajax=1");
0 ignored issues
show
Documentation introduced by
$ball1 is of type object<DataObject>|null, but the function expects a object<Buyable>.

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...
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
315
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
316
            $items->Count(),
317
            1,
318
            "There is 1 item in the cart"
319
        );
320
        $this->assertFalse(
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
321
            $this->cart->get($ball1),
322
            "first item not in cart"
323
        );
324
        $this->assertNotNull(
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<SilvershopJsonResponseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
325
            $this->cart->get($ball1),
326
            "second item is in cart"
327
        );
328
    }
329
330
    public function testGet()
331
    {
332
        // add items via url to setup
333
        $this->get(ShoppingCart_Controller::set_quantity_item_link($this->mp3player, array('quantity' => 5)));
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...array('quantity' => 5)) targeting ShoppingCart_Controller::set_quantity_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
334
        $this->get(ShoppingCart_Controller::add_item_link($this->socks));
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...item_link($this->socks) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
335
        $shoppingcart = ShoppingCart::curr();
336
        $shoppingcart->calculate();  // recalculate the shopping cart
337
338
        $response = $this->get("shoppingcart/get" . "?ajax=1");
339
340
        $this->assertContains(
341
            'tableTitle',
342
            $response->getBody(),
343
            "Json contains tableTitle"
344
        );
345
        $this->assertContains(
346
            'tableValue',
347
            $response->getBody(),
348
            "Json contains tableValue"
349
        );
350
        $this->assertContains(
351
            'Tax @ 15.0%',
352
            $response->getBody(),
353
            "Contains GST modifier in the response"
354
        );
355
        $this->assertContains(
356
            '"subTotal":1008',
357
            $response->getBody(),
358
            "Contains SubTotal of 1008"
359
        );
360
        $this->assertContains(
361
            '"grandTotal":1159.2',
362
            $response->getBody(),
363
            "Contains a GrandTotal of 1159.2; the GST amount (the Flat Tax Modifier) is the difference"
364
        );
365
    }
366
}
367