RounderTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 71
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testRound() 0 4 1
A testRoundPound() 0 5 1
A testRoundPoundUp() 0 5 1
A testRoundPoundDown() 0 5 1
A testRoundFifty() 0 6 1
A testRoundFiftyUp() 0 6 1
A testRoundFiftyDown() 0 6 1
A testRoundToZero() 0 4 1
A testGetRoundingRules() 0 6 1
1
<?php
2
3
namespace Meanbee\MagentoRoyalmail\Test\Unit\Model;
4
5
use Meanbee\MagentoRoyalmail\Model\Rounder;
6
7
/**
8
 * Class RounderTest
9
 */
10
class RounderTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var Rounder
14
     */
15
    protected $rounder;
16
17
    /**
18
     * @inheritdoc
19
     */
20
    protected function setUp()
21
    {
22
        $this->rounder = new Rounder();
23
    }
24
25
    public function testRound()
26
    {
27
        $this->assertEquals(1, $this->rounder->round('', 1));
28
    }
29
30
    public function testRoundPound()
31
    {
32
        $this->assertEquals(1, $this->rounder->round(Rounder::POUND, 0.53));
33
        $this->assertEquals(1, $this->rounder->round(Rounder::POUND, 1.03));
34
    }
35
36
    public function testRoundPoundUp()
37
    {
38
        $this->assertEquals(1, $this->rounder->round(Rounder::POUND_UP, 0.43));
39
        $this->assertEquals(1, $this->rounder->round(Rounder::POUND_UP, 0.53));
40
    }
41
42
    public function testRoundPoundDown()
43
    {
44
        $this->assertEquals(1, $this->rounder->round(Rounder::POUND_DOWN, 1.43));
45
        $this->assertEquals(1, $this->rounder->round(Rounder::POUND_DOWN, 1.53));
46
    }
47
48
    public function testRoundFifty()
49
    {
50
        $this->assertEquals(1.50, $this->rounder->round(Rounder::FIFTY, 1.49));
51
        $this->assertEquals(1, $this->rounder->round(Rounder::FIFTY, 1.23));
52
        $this->assertEquals(2, $this->rounder->round(Rounder::FIFTY, 1.75));
53
    }
54
55
    public function testRoundFiftyUp()
56
    {
57
        $this->assertEquals(1.50, $this->rounder->round(Rounder::FIFTY_UP, 1.49));
58
        $this->assertEquals(1.50, $this->rounder->round(Rounder::FIFTY_UP, 1.23));
59
        $this->assertEquals(2, $this->rounder->round(Rounder::FIFTY_UP, 1.75));
60
    }
61
62
    public function testRoundFiftyDown()
63
    {
64
        $this->assertEquals(1, $this->rounder->round(Rounder::FIFTY_DOWN, 1.49));
65
        $this->assertEquals(1.50, $this->rounder->round(Rounder::FIFTY_DOWN, 1.53));
66
        $this->assertEquals(1.50, $this->rounder->round(Rounder::FIFTY_DOWN, 1.90));
67
    }
68
69
    public function testRoundToZero()
70
    {
71
        $this->assertEquals(1, $this->rounder->round(Rounder::POUND_DOWN, 0.40));
72
    }
73
74
    public function testGetRoundingRules()
75
    {
76
        $rules = $this->rounder->getRoundingRules();
77
        $this->assertInternalType('array', $rules);
78
        $this->assertGreaterThan(0, count($rules));
79
    }
80
}
81