|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the daikon-cqrs/value-object project. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Daikon\Tests\ValueObject; |
|
10
|
|
|
|
|
11
|
|
|
use Daikon\Tests\ValueObject\Fixture\DateList; |
|
12
|
|
|
use Daikon\ValueObject\Date; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
|
|
15
|
|
|
final class DateListTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
1 |
|
public function testConstruct(): void |
|
18
|
|
|
{ |
|
19
|
1 |
|
$d0 = Date::fromString('2020-01-01'); |
|
20
|
1 |
|
$unwrappedList = (new DateList([$d0]))->unwrap(); |
|
21
|
1 |
|
$this->assertNotSame($d0, $unwrappedList[0]); |
|
22
|
1 |
|
$this->assertEquals($d0, $unwrappedList[0]); |
|
23
|
1 |
|
} |
|
24
|
|
|
|
|
25
|
1 |
|
public function testEquals(): void |
|
26
|
|
|
{ |
|
27
|
1 |
|
$d0 = Date::fromString('2020-01-01'); |
|
28
|
1 |
|
$list0 = new DateList([$d0]); |
|
29
|
1 |
|
$list1 = new DateList([$d0]); |
|
30
|
1 |
|
$this->assertTrue($list0->equals($list1)); |
|
31
|
1 |
|
$this->assertNotSame($list0, $list1); |
|
32
|
1 |
|
$this->assertEquals($list0, $list1); |
|
33
|
1 |
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
public function testNotEquals(): void |
|
36
|
|
|
{ |
|
37
|
1 |
|
$d0 = Date::fromString('2020-01-01'); |
|
38
|
1 |
|
$d1 = Date::fromString('2030-01-01'); |
|
39
|
1 |
|
$d2 = clone $d1; |
|
40
|
1 |
|
$list0 = new DateList([$d0, $d1]); |
|
41
|
1 |
|
$list1 = new DateList([$d2, $d0]); |
|
42
|
1 |
|
$this->assertFalse($list0->equals($list1)); |
|
43
|
1 |
|
$this->assertNotSame($list0, $list1); |
|
44
|
1 |
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
public function testToString(): void |
|
47
|
|
|
{ |
|
48
|
1 |
|
$d0 = Date::fromString('2020-01-01'); |
|
49
|
1 |
|
$d1 = Date::fromString('2030-01-01'); |
|
50
|
1 |
|
$list = new DateList([$d0, $d1]); |
|
51
|
1 |
|
$this->assertEquals('0:2020-01-01, 1:2030-01-01', (string)$list); |
|
52
|
1 |
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|