9
9
10
10
class RelatedUsersCollectionTest extends BaseTestCase
11
11
{
12
+ public function apply ($ func , array $ arr ): array
13
+ {
14
+ return array_map (function (array $ val ) use ($ func ) {
15
+ $ func ($ val );
16
+ return $ val ;
17
+ }, $ arr );
18
+ }
19
+
12
20
public function testAppendingWithSingleUser ()
13
21
{
14
22
$ collection = new RelatedUsersCollection ();
15
23
$ collection ->append ('user ' , 'relatedUser ' );
16
24
17
- $ this ->assertEquals ($ collection ->getAll () , [
25
+ $ this ->assertEquals ($ collection ->getAllApply ( ' sort ' ), $ this -> apply ( ' sort ' , [
18
26
'user ' => ['relatedUser ' ],
19
27
'relatedUser ' => ['user ' ],
20
- ]);
28
+ ])) ;
21
29
}
22
30
23
31
public function testAppendingWithMultipleUsers ()
@@ -27,12 +35,12 @@ public function testAppendingWithMultipleUsers()
27
35
$ collection ->append ('user ' , 'relatedUser2 ' );
28
36
$ collection ->append ('user ' , 'relatedUser3 ' );
29
37
30
- $ this ->assertEquals ($ collection ->getAll () , [
38
+ $ this ->assertEquals ($ collection ->getAllApply ( ' sort ' ), $ this -> apply ( ' sort ' , [
31
39
'user ' => ['relatedUser ' , 'relatedUser2 ' , 'relatedUser3 ' ],
32
40
'relatedUser ' => ['user ' , 'relatedUser2 ' , 'relatedUser3 ' ],
33
41
'relatedUser2 ' => ['user ' , 'relatedUser ' , 'relatedUser3 ' ],
34
42
'relatedUser3 ' => ['user ' , 'relatedUser ' , 'relatedUser2 ' ],
35
- ]);
43
+ ])) ;
36
44
}
37
45
38
46
public function testAppendingWithSameUsers ()
@@ -47,12 +55,12 @@ public function testAppendingWithSameUsers()
47
55
$ collection ->append ('relatedUser2 ' , 'relatedUser3 ' );
48
56
$ collection ->append ('relatedUser3 ' , 'relatedUser2 ' );
49
57
50
- $ this ->assertEquals ($ collection ->getAll () , [
58
+ $ this ->assertEquals ($ collection ->getAllApply ( ' sort ' ), $ this -> apply ( ' sort ' , [
51
59
'user ' => ['relatedUser ' , 'relatedUser2 ' , 'relatedUser3 ' ],
52
60
'relatedUser ' => ['user ' , 'relatedUser2 ' , 'relatedUser3 ' ],
53
61
'relatedUser2 ' => ['user ' , 'relatedUser ' , 'relatedUser3 ' ],
54
62
'relatedUser3 ' => ['user ' , 'relatedUser ' , 'relatedUser2 ' ],
55
- ]);
63
+ ])) ;
56
64
}
57
65
58
66
public function testAppendingViaChilds ()
@@ -63,12 +71,12 @@ public function testAppendingViaChilds()
63
71
$ collection ->append ('relatedUser2 ' , 'user ' );
64
72
$ collection ->append ('relatedUser3 ' , 'user ' );
65
73
66
- $ this ->assertEquals ($ collection ->getAll () , [
74
+ $ this ->assertEquals ($ collection ->getAllApply ( ' sort ' ), $ this -> apply ( ' sort ' , [
67
75
'user ' => ['relatedUser ' , 'relatedUser2 ' , 'relatedUser3 ' ],
68
76
'relatedUser ' => ['user ' , 'relatedUser2 ' , 'relatedUser3 ' ],
69
77
'relatedUser2 ' => ['user ' , 'relatedUser ' , 'relatedUser3 ' ],
70
78
'relatedUser3 ' => ['user ' , 'relatedUser ' , 'relatedUser2 ' ],
71
- ]);
79
+ ])) ;
72
80
}
73
81
74
82
public function testGettingForAppendingViaChilds ()
@@ -89,14 +97,23 @@ public function testGettingForAppendingViaChilds()
89
97
['user ' , 'relatedUser2 ' , 'relatedUser3 ' ]
90
98
);
91
99
100
+ $ exp = ['user ' , 'relatedUser ' , 'relatedUser3 ' ];
101
+ sort ($ exp );
102
+ $ val = $ collection ->getByUserId ('relatedUser2 ' );
103
+ sort ($ val );
92
104
$ this ->assertEquals (
93
- $ collection -> getByUserId ( ' relatedUser2 ' ) ,
94
- [ ' user ' , ' relatedUser ' , ' relatedUser3 ' ],
105
+ $ val ,
106
+ $ exp
95
107
);
96
108
109
+ $ val = $ collection ->getByUserId ('relatedUser3 ' );
110
+ $ exp = ['user ' , 'relatedUser ' , 'relatedUser2 ' ];
111
+ sort ($ val );
112
+ sort ($ exp );
113
+
97
114
$ this ->assertEquals (
98
- $ collection -> getByUserId ( ' relatedUser3 ' ) ,
99
- [ ' user ' , ' relatedUser ' , ' relatedUser2 ' ]
115
+ $ val ,
116
+ $ exp
100
117
);
101
118
}
102
119
@@ -112,7 +129,7 @@ public function testAppendingWithParallelRelatedUsers()
112
129
$ collection ->append ('user2 ' , 'user2Related2 ' );
113
130
$ collection ->append ('user2 ' , 'user2Related3 ' );
114
131
115
- $ this ->assertEquals ($ collection ->getAll () , [
132
+ $ this ->assertEquals ($ collection ->getAllApply ( ' sort ' ), $ this -> apply ( ' sort ' , [
116
133
'user ' => ['relatedUser ' , 'relatedUser2 ' , 'relatedUser3 ' ],
117
134
'relatedUser ' => ['user ' , 'relatedUser2 ' , 'relatedUser3 ' ],
118
135
'relatedUser2 ' => ['user ' , 'relatedUser ' , 'relatedUser3 ' ],
@@ -122,7 +139,7 @@ public function testAppendingWithParallelRelatedUsers()
122
139
'user2Related ' => ['user2 ' , 'user2Related2 ' , 'user2Related3 ' ],
123
140
'user2Related2 ' => ['user2 ' , 'user2Related ' , 'user2Related3 ' ],
124
141
'user2Related3 ' => ['user2 ' , 'user2Related ' , 'user2Related2 ' ],
125
- ]);
142
+ ])) ;
126
143
}
127
144
128
145
public function testAppendingWithParallelRelatedUsersMerge ()
@@ -140,7 +157,7 @@ public function testAppendingWithParallelRelatedUsersMerge()
140
157
$ collection ->append ('user ' , 'user2 ' );
141
158
142
159
143
- $ this ->assertEquals ($ collection ->getAll () , [
160
+ $ this ->assertEquals ($ collection ->getAllApply ( ' sort ' ), $ this -> apply ( ' sort ' , [
144
161
'user ' => [
145
162
'relatedUser ' ,
146
163
'relatedUser2 ' ,
@@ -214,7 +231,7 @@ public function testAppendingWithParallelRelatedUsersMerge()
214
231
'relatedUser2 ' ,
215
232
'relatedUser3 ' ,
216
233
],
217
- ]);
234
+ ])) ;
218
235
}
219
236
220
237
public function testAppendingWithParallelRelatedUsersMergeDirection2 ()
0 commit comments