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