|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ArpTest\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use ArpTest\Entity\Double\EntityFake; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @covers \Arp\Entity\EntityTrait |
|
12
|
|
|
*/ |
|
13
|
|
|
final class EntityTraitTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
private EntityFake $entity; |
|
16
|
|
|
|
|
17
|
|
|
public function setUp(): void |
|
18
|
|
|
{ |
|
19
|
|
|
$this->entity = new EntityFake(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Assert that we can set and get the id using setId() and getId() |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testGetSetId(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$id = 123; |
|
28
|
|
|
$this->entity->setId($id); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertSame($id, $this->entity->getId()); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Assert that when calling hasId() without any id set, boolean FALSE is returned |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testHasIdWillReturnFalseByDefault(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->assertFalse($this->entity->hasId()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Assert that when the id is set that calls to hasId() will return boolean TRUE |
|
43
|
|
|
*/ |
|
44
|
|
|
public function testHasIdWillReturnTrueWhenIdIsNotNull(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$id = 123; |
|
47
|
|
|
$this->entity->setId($id); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertTrue($this->entity->hasId()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Assert that calls to isId() will return the correct boolean value |
|
54
|
|
|
* |
|
55
|
|
|
* @dataProvider getIsIdData |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testIsId(int $id, int $testId, bool $expected): void |
|
58
|
|
|
{ |
|
59
|
|
|
$this->entity->setId($id); |
|
60
|
|
|
|
|
61
|
|
|
$result = $this->entity->isId($testId); |
|
62
|
|
|
|
|
63
|
|
|
if ($expected) { |
|
64
|
|
|
$this->assertTrue($result); |
|
65
|
|
|
} else { |
|
66
|
|
|
$this->assertFalse($result); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return array<mixed> |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getIsIdData(): array |
|
74
|
|
|
{ |
|
75
|
|
|
return [ |
|
76
|
|
|
[123, 123, true], |
|
77
|
|
|
[456, 456, true], |
|
78
|
|
|
[123, 10, false], |
|
79
|
|
|
[999, 901, false], |
|
80
|
|
|
[12345, 12345, true], |
|
81
|
|
|
]; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|