| Conditions | 1 |
| Paths | 1 |
| Total Lines | 63 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 28 | public function testCustomProduct() |
||
| 29 | { |
||
| 30 | $thing = CustomProduct::create()->update( |
||
| 31 | [ |
||
| 32 | "Title" => "Thing", |
||
| 33 | "Price" => 30, |
||
| 34 | ] |
||
| 35 | ); |
||
| 36 | $thing->write(); |
||
| 37 | |||
| 38 | $cart = ShoppingCart::singleton(); |
||
| 39 | |||
| 40 | $options1 = ['Color' => 'Green', 'Size' => 5, 'Premium' => true]; |
||
| 41 | $this->assertTrue((bool)$cart->add($thing, 1, $options1), "add to customisation 1 to cart"); |
||
| 42 | $item = $cart->get($thing, $options1); |
||
| 43 | |||
| 44 | $this->assertTrue((bool)$item, "item with customisation 1 exists"); |
||
| 45 | $this->assertEquals(1, $item->Quantity); |
||
| 46 | |||
| 47 | $this->assertTrue((bool)$cart->add($thing, 2, $options1), "add another two customisation 1"); |
||
| 48 | $item = $cart->get($thing, $options1); |
||
| 49 | $this->assertEquals(3, $item->Quantity, "quantity has updated correctly"); |
||
| 50 | $this->assertEquals("Green", $item->Color); |
||
| 51 | $this->assertEquals(5, $item->Size); |
||
| 52 | $this->assertEquals(1, $item->Premium); //should be true? |
||
| 53 | |||
| 54 | $this->assertFalse((bool)$cart->get($thing), "try to get a non-customised product"); |
||
| 55 | |||
| 56 | $options2 = ['Color' => 'Blue', 'Size' => 6, 'Premium' => false]; |
||
| 57 | $this->assertTrue((bool)$cart->add($thing, 5, $options2), "add customisation 2 to cart"); |
||
| 58 | $item = $cart->get($thing, $options2); |
||
| 59 | $this->assertTrue((bool)$item, "item with customisation 2 exists"); |
||
| 60 | $this->assertEquals(5, $item->Quantity); |
||
| 61 | |||
| 62 | $options3 = ['Color' => 'Blue']; |
||
| 63 | $this->assertTrue((bool)$cart->add($thing, 1, $options3), "add a sub-variant of customisation 2"); |
||
| 64 | $item = $cart->get($thing, $options3); |
||
|
|
|||
| 65 | |||
| 66 | $this->assertTrue((bool)$cart->add($thing), "add product with no customisation"); |
||
| 67 | $item = $cart->get($thing); |
||
| 68 | |||
| 69 | $order = $cart->current(); |
||
| 70 | $items = $order->Items(); |
||
| 71 | $this->assertEquals(4, $items->Count(), "4 items in cart"); |
||
| 72 | |||
| 73 | //remove |
||
| 74 | $cart->remove($thing, 2, $options2); |
||
| 75 | $item = $cart->get($thing, $options2); |
||
| 76 | $this->assertNotNull($item, 'item exists in cart'); |
||
| 77 | $this->assertEquals(3, $item->Quantity); |
||
| 78 | |||
| 79 | $cart->clear(); |
||
| 80 | |||
| 81 | //set quantity |
||
| 82 | $options4 = ['Size' => 12, 'Color' => 'Blue', 'Premium' => false]; |
||
| 83 | $resp = $cart->setQuantity($thing, 5, $options4); |
||
| 84 | |||
| 85 | $item = $cart->get($thing, $options4); |
||
| 86 | $this->assertTrue((bool)$item, 'item exists in cart'); |
||
| 87 | |||
| 88 | $this->assertEquals(5, $item->Quantity, "quantity is 5"); |
||
| 89 | |||
| 90 | $this->markTestIncomplete("what about default values that have been set"); |
||
| 91 | //test by using urls |
||
| 95 |