1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ArpTest\Entity; |
6
|
|
|
|
7
|
|
|
use Arp\Entity\DateCreatedAwareTrait; |
8
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @covers \Arp\Entity\DateCreatedAwareTrait |
13
|
|
|
* |
14
|
|
|
* @author Alex Patterson <[email protected]> |
15
|
|
|
* @package ArpTest\Entity |
16
|
|
|
*/ |
17
|
|
|
final class DateCreatedAwareTraitTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var DateCreatedAwareTrait|MockObject |
21
|
|
|
*/ |
22
|
|
|
private $dateCreatedAwareTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Prepare the test case dependencies. |
26
|
|
|
*/ |
27
|
|
|
public function setUp(): void |
28
|
|
|
{ |
29
|
|
|
$this->dateCreatedAwareTrait = $this->getMockForTrait(DateCreatedAwareTrait::class); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Assert that the created date time can be set and returned calling setDateCreated() and getDateCreated(). |
34
|
|
|
*/ |
35
|
|
|
public function testSetAndGetDateCreated(): void |
36
|
|
|
{ |
37
|
|
|
$this->assertNull($this->dateCreatedAwareTrait->getDateCreated()); |
38
|
|
|
|
39
|
|
|
$dateCreated = new \DateTime(); |
40
|
|
|
|
41
|
|
|
$this->dateCreatedAwareTrait->setDateCreated($dateCreated); |
42
|
|
|
|
43
|
|
|
$this->assertSame($dateCreated, $this->dateCreatedAwareTrait->getDateCreated()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Assert that the default value returned from hasDateCreated() is false. |
48
|
|
|
*/ |
49
|
|
|
public function testHasDateCreatedIsDefaultFalse(): void |
50
|
|
|
{ |
51
|
|
|
$this->assertFalse($this->dateCreatedAwareTrait->hasDateCreated()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Assert that if a created date has been set, the call to hasDate() will return true. |
56
|
|
|
*/ |
57
|
|
|
public function testHasDateCreatedWillReturnTrueWhenDateIsSet(): void |
58
|
|
|
{ |
59
|
|
|
$createdDate = new \DateTime(); |
60
|
|
|
|
61
|
|
|
$this->dateCreatedAwareTrait->setDateCreated($createdDate); |
62
|
|
|
|
63
|
|
|
$this->assertTrue($this->dateCreatedAwareTrait->hasDateCreated()); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|