Issues (4)

tests/EntityTest.php (4 issues)

Labels
Severity
1
<?php
2
3
namespace Byscripts\StaticEntity\Tests;
4
5
use Byscripts\StaticEntity\Tests\Fixtures\BadProperty;
6
use Byscripts\StaticEntity\Tests\Fixtures\Civility;
7
use Byscripts\StaticEntity\Tests\Fixtures\WebBrowser;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * Class EntityTest
12
 *
13
 * @author Thierry Goettelmann <[email protected]>
14
 */
15
class EntityTest extends TestCase
16
{
17
    public function testFind()
18
    {
19
        $civility = Civility::get(Civility::MR);
20
        $webBrowser = WebBrowser::get(WebBrowser::CHROME);
21
22
        $this->assertInstanceOf(Civility::class, $civility);
23
        $this->assertEquals(Civility::MR, $civility->getId());
24
        $this->assertEquals('Male', $civility->getGender());
0 ignored issues
show
The method getGender() does not exist on Byscripts\StaticEntity\StaticEntityInterface. It seems like you code against a sub-type of Byscripts\StaticEntity\StaticEntityInterface such as Byscripts\StaticEntity\Tests\Fixtures\Civility. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        $this->assertEquals('Male', $civility->/** @scrutinizer ignore-call */ getGender());
Loading history...
25
        $this->assertEquals('Mr.', $civility->getShortName());
0 ignored issues
show
The method getShortName() does not exist on Byscripts\StaticEntity\StaticEntityInterface. It seems like you code against a sub-type of Byscripts\StaticEntity\StaticEntityInterface such as Byscripts\StaticEntity\Tests\Fixtures\Civility. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        $this->assertEquals('Mr.', $civility->/** @scrutinizer ignore-call */ getShortName());
Loading history...
26
27
        $this->assertInstanceOf(WebBrowser::class, $webBrowser);
28
        $this->assertEquals(WebBrowser::CHROME, $webBrowser->getId());
29
        $this->assertEquals('Chrome', $webBrowser->getName());
0 ignored issues
show
The method getName() does not exist on Byscripts\StaticEntity\StaticEntityInterface. It seems like you code against a sub-type of Byscripts\StaticEntity\StaticEntityInterface such as Byscripts\StaticEntity\Tests\Fixtures\WebBrowser. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        $this->assertEquals('Chrome', $webBrowser->/** @scrutinizer ignore-call */ getName());
Loading history...
30
        $this->assertEquals('Google', $webBrowser->getVendor());
0 ignored issues
show
The method getVendor() does not exist on Byscripts\StaticEntity\StaticEntityInterface. It seems like you code against a sub-type of Byscripts\StaticEntity\StaticEntityInterface such as Byscripts\StaticEntity\Tests\Fixtures\WebBrowser. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        $this->assertEquals('Google', $webBrowser->/** @scrutinizer ignore-call */ getVendor());
Loading history...
31
    }
32
33
    /**
34
     * @expectedException \InvalidArgumentException
35
     * @expectedExceptionMessage Unable to find data
36
     */
37
    public function testNotFound()
38
    {
39
        WebBrowser::get('bad-id');
40
    }
41
42
    public function testFindReturnsSameInstance()
43
    {
44
        $civility1 = Civility::get(Civility::MR);
45
        $civility2 = Civility::get(Civility::MR);
46
47
        $this->assertSame($civility1, $civility2);
48
    }
49
50
    public function testExists()
51
    {
52
        $this->assertTrue(
53
            WebBrowser::hasId(WebBrowser::CHROME)
54
        );
55
56
        $this->assertFalse(
57
            WebBrowser::hasId('bad-id')
58
        );
59
    }
60
61
    public function testToId()
62
    {
63
        $civility = Civility::get(Civility::MR);
64
65
        $this->assertEquals(Civility::MR, Civility::toId($civility));
66
        $this->assertEquals(Civility::MR, Civility::toId(Civility::MR));
67
    }
68
69
    /**
70
     * @expectedException \InvalidArgumentException
71
     * @expectedExceptionMessage Unable to find ID
72
     */
73
    public function testBadIdToId()
74
    {
75
        Civility::toId('bad-id');
76
    }
77
78
    /**
79
     * @expectedException \InvalidArgumentException
80
     * @expectedExceptionMessage does not implement
81
     */
82
    public function testBadClassToId()
83
    {
84
        Civility::toId(new class {});
85
    }
86
87
    public function testFindAll()
88
    {
89
        /** @var $all Civility[] */
90
        $all = Civility::getAll();
91
92
        $this->assertArrayHasKey(Civility::MR, $all);
93
        $this->assertArrayHasKey(Civility::MRS, $all);
94
95
        $this->assertInstanceOf(Civility::class, $all[Civility::MR]);
96
        $this->assertInstanceOf(Civility::class, $all[Civility::MRS]);
97
98
        $this->assertEquals('Male', $all[Civility::MR]->getGender());
99
        $this->assertEquals('Female', $all[Civility::MRS]->getGender());
100
    }
101
102
    public function testGetAllTwice()
103
    {
104
        $all1 = Civility::getAll();
105
        $all2 = Civility::getAll();
106
107
        $this->assertSame($all1, $all2);
108
    }
109
110
    public function testFindAssociative()
111
    {
112
        $associative = Civility::getAssociative('gender');
113
114
        $this->assertArrayHasKey(Civility::MR, $associative);
115
        $this->assertArrayHasKey(Civility::MRS, $associative);
116
117
        $this->assertEquals('Male', $associative[Civility::MR]);
118
        $this->assertEquals('Female', $associative[Civility::MRS]);
119
120
        $associative = Civility::getAssociative('shortName');
121
122
        $this->assertArrayHasKey(Civility::MR, $associative);
123
        $this->assertArrayHasKey(Civility::MRS, $associative);
124
125
        $this->assertEquals('Mr.', $associative[Civility::MR]);
126
        $this->assertEquals('Mrs', $associative[Civility::MRS]);
127
    }
128
129
    public function testFindIds()
130
    {
131
        $ids = Civility::getIds();
132
133
        $this->assertEquals([Civility::MR, Civility::MRS], $ids);
134
    }
135
136
    /**
137
     * @expectedException \InvalidArgumentException
138
     * @expectedExceptionMessage has no property
139
     */
140
    public function testBadProperty()
141
    {
142
        BadProperty::getAll();
143
    }
144
}
145