BaseEntityTest   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 153
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 81
c 2
b 0
f 0
dl 0
loc 153
rs 10
wmc 13

13 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsSaved() 0 3 1
A testPrimaryKeys() 0 3 1
A testGetters() 0 16 1
A testIsNew() 0 3 1
A testColumns() 0 3 1
A testDataOriginalWithInvalidKey() 0 6 1
A testDataOriginal() 0 19 1
A testData() 0 12 1
A testDataWithInvalidKey() 0 6 1
A testGettersInvalid() 0 6 1
A setUp() 0 9 1
A testPrimaryKeysAutoIncrement() 0 3 1
A testSetters() 0 21 1
1
<?php declare(strict_types=1);
2
3
namespace Janisbiz\LightOrm\Tests\Unit\Entity;
4
5
use Janisbiz\LightOrm\Entity\BaseEntity;
6
use Janisbiz\LightOrm\Entity\EntityException;
7
use PHPUnit\Framework\TestCase;
8
9
class BaseEntityTest extends TestCase
10
{
11
    const COL_ONE_VALUE = '<b>valOne</b>';
12
    const COL_ONE_VALUE_REPLACEMENT = 'valOneReplacement';
13
    const COL_TWO_VALUE = 2;
14
    const COL_TWO_VALUE_REPLACEMENT = 2.2;
15
    const COL_THREE_VALUE = 3.3;
16
    const COL_THREE_VALUE_REPLACEMENT = 3.33;
17
    const COL_THREE_VALUE_REPLACEMENT_EMPTY = '';
18
    const COL_FOUR_VALUE = 'This is column four!';
19
    const COL_FIVE_VALUE = 'This is column five!';
20
    const COL_NON_EXISTENT = 'non_existent';
21
    const COL_NON_EXISTENT_VALUE = null;
22
23
    /**
24
     * @var BaseEntity
25
     */
26
    private $baseEntity;
27
28
    public function setUp()
29
    {
30
        $baseEntity = new BaseEntity();
31
32
        $baseEntity->col_one = static::COL_ONE_VALUE;
0 ignored issues
show
Bug Best Practice introduced by
The property col_one does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __set, consider adding a @property annotation.
Loading history...
33
        $baseEntity->col_two = static::COL_TWO_VALUE;
0 ignored issues
show
Bug Best Practice introduced by
The property col_two does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __set, consider adding a @property annotation.
Loading history...
34
        $baseEntity->col_three = static::COL_THREE_VALUE;
0 ignored issues
show
Bug Best Practice introduced by
The property col_three does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __set, consider adding a @property annotation.
Loading history...
35
36
        $this->baseEntity = $baseEntity;
37
    }
38
39
    public function testGetters()
40
    {
41
        $this->assertEquals(static::COL_ONE_VALUE, $this->baseEntity->getColOne());
0 ignored issues
show
Bug introduced by
The method getColOne() does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

41
        $this->assertEquals(static::COL_ONE_VALUE, $this->baseEntity->/** @scrutinizer ignore-call */ getColOne());
Loading history...
42
        $this->assertEquals(
43
            \nl2br(\htmlspecialchars(\trim(static::COL_ONE_VALUE), ENT_QUOTES, 'UTF-8')),
44
            $this->baseEntity->getColOne(true)
45
        );
46
        $this->assertEquals(static::COL_ONE_VALUE, $this->baseEntity->col_one);
0 ignored issues
show
Bug Best Practice introduced by
The property col_one does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __get, consider adding a @property annotation.
Loading history...
47
        $this->assertEquals(static::COL_TWO_VALUE, $this->baseEntity->getColTwo());
0 ignored issues
show
Bug introduced by
The method getColTwo() does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

47
        $this->assertEquals(static::COL_TWO_VALUE, $this->baseEntity->/** @scrutinizer ignore-call */ getColTwo());
Loading history...
48
        $this->assertEquals(static::COL_TWO_VALUE, $this->baseEntity->getColTwo(true));
49
        $this->assertEquals(static::COL_TWO_VALUE, $this->baseEntity->col_two);
0 ignored issues
show
Bug Best Practice introduced by
The property col_two does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __get, consider adding a @property annotation.
Loading history...
50
        $this->assertEquals(static::COL_THREE_VALUE, $this->baseEntity->getColThree());
0 ignored issues
show
Bug introduced by
The method getColThree() does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

50
        $this->assertEquals(static::COL_THREE_VALUE, $this->baseEntity->/** @scrutinizer ignore-call */ getColThree());
Loading history...
51
        $this->assertEquals(static::COL_THREE_VALUE, $this->baseEntity->getColThree(true));
52
        $this->assertEquals(static::COL_THREE_VALUE, $this->baseEntity->col_three);
0 ignored issues
show
Bug Best Practice introduced by
The property col_three does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __get, consider adding a @property annotation.
Loading history...
53
        $this->assertEquals(static::COL_THREE_VALUE, $this->baseEntity->col_three);
54
        $this->assertEquals(static::COL_NON_EXISTENT_VALUE, $this->baseEntity->invalid_col);
0 ignored issues
show
Bug Best Practice introduced by
The property invalid_col does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __get, consider adding a @property annotation.
Loading history...
55
    }
56
57
    public function testGettersInvalid()
58
    {
59
        $this->expectException(EntityException::class);
60
        $this->expectExceptionMessage('Call to undefined method Janisbiz\LightOrm\Entity\BaseEntity::getInvalidCol()');
61
62
        $this->baseEntity->getInvalidCol();
0 ignored issues
show
Bug introduced by
The method getInvalidCol() does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

62
        $this->baseEntity->/** @scrutinizer ignore-call */ 
63
                           getInvalidCol();
Loading history...
63
    }
64
65
    public function testSetters()
66
    {
67
        $this->baseEntity->setColThree(static::COL_THREE_VALUE_REPLACEMENT);
0 ignored issues
show
Bug introduced by
The method setColThree() does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

67
        $this->baseEntity->/** @scrutinizer ignore-call */ 
68
                           setColThree(static::COL_THREE_VALUE_REPLACEMENT);
Loading history...
68
        $this->assertEquals(static::COL_THREE_VALUE_REPLACEMENT, $this->baseEntity->getColThree());
69
        $this->assertEquals(static::COL_THREE_VALUE_REPLACEMENT, $this->baseEntity->col_three);
0 ignored issues
show
Bug Best Practice introduced by
The property col_three does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __get, consider adding a @property annotation.
Loading history...
70
71
        $this->baseEntity->setColThree(static::COL_THREE_VALUE_REPLACEMENT_EMPTY);
72
        $this->assertEquals(null, $this->baseEntity->getColThree());
73
        $this->assertEquals(null, $this->baseEntity->col_three);
74
75
        $this->baseEntity->setColFour(static::COL_FOUR_VALUE);
0 ignored issues
show
Bug introduced by
The method setColFour() does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

75
        $this->baseEntity->/** @scrutinizer ignore-call */ 
76
                           setColFour(static::COL_FOUR_VALUE);
Loading history...
76
        $this->assertEquals(static::COL_FOUR_VALUE, $this->baseEntity->getColFour());
0 ignored issues
show
Bug introduced by
The method getColFour() does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

76
        $this->assertEquals(static::COL_FOUR_VALUE, $this->baseEntity->/** @scrutinizer ignore-call */ getColFour());
Loading history...
77
        $this->assertEquals(static::COL_FOUR_VALUE, $this->baseEntity->col_four);
0 ignored issues
show
Bug Best Practice introduced by
The property col_four does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __get, consider adding a @property annotation.
Loading history...
78
79
        $this->baseEntity->col_one = static::COL_ONE_VALUE_REPLACEMENT;
0 ignored issues
show
Bug Best Practice introduced by
The property col_one does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __set, consider adding a @property annotation.
Loading history...
80
        $this->assertEquals(static::COL_ONE_VALUE_REPLACEMENT, $this->baseEntity->getColOne());
81
        $this->assertEquals(static::COL_ONE_VALUE_REPLACEMENT, $this->baseEntity->col_one);
0 ignored issues
show
Bug Best Practice introduced by
The property col_one does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __get, consider adding a @property annotation.
Loading history...
82
83
        $this->baseEntity->col_five = static::COL_FIVE_VALUE;
0 ignored issues
show
Bug Best Practice introduced by
The property col_five does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __set, consider adding a @property annotation.
Loading history...
84
        $this->assertEquals(static::COL_FIVE_VALUE, $this->baseEntity->getColFive());
0 ignored issues
show
Bug introduced by
The method getColFive() does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

84
        $this->assertEquals(static::COL_FIVE_VALUE, $this->baseEntity->/** @scrutinizer ignore-call */ getColFive());
Loading history...
85
        $this->assertEquals(static::COL_FIVE_VALUE, $this->baseEntity->col_five);
0 ignored issues
show
Bug Best Practice introduced by
The property col_five does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __get, consider adding a @property annotation.
Loading history...
86
    }
87
88
    public function testData()
89
    {
90
        $data = &$this->baseEntity->data();
91
92
        $this->assertCount(3, $data);
93
        $this->baseEntity->setColFour(static::COL_FOUR_VALUE);
94
        $this->assertCount(4, $data);
95
        $data['col_five'] = static::COL_FIVE_VALUE;
96
        $this->assertCount(5, $data);
97
        $this->assertEquals(static::COL_FIVE_VALUE, $this->baseEntity->getColFive());
98
        $this->assertEquals(static::COL_FIVE_VALUE, $this->baseEntity->col_five);
0 ignored issues
show
Bug Best Practice introduced by
The property col_five does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __get, consider adding a @property annotation.
Loading history...
99
        $this->assertEquals(static::COL_FIVE_VALUE, $this->baseEntity->data('col_five'));
100
    }
101
102
    public function testDataWithInvalidKey()
103
    {
104
        $this->expectException(EntityException::class);
105
        $this->expectExceptionMessage('There is no key "ivalid_key" present in data!');
106
107
        $this->baseEntity->data('ivalid_key');
108
    }
109
110
    public function testDataOriginal()
111
    {
112
        $data = &$this->baseEntity->data();
113
        $dataOriginal = &$this->baseEntity->dataOriginal();
114
115
        $this->assertCount(3, $dataOriginal);
116
117
        $this->baseEntity->setColFour(static::COL_FOUR_VALUE);
118
        $this->assertCount(3, $dataOriginal);
119
120
        $data['col_five'] = static::COL_FIVE_VALUE;
121
        $this->assertCount(3, $dataOriginal);
122
123
        $this->assertEquals(static::COL_FIVE_VALUE, $this->baseEntity->getColFive());
124
        $this->assertEquals(static::COL_FIVE_VALUE, $this->baseEntity->dataOriginal('col_five'));
125
        $this->assertEquals(static::COL_FIVE_VALUE, $this->baseEntity->col_five);
0 ignored issues
show
Bug Best Practice introduced by
The property col_five does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __get, consider adding a @property annotation.
Loading history...
126
127
        $this->baseEntity->col_five = static::COL_FIVE_VALUE;
0 ignored issues
show
Bug Best Practice introduced by
The property col_five does not exist on Janisbiz\LightOrm\Entity\BaseEntity. Since you implemented __set, consider adding a @property annotation.
Loading history...
128
        $this->assertCount(4, $dataOriginal);
129
    }
130
131
    public function testDataOriginalWithInvalidKey()
132
    {
133
        $this->expectException(EntityException::class);
134
        $this->expectExceptionMessage('There is no key "ivalid_key" present in data original!');
135
136
        $this->baseEntity->dataOriginal('ivalid_key');
137
    }
138
139
    public function testIsNew()
140
    {
141
        $this->assertTrue($this->baseEntity->isNew());
142
    }
143
144
    public function testIsSaved()
145
    {
146
        $this->assertFalse($this->baseEntity->isSaved());
147
    }
148
149
    public function testPrimaryKeys()
150
    {
151
        $this->assertCount(0, $this->baseEntity->primaryKeys());
152
    }
153
154
    public function testPrimaryKeysAutoIncrement()
155
    {
156
        $this->assertCount(0, $this->baseEntity->primaryKeysAutoIncrement());
157
    }
158
159
    public function testColumns()
160
    {
161
        $this->assertCount(0, $this->baseEntity->columns());
162
    }
163
}
164