|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace StraTDeS\VO\Tests\Collection; |
|
4
|
|
|
|
|
5
|
|
|
use StraTDeS\VO\Collection\CurrencyCollection; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use StraTDeS\VO\Single\Currency; |
|
8
|
|
|
|
|
9
|
|
|
class CurrencyCollectionTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testGivenValidCurrenciesAValidCurrencyCollectionIsReturned(): void |
|
12
|
|
|
{ |
|
13
|
|
|
// Arrange |
|
14
|
|
|
$currency1 = Currency::fromValue(Currency::EUR); |
|
15
|
|
|
$currency2 = Currency::fromValue(Currency::USD); |
|
16
|
|
|
$currency3 = Currency::fromValue(Currency::VES); |
|
17
|
|
|
$currencyArray = [ |
|
18
|
|
|
$currency1, |
|
19
|
|
|
$currency2, |
|
20
|
|
|
$currency3 |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
// Act |
|
24
|
|
|
$currencyCollection = CurrencyCollection::create(); |
|
25
|
|
|
$currencyCollection->add($currency1); |
|
26
|
|
|
$currencyCollection->add($currency2); |
|
27
|
|
|
$currencyCollection->add($currency3); |
|
28
|
|
|
|
|
29
|
|
|
// Assert |
|
30
|
|
|
$this->assertInstanceOf(CurrencyCollection::class, $currencyCollection); |
|
31
|
|
|
$this->assertEquals($currency1, $currencyCollection[0]); |
|
32
|
|
|
$this->assertEquals($currency2, $currencyCollection[1]); |
|
33
|
|
|
$this->assertEquals($currency3, $currencyCollection[2]); |
|
34
|
|
|
$this->assertEquals( |
|
35
|
|
|
$currencyArray, |
|
36
|
|
|
$currencyCollection->items() |
|
37
|
|
|
); |
|
38
|
|
|
$this->assertEquals(3, count($currencyCollection)); |
|
39
|
|
|
|
|
40
|
|
|
for($i = 0; $i < 3; $i++) { |
|
41
|
|
|
$this->assertEquals($currencyArray[$i], $currencyCollection[$i]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
foreach($currencyCollection as $key => $currency) { |
|
45
|
|
|
$this->assertInstanceOf(Currency::class, $currency); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testGivenAValueByOffsetReturnsAValidValue(): void |
|
50
|
|
|
{ |
|
51
|
|
|
// Arrange |
|
52
|
|
|
$currency1 = Currency::fromValue(Currency::EUR); |
|
53
|
|
|
|
|
54
|
|
|
// Act |
|
55
|
|
|
$currencyCollection = CurrencyCollection::create(); |
|
56
|
|
|
$currencyCollection[0] = $currency1; |
|
57
|
|
|
|
|
58
|
|
|
// Assert |
|
59
|
|
|
$this->assertEquals($currency1, $currencyCollection[0]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testGivenAnInvalidValueItThrowsAnException(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
65
|
|
|
$this->expectExceptionMessage("Provided value is not a valid " . Currency::class); |
|
66
|
|
|
|
|
67
|
|
|
$currency1 = new \stdClass(); |
|
68
|
|
|
|
|
69
|
|
|
$currencyCollection = CurrencyCollection::create(); |
|
70
|
|
|
$currencyCollection->add($currency1); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|