|
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); |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
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
|
|
|
|
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.