Passed
Push — master ( c541cb...64a56e )
by Chris
33s
created

MoneyTest::provideCompare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
4
namespace ConferenceTools\Tickets\Domain\ValueObject;
5
6
7
class MoneyTest extends \PHPUnit\Framework\TestCase
8
{
9
    public function testCreate()
10
    {
11
        $sut = Money::EUR(300);
12
        self::assertEquals(300, $sut->getAmount());
13
        self::assertEquals('EUR', $sut->getCurrency());
14
    }
15
16
    /**
17
     * @dataProvider provideCompare
18
     *
19
     * @param Money $a
20
     * @param Money $b
21
     * @param int $expected
22
     */
23
    public function testCompare(Money $a, Money $b, $expected)
24
    {
25
        self::assertEquals($expected, $a->compare($b));
26
        self::assertEquals(-1 * $expected, $b->compare($a));
27
    }
28
29
    public function provideCompare()
30
    {
31
        $a = new Money(10, 'GBP');
32
        $b = new Money(10, 'GBP');
33
        $c = new Money(11, 'GBP');
34
        $d = new Money(12, 'GBP');
35
        return [
36
            [$a, $b, 0],
37
            [$b, $c, -1],
38
            [$c, $d, -1],
39
            [$d, $a, 1],
40
        ];
41
    }
42
43
    public function testExceptionWithDifferentCurrencies()
44
    {
45
        $this->setExpectedException(\InvalidArgumentException::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
46
47
        $sut = new Money(10, 'GBP');
48
        $money1 = new Money(9, 'USD');
49
50
        $sut->compare($money1);
51
    }
52
53 View Code Duplication
    public function testEquals()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $sut = new Money(10, 'GBP');
56
        $money1 = new Money(10, 'GBP');
57
        $money2 = new Money(11, 'GBP');
58
59
        self::assertTrue($sut->equals($money1));
60
        self::assertFalse($sut->equals($money2));
61
    }
62
63 View Code Duplication
    public function testLessThan()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $sut = new Money(10, 'GBP');
66
        $money1 = new Money(9, 'GBP');
67
        $money2 =  new Money(11, 'GBP');
68
69
        self::assertTrue($sut->lessThan($money2));
70
        self::assertFalse($sut->lessThan($money1));
71
    }
72
73 View Code Duplication
    public function testGreaterThan()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
    {
75
        $sut = new Money(10, 'GBP');
76
        $money1 = new Money(9, 'GBP');
77
        $money2 = new Money(11, 'GBP');
78
79
        self::assertTrue($sut->greaterThan($money1));
80
        self::assertFalse($sut->greaterThan($money2));
81
    }
82
}
83