Completed
Push — master ( 0d684b...49516e )
by Dariusz
03:16
created

ShippingTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 43
loc 43
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateObject() 11 11 1
A testSetCost() 7 7 1
A testSetPriceFormat() 13 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Plane\Shop\Tests;
4
5
use Plane\Shop\Shipping;
6
use Plane\Shop\PriceFormat\EnglishFormat as PriceFormat;
7
8
/**
9
 * Shipping test suite
10
 *
11
 * @author Dariusz Korsak <[email protected]>
12
 * @package Plane\Shop
13
 */
14 View Code Duplication
class ShippingTest extends \PHPUnit\Framework\TestCase
15
{
16
    protected $shippingInput = [
17
       'id'             => 1,
18
       'name'           => 'National postal services',
19
       'description'    => '',
20
       'cost'           => 3.4
21
    ];
22
23
    public function testCreateObject()
24
    {
25
        $shipping = new Shipping($this->shippingInput);
26
27
        $this->assertSame($this->shippingInput, [
28
            'id'                => $shipping->getId(),
29
            'name'              => $shipping->getName(),
30
            'description'       => $shipping->getDescription(),
31
            'cost'              => $shipping->getCost(),
32
        ]);
33
    }
34
    
35
    public function testSetCost()
36
    {
37
        $shipping = new Shipping($this->shippingInput);
38
        $shipping->setCost(2);
39
        
40
        $this->assertSame(2.00, $shipping->getCost());
41
    }
42
43
    public function testSetPriceFormat()
44
    {
45
        $priceFormat = $this->getMockBuilder(PriceFormat::class)->getMock();
46
        
47
        $priceFormat->expects($this->any())
48
            ->method('formatPrice')
49
            ->willReturn(3.40);
50
        
51
        $shipping = new Shipping($this->shippingInput);
52
        $shipping->setPriceFormat($priceFormat);
53
        
54
        $this->assertSame(3.40, $shipping->getCost());
55
    }
56
}
57