testSetAndGetDateCreated()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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