MoneyTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testCompare() 0 4 1
A testExceptionWithDifferentCurrencies() 0 8 1
A provideCompare() 0 11 1
A testCreate() 0 5 1
A testGreaterThan() 0 8 1
A testEquals() 0 8 1
A testLessThan() 0 8 1
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);
0 ignored issues
show
Bug introduced by
The method EUR() does not exist on ConferenceTools\Tickets\Domain\ValueObject\Money. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

11
        /** @scrutinizer ignore-call */ 
12
        $sut = Money::EUR(300);
Loading history...
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 function PHPUnit_Framework_TestCase::setExpectedException() has been deprecated: Method deprecated since Release 5.2.0; use expectException() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

45
        /** @scrutinizer ignore-deprecated */ $this->setExpectedException(\InvalidArgumentException::class);

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

The explanatory message should give you some clue as to whether and when the function will be removed and what other function 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
    public function testEquals()
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
    public function testLessThan()
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
    public function testGreaterThan()
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