Passed
Push — master ( d8a1be...a0c8b7 )
by Ion
02:39
created

BaseModelTest::testGetOriginal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 1
eloc 2
c 1
b 1
f 1
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace IonGhitun\MysqlEncryption\Tests\Models;
5
6
use IonGhitun\MysqlEncryption\Models\BaseModel;
7
use PHPUnit\Framework\TestCase;
8
use ReflectionClass;
9
10
/**
11
 * Class BaseModelTest
12
 *
13
 * @package IonGhitun\MysqlEncryption\Tests\Models
14
 */
15
class BaseModelTest extends TestCase
16
{
17
    /**
18
     * Test getAnonymizable
19
     */
20
    public function testGetAnonymizable()
21
    {
22
        $model = new BaseModel();
23
24
        $this->assertEquals([], $model->getAnonymizable());
25
    }
26
27
    /**
28
     * Test getEncrypted
29
     */
30
    public function testGetEncrypted()
31
    {
32
        $model = new BaseModel();
33
34
        $this->assertEquals([], $model->getEncrypted());
35
    }
36
37
    /**
38
     * Test getAttribute
39
     */
40
    public function tesBaseGetAttribute()
41
    {
42
        $model = new BaseModel();
43
44
        $model->name = 'Test';
1 ignored issue
show
Bug introduced by
The property name does not seem to exist on IonGhitun\MysqlEncryption\Models\BaseModel. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
45
46
        $this->assertEquals('Test', $model->name);
47
    }
48
49
    /**
50
     * Test getAttribute
51
     *
52
     * @throws \ReflectionException
53
     */
54
    public function testEncryptedGetAttribute()
55
    {
56
        $model = new BaseModel();
57
58
        $reflection = new ReflectionClass($model);
59
60
        $encrypted = $reflection->getProperty('encrypted');
61
        $encrypted->setAccessible(true);
62
63
        $encrypted->setValue($model, ['name']);
64
65
        $model->name = 'Test';
1 ignored issue
show
Bug introduced by
The property name does not seem to exist on IonGhitun\MysqlEncryption\Models\BaseModel. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
66
67
        $this->assertEquals('Test', $model->name);
68
    }
69
70
    /**
71
     * Test toArray
72
     */
73
    public function testToArray()
74
    {
75
        $model = new BaseModel();
76
77
        $model->name = 'Test';
1 ignored issue
show
Bug introduced by
The property name does not seem to exist on IonGhitun\MysqlEncryption\Models\BaseModel. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
78
79
        $this->assertEquals(['name' => 'Test'], $model->toArray());
80
    }
81
82
    /**
83
     * Test toArray
84
     *
85
     * @throws \ReflectionException
86
     */
87
    public function testEncryptedToArray()
88
    {
89
        $model = new BaseModel();
90
91
        $reflection = new ReflectionClass($model);
92
93
        $encrypted = $reflection->getProperty('encrypted');
94
        $encrypted->setAccessible(true);
95
96
        $encrypted->setValue($model, ['name']);
97
98
        $model->name = 'Test';
1 ignored issue
show
Bug introduced by
The property name does not seem to exist on IonGhitun\MysqlEncryption\Models\BaseModel. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
99
100
        $this->assertEquals(['name' => 'Test'], $model->toArray());
101
    }
102
103
    /**
104
     * Test getOriginal
105
     */
106
    public function testGetOriginal()
107
    {
108
        $model = new BaseModel();
109
110
        $this->assertEquals([], $model->getOriginal());
111
    }
112
113
    /**
114
     * Test anonymize
115
     *
116
     * @throws \ReflectionException
117
     */
118
    public function testAnonymize()
119
    {
120
        $model = new BaseModel();
121
122
        $reflection = new ReflectionClass($model);
123
124
        $anonymize = $reflection->getProperty('anonymizable');
125
        $anonymize->setAccessible(true);
126
127
        $anonymize->setValue($model, ['name' => ['text'], 'gender' => ['shuffle', 'male', 'female']]);
128
129
        $attributes = $reflection->getProperty('attributes');
130
        $attributes->setAccessible(true);
131
132
        $attributes->setValue($model, ['name', 'gender']);
133
134
        $model->name = 'Test';
1 ignored issue
show
Bug introduced by
The property name does not seem to exist on IonGhitun\MysqlEncryption\Models\BaseModel. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
135
        $model->gender = 'male';
1 ignored issue
show
Bug introduced by
The property gender does not seem to exist on IonGhitun\MysqlEncryption\Models\BaseModel. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
136
137
        $model->anonymize();
138
139
        $this->assertNotEquals('Test', $model->name);
140
    }
141
}
142