Passed
Pull Request — master (#5)
by Alex
02:32
created

EntityTraitTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ArpTest\Entity;
6
7
use Arp\Entity\EntityTrait;
8
use PHPUnit\Framework\MockObject\MockObject;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * @covers  \Arp\Entity\EntityTrait
13
 *
14
 * @author  Alex Patterson <[email protected]>
15
 * @package ArpTest\Entity
16
 */
17
final class EntityTraitTest extends TestCase
18
{
19
    /** @var EntityTrait|MockObject */
20
    private $entityTrait;
21
22
    /**
23
     * Set up the test dependencies.
24
     */
25
    public function setUp(): void
26
    {
27
        $this->entityTrait = $this->getMockForTrait(EntityTrait::class);
28
    }
29
30
    /**
31
     * Assert that we can set and get the id using setId() and getId().
32
     */
33
    public function testGetSetId(): void
34
    {
35
        $id = 'A';
36
        $this->entityTrait->setId($id);
37
38
        $this->assertSame($id, $this->entityTrait->getId());
39
    }
40
41
    /**
42
     * Assert that when calling hasId() without any id set, boolean FALSE is returned.
43
     */
44
    public function testHasIdWillReturnFalseByDefault(): void
45
    {
46
        $this->assertFalse($this->entityTrait->hasId());
47
    }
48
49
    /**
50
     * Assert that when the id is set that calls to hasId() will return boolean TRUE.
51
     */
52
    public function testHasIdWillReturnTrueWhenIdIsNotNull(): void
53
    {
54
        $id = 'ABC';
55
        $this->entityTrait->setId($id);
56
57
        $this->assertTrue($this->entityTrait->hasId());
58
    }
59
60
    /**
61
     * Assert that calls to isId() will return the correct boolean value.
62
     *
63
     * @param string  $id
64
     * @param string  $testId
65
     * @param boolean $expected
66
     *
67
     * @dataProvider getIsIdData
68
     */
69
    public function testIsId(string $id, string $testId, bool $expected): void
70
    {
71
        $this->entityTrait->setId($id);
72
73
        $result = $this->entityTrait->isId($testId);
74
        if ($expected) {
75
            $this->assertTrue($result);
76
        } else {
77
            $this->assertFalse($result);
78
        }
79
    }
80
81
    /**
82
     * @return array|array[]
83
     */
84
    public function getIsIdData(): array
85
    {
86
        return [
87
            ['', '', true],
88
            ['ABC', 'ABC', true],
89
            ['', 'ABC', false],
90
            ['HELLO', 'TEST', false],
91
            ['TEST123', 'TEST123', true],
92
        ];
93
    }
94
}
95