Repository navigation
Expand file tree
/
Copy pathAbstractDomainIdTest.php
More file actions
83 lines (69 loc) · 2.37 KB
/
Copy pathAbstractDomainIdTest.php
File metadata and controls
83 lines (69 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
declare(strict_types=1);
namespace MsgPhp\Domain\Tests;
use MsgPhp\Domain\AbstractDomainId;
use MsgPhp\Domain\DomainId;
use MsgPhp\Domain\GenericDomainId;
use PHPUnit\Framework\TestCase;
/**
* @internal
*/
final class AbstractDomainIdTest extends TestCase
{
public function testFromInt(): void
{
self::assertTrue(TestAbstractDomainId::fromInt(null)->isNil());
self::assertFalse(TestAbstractDomainId::fromInt(-123)->isNil());
self::assertSame('-123', TestAbstractDomainId::fromInt(-123)->toString());
self::assertTrue(TestAbstractDomainId::fromInt(0)->isNil());
self::assertSame('123', TestAbstractDomainId::fromInt(123)->toString());
self::assertFalse(TestAbstractDomainId::fromInt(123)->isNil());
}
public function testIsNil(): void
{
$id = $this->createMock(DomainId::class);
$id->expects(self::once())
->method('isNil')
->with()
->willReturn(true)
;
self::assertTrue((new TestAbstractDomainId($id))->isNil());
}
public function testEquals(): void
{
$id = $this->createMock(DomainId::class);
$id->expects(self::exactly(2))
->method('equals')
->with($id)
->willReturn(true)
;
self::assertFalse((new TestAbstractDomainId($id))->equals(''));
self::assertFalse((new TestAbstractDomainId($id))->equals($id));
self::assertTrue((new TestAbstractDomainId($id))->equals(new TestAbstractDomainId($id)));
self::assertTrue((new TestAbstractDomainId($id))->equals(new TestSubAbstractDomainId($id)));
self::assertFalse((new TestAbstractDomainId($id))->equals(new TestOtherAbstractDomainId($id)));
}
public function testToString(): void
{
$id = $this->createMock(DomainId::class);
$id->expects(self::once())
->method('toString')
->with()
->willReturn('foo')
;
self::assertSame('foo', (new TestAbstractDomainId($id))->toString());
}
public function testSerialize(): void
{
self::assertSame('foo', (string) unserialize(serialize(new TestAbstractDomainId(new GenericDomainId('foo')))));
}
}
class TestAbstractDomainId extends AbstractDomainId
{
}
class TestSubAbstractDomainId extends TestAbstractDomainId
{
}
class TestOtherAbstractDomainId extends AbstractDomainId
{
}