ObjectHelperTest::testPrefixTreeFromArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace BWC\Share\Tests\Object;
4
5
use BWC\Share\Object\ObjectHelper;
6
7
class ObjectHelperTest extends \PHPUnit_Framework_TestCase
8
{
9
    function testSimpleFromArray() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
10
        $from = array(
11
            'id' => 1,
12
            'name' => 'name',
13
            'email' => 'email'
14
        );
15
        $user = new User();
16
        ObjectHelper::copyExistingProperties($from, $user);
17
        $this->assertEquals($from['id'], $user->id);
18
        $this->assertEquals($from['name'], $user->name);
19
        $this->assertEquals($from['email'], $user->email);
20
    }
21
22
23
    function testSimpleFromObject() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
24
        $from = (object)array(
25
            'id' => 1,
26
            'name' => 'name',
27
            'email' => 'email'
28
        );
29
        $user = new User();
30
        ObjectHelper::copyExistingProperties($from, $user);
31
        $this->assertEquals($from->id, $user->id);
32
        $this->assertEquals($from->name, $user->name);
33
        $this->assertEquals($from->email, $user->email);
34
    }
35
36
37
    function testPrefixOneFromArray() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
38
        $from = array(
39
            'id' => 1,
40
            'name' => 'name',
41
            'email' => 'email',
42
            'g_id' => 2,
43
            'g_name' => 'group_name'
44
        );
45
        $user = new User();
46
        $group = new Group();
47
        ObjectHelper::copyExistingProperties($from, $user);
48
        ObjectHelper::copyExistingProperties($from, $group, 'g_');
49
        $this->assertEquals($from['id'], $user->id);
50
        $this->assertEquals($from['name'], $user->name);
51
        $this->assertEquals($from['email'], $user->email);
52
        $this->assertEquals($from['g_id'], $group->id);
53
        $this->assertEquals($from['g_name'], $group->name);
54
    }
55
56
    function testPrefixBothFromArray() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
57
        $from = array(
58
            'u_id' => 1,
59
            'u_name' => 'name',
60
            'u_email' => 'email',
61
            'g_id' => 2,
62
            'g_name' => 'group_name'
63
        );
64
        $user = new User();
65
        $group = new Group();
66
        ObjectHelper::copyExistingProperties($from, $user, 'u_');
67
        ObjectHelper::copyExistingProperties($from, $group, 'g_');
68
        $this->assertEquals($from['u_id'], $user->id);
69
        $this->assertEquals($from['u_name'], $user->name);
70
        $this->assertEquals($from['u_email'], $user->email);
71
        $this->assertEquals($from['g_id'], $group->id);
72
        $this->assertEquals($from['g_name'], $group->name);
73
    }
74
75
76
    function testPrefixOneFromObject() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
77
        $from = (object)array(
78
            'id' => 1,
79
            'name' => 'name',
80
            'email' => 'email',
81
            'g_id' => 2,
82
            'g_name' => 'group_name'
83
        );
84
        $user = new User();
85
        $group = new Group();
86
        ObjectHelper::copyExistingProperties($from, $user);
87
        ObjectHelper::copyExistingProperties($from, $group, 'g_');
88
        $this->assertEquals($from->id, $user->id);
89
        $this->assertEquals($from->name, $user->name);
90
        $this->assertEquals($from->email, $user->email);
91
        $this->assertEquals($from->g_id, $group->id);
92
        $this->assertEquals($from->g_name, $group->name);
93
    }
94
95
    function testPrefixBothFromObject() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
96
        $from = (object)array(
97
            'u_id' => 1,
98
            'u_name' => 'name',
99
            'u_email' => 'email',
100
            'g_id' => 2,
101
            'g_name' => 'group_name'
102
        );
103
        $user = new User();
104
        $group = new Group();
105
        ObjectHelper::copyExistingProperties($from, $user, 'u_');
106
        ObjectHelper::copyExistingProperties($from, $group, 'g_');
107
        $this->assertEquals($from->u_id, $user->id);
108
        $this->assertEquals($from->u_name, $user->name);
109
        $this->assertEquals($from->u_email, $user->email);
110
        $this->assertEquals($from->g_id, $group->id);
111
        $this->assertEquals($from->g_name, $group->name);
112
    }
113
114
    function testPrefixTreeFromArray() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
115
        $from = array(
116
            'id' => 1,
117
            'name' => 'name',
118
            'email' => 'email',
119
            'g_id' => 2,
120
            'g_name' => 'group_name',
121
            'r_id' => 3,
122
            'r_name' => 'role_name'
123
        );
124
        $user = new User();
125
        $group = new Group();
126
        $role = new Role();
127
        ObjectHelper::copyExistingProperties($from, $user);
128
        ObjectHelper::copyExistingProperties($from, $group, 'g_');
129
        ObjectHelper::copyExistingProperties($from, $role, 'r_');
130
        $this->assertEquals($from['id'], $user->id);
131
        $this->assertEquals($from['name'], $user->name);
132
        $this->assertEquals($from['email'], $user->email);
133
        $this->assertEquals($from['g_id'], $group->id);
134
        $this->assertEquals($from['g_name'], $group->name);
135
        $this->assertEquals($from['r_id'], $role->id);
136
        $this->assertEquals($from['r_name'], $role->name);
137
    }
138
139
    function testPrefixTreeFromObject() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
140
        $from = (object)array(
141
            'id' => 1,
142
            'name' => 'name',
143
            'email' => 'email',
144
            'g_id' => 2,
145
            'g_name' => 'group_name',
146
            'r_id' => 3,
147
            'r_name' => 'role_name'
148
        );
149
        $user = new User();
150
        $group = new Group();
151
        $role = new Role();
152
        ObjectHelper::copyExistingProperties($from, $user);
153
        ObjectHelper::copyExistingProperties($from, $group, 'g_');
154
        ObjectHelper::copyExistingProperties($from, $role, 'r_');
155
        $this->assertEquals($from->id, $user->id);
156
        $this->assertEquals($from->name, $user->name);
157
        $this->assertEquals($from->email, $user->email);
158
        $this->assertEquals($from->g_id, $group->id);
159
        $this->assertEquals($from->g_name, $group->name);
160
        $this->assertEquals($from->r_id, $role->id);
161
        $this->assertEquals($from->r_name, $role->name);
162
    }
163
164
}