|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Friends. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Christopher Lass <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
use Arubacao\Friends\FriendshipStatus; |
|
12
|
|
|
|
|
13
|
|
|
class FriendsTest extends AbstractTestCase |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
use \Illuminate\Foundation\Testing\DatabaseTransactions; |
|
16
|
|
|
// use \Illuminate\Foundation\Testing\DatabaseMigrations; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @test |
|
20
|
|
|
*/ |
|
21
|
|
|
public function a_user_can_send_a_user_a_friend_request() { |
|
22
|
|
|
$sender = factory(User::class)->create(); |
|
23
|
|
|
$recipient = factory(User::class)->create(); |
|
24
|
|
|
|
|
25
|
|
|
$bool = $sender->sendFriendRequestTo($recipient); |
|
26
|
|
|
|
|
27
|
|
|
$this->assertTrue($bool); |
|
28
|
|
|
$this->seeInDatabase('friends', [ |
|
29
|
|
|
'sender_id' => $sender->id, |
|
30
|
|
|
'recipient_id' => $recipient->id, |
|
31
|
|
|
'friendship_status' => FriendshipStatus::PENDING, |
|
32
|
|
|
]); |
|
33
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
34
|
|
|
'recipient_id' => $sender->id, |
|
35
|
|
|
'sender_id' => $recipient->id, |
|
36
|
|
|
'friendship_status' => FriendshipStatus::PENDING, |
|
37
|
|
|
]); |
|
38
|
|
|
$this->assertCount(1, $sender->any_friends()); |
|
39
|
|
|
$this->assertCount(1, $recipient->any_friends()); |
|
40
|
|
|
$this->assertTrue($recipient->hasPendingRequestFrom($sender)); |
|
41
|
|
|
$this->assertFalse($sender->hasPendingRequestFrom($recipient)); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @test |
|
46
|
|
|
*/ |
|
47
|
|
|
public function a_user_can_not_send_a_user_a_friend_request_to_himself() { |
|
48
|
|
|
$sender = factory(User::class)->create(); |
|
49
|
|
|
|
|
50
|
|
|
$bool = $sender->sendFriendRequestTo($sender); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertFalse($bool); |
|
53
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
54
|
|
|
'recipient_id' => $sender->id, |
|
55
|
|
|
]); |
|
56
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
57
|
|
|
'sender_id' => $sender->id, |
|
58
|
|
|
]); |
|
59
|
|
|
$this->assertCount(0, $sender->any_friends()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @test |
|
64
|
|
|
*/ |
|
65
|
|
|
public function a_user_can_only_send_one_friend_request_to_a_user() { |
|
66
|
|
|
$sender = factory(User::class)->create(); |
|
67
|
|
|
$recipient = factory(User::class)->create(); |
|
68
|
|
|
|
|
69
|
|
|
$true = $sender->sendFriendRequestTo($recipient); |
|
70
|
|
|
$false1 = $sender->sendFriendRequestTo($recipient); |
|
71
|
|
|
$false2 = $sender->sendFriendRequestTo($recipient); |
|
72
|
|
|
$false3 = $sender->sendFriendRequestTo($recipient); |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
$this->assertTrue($true); |
|
76
|
|
|
$this->assertFalse($false1); |
|
77
|
|
|
$this->assertFalse($false2); |
|
78
|
|
|
$this->assertFalse($false3); |
|
79
|
|
|
$this->seeInDatabase('friends', [ |
|
80
|
|
|
'sender_id' => $sender->id, |
|
81
|
|
|
'recipient_id' => $recipient->id, |
|
82
|
|
|
'friendship_status' => FriendshipStatus::PENDING, |
|
83
|
|
|
]); |
|
84
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
85
|
|
|
'recipient_id' => $sender->id, |
|
86
|
|
|
'sender_id' => $recipient->id, |
|
87
|
|
|
'friendship_status' => FriendshipStatus::PENDING, |
|
88
|
|
|
]); |
|
89
|
|
|
$this->assertCount(1, $sender->any_friends()); |
|
90
|
|
|
$this->assertCount(1, $recipient->any_friends()); |
|
91
|
|
|
$this->assertTrue($recipient->hasPendingRequestFrom($sender)); |
|
92
|
|
|
$this->assertFalse($sender->hasPendingRequestFrom($recipient)); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @test |
|
97
|
|
|
*/ |
|
98
|
|
|
public function a_user_can_not_send_a_new_friend_request_to_a_friend() { |
|
99
|
|
|
$sender = factory(User::class)->create(); |
|
100
|
|
|
$recipient = factory(User::class)->create(); |
|
101
|
|
|
|
|
102
|
|
|
$true1 = $sender->sendFriendRequestTo($recipient); |
|
103
|
|
|
$true2 = $recipient->acceptFriendRequestFrom($sender); |
|
104
|
|
|
$false = $sender->sendFriendRequestTo($recipient); |
|
105
|
|
|
|
|
106
|
|
|
$this->assertTrue($true1); |
|
107
|
|
|
$this->assertTrue($true2); |
|
108
|
|
|
$this->assertFalse($false); |
|
109
|
|
|
$this->seeInDatabase('friends', [ |
|
110
|
|
|
'sender_id' => $sender->id, |
|
111
|
|
|
'recipient_id' => $recipient->id, |
|
112
|
|
|
'friendship_status' => FriendshipStatus::ACCEPTED, |
|
113
|
|
|
]); |
|
114
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
115
|
|
|
'sender_id' => $sender->id, |
|
116
|
|
|
'recipient_id' => $recipient->id, |
|
117
|
|
|
'friendship_status' => FriendshipStatus::PENDING, |
|
118
|
|
|
]); |
|
119
|
|
|
$this->assertCount(1, $sender->any_friends()); |
|
120
|
|
|
$this->assertCount(1, $sender->friends()); |
|
121
|
|
|
$this->assertCount(1, $recipient->any_friends()); |
|
122
|
|
|
$this->assertCount(1, $recipient->friends()); |
|
123
|
|
|
$this->assertFalse($recipient->hasPendingRequestFrom($sender)); |
|
124
|
|
|
$this->assertFalse($sender->hasPendingRequestFrom($recipient)); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @test |
|
129
|
|
|
*/ |
|
130
|
|
|
public function a_user_can_not_send_a_new_friend_request_to_a_friend_2() { |
|
131
|
|
|
$sender = factory(User::class)->create(); |
|
132
|
|
|
$recipient = factory(User::class)->create(); |
|
133
|
|
|
|
|
134
|
|
|
$true1 = $sender->sendFriendRequestTo($recipient); |
|
135
|
|
|
$true2 = $recipient->acceptFriendRequestFrom($sender); |
|
136
|
|
|
$false = $recipient->sendFriendRequestTo($sender); |
|
137
|
|
|
|
|
138
|
|
|
$this->assertTrue($true1); |
|
139
|
|
|
$this->assertTrue($true2); |
|
140
|
|
|
$this->assertFalse($false); |
|
141
|
|
|
$this->seeInDatabase('friends', [ |
|
142
|
|
|
'sender_id' => $sender->id, |
|
143
|
|
|
'recipient_id' => $recipient->id, |
|
144
|
|
|
'friendship_status' => FriendshipStatus::ACCEPTED, |
|
145
|
|
|
]); |
|
146
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
147
|
|
|
'sender_id' => $sender->id, |
|
148
|
|
|
'recipient_id' => $recipient->id, |
|
149
|
|
|
'friendship_status' => FriendshipStatus::PENDING, |
|
150
|
|
|
]); |
|
151
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
152
|
|
|
'sender_id' => $recipient->id, |
|
153
|
|
|
'recipient_id' => $sender->id, |
|
154
|
|
|
'friendship_status' => FriendshipStatus::PENDING, |
|
155
|
|
|
]); |
|
156
|
|
|
$this->assertCount(1, $sender->any_friends()); |
|
157
|
|
|
$this->assertCount(1, $sender->friends()); |
|
158
|
|
|
$this->assertCount(1, $recipient->any_friends()); |
|
159
|
|
|
$this->assertCount(1, $recipient->friends()); |
|
160
|
|
|
$this->assertFalse($recipient->hasPendingRequestFrom($sender)); |
|
161
|
|
|
$this->assertFalse($sender->hasPendingRequestFrom($recipient)); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @test |
|
166
|
|
|
*/ |
|
167
|
|
|
public function a_user_can_delete_a_friend() { |
|
168
|
|
|
$sender = factory(User::class)->create(); |
|
169
|
|
|
$recipient = factory(User::class)->create(); |
|
170
|
|
|
|
|
171
|
|
|
$sender->sendFriendRequestTo($recipient); |
|
172
|
|
|
$recipient->acceptFriendRequestFrom($sender); |
|
173
|
|
|
$sender->deleteFriend($recipient); |
|
174
|
|
|
|
|
175
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
176
|
|
|
'sender_id' => $sender->id, |
|
177
|
|
|
]); |
|
178
|
|
|
$this->assertCount(0, $sender->any_friends()); |
|
179
|
|
|
$this->assertCount(0, $recipient->any_friends()); |
|
180
|
|
|
$this->assertFalse($recipient->isFriendWith($sender)); |
|
181
|
|
|
$this->assertFalse($sender->isFriendWith($recipient)); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @test |
|
186
|
|
|
*/ |
|
187
|
|
|
public function a_user_can_accept_a_friend_request() { |
|
188
|
|
|
$sender = factory(User::class)->create(); |
|
189
|
|
|
$recipient = factory(User::class)->create(); |
|
190
|
|
|
|
|
191
|
|
|
$sender->sendFriendRequestTo($recipient); |
|
192
|
|
|
$recipient->acceptFriendRequestFrom($sender); |
|
193
|
|
|
|
|
194
|
|
|
$this->seeInDatabase('friends', [ |
|
195
|
|
|
'sender_id' => $sender->id, |
|
196
|
|
|
'recipient_id' => $recipient->id, |
|
197
|
|
|
'friendship_status' => FriendshipStatus::ACCEPTED, |
|
198
|
|
|
]); |
|
199
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
200
|
|
|
'sender_id' => $sender->id, |
|
201
|
|
|
'recipient_id' => $recipient->id, |
|
202
|
|
|
'friendship_status' => FriendshipStatus::PENDING, |
|
203
|
|
|
]); |
|
204
|
|
|
|
|
205
|
|
|
$this->assertCount(1, $sender->friends()); |
|
206
|
|
|
$this->assertCount(1, $recipient->friends()); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* @test |
|
211
|
|
|
*/ |
|
212
|
|
|
public function a_user_is_friend_with_a_user_after_a_friend_request() { |
|
213
|
|
|
$sender = factory(User::class)->create(); |
|
214
|
|
|
$recipient = factory(User::class)->create(); |
|
215
|
|
|
|
|
216
|
|
|
$sender->sendFriendRequestTo($recipient); |
|
217
|
|
|
$recipient->sendFriendRequestTo($sender); |
|
218
|
|
|
|
|
219
|
|
|
$this->assertTrue($sender->isFriendWith($recipient)); |
|
220
|
|
|
$this->assertTrue($recipient->isFriendWith($sender)); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* @test |
|
225
|
|
|
*/ |
|
226
|
|
|
public function a_user_can_deny_a_friend_request() { |
|
227
|
|
|
$sender = factory(User::class)->create(); |
|
228
|
|
|
$recipient = factory(User::class)->create(); |
|
229
|
|
|
|
|
230
|
|
|
$sender->sendFriendRequestTo($recipient); |
|
231
|
|
|
$recipient->denyFriendRequestFrom($sender); |
|
232
|
|
|
|
|
233
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
234
|
|
|
'sender_id' => $sender->id, |
|
235
|
|
|
]); |
|
236
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
237
|
|
|
'recipient_id' => $recipient->id, |
|
238
|
|
|
]); |
|
239
|
|
|
|
|
240
|
|
|
$this->assertCount(0, $sender->any_friends()); |
|
241
|
|
|
$this->assertCount(0, $recipient->any_friends()); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* @test |
|
246
|
|
|
*/ |
|
247
|
|
|
public function a_user_can_not_accept_a_non_existing_friend_request() { |
|
248
|
|
|
$sender = factory(User::class)->create(); |
|
249
|
|
|
$recipient = factory(User::class)->create(); |
|
250
|
|
|
|
|
251
|
|
|
$bool = $recipient->acceptFriendRequestFrom($sender); |
|
252
|
|
|
|
|
253
|
|
|
$this->assertFalse($bool); |
|
254
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
255
|
|
|
'sender_id' => $recipient->id, |
|
256
|
|
|
'recipient_id' => $sender->id, |
|
257
|
|
|
]); |
|
258
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
259
|
|
|
'sender_id' => $sender->id, |
|
260
|
|
|
'recipient_id' => $recipient->id, |
|
261
|
|
|
]); |
|
262
|
|
|
|
|
263
|
|
|
$this->assertCount(0, $sender->friends()); |
|
264
|
|
|
$this->assertCount(0, $recipient->friends()); |
|
265
|
|
|
$this->assertCount(0, $sender->any_friends()); |
|
266
|
|
|
$this->assertCount(0, $recipient->any_friends()); |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* @test |
|
271
|
|
|
*/ |
|
272
|
|
|
public function a_friend_request_results_in_a_accepted_if_pending_request_is_available_from_recipient() { |
|
273
|
|
|
$sender = factory(User::class)->create(); |
|
274
|
|
|
$recipient = factory(User::class)->create(); |
|
275
|
|
|
|
|
276
|
|
|
$sender->sendFriendRequestTo($recipient); |
|
277
|
|
|
$recipient->sendFriendRequestTo($sender); |
|
278
|
|
|
|
|
279
|
|
|
$this->seeInDatabase('friends', [ |
|
280
|
|
|
'sender_id' => $sender->id, |
|
281
|
|
|
'recipient_id' => $recipient->id, |
|
282
|
|
|
'friendship_status' => FriendshipStatus::ACCEPTED, |
|
283
|
|
|
]); |
|
284
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
285
|
|
|
'sender_id' => $sender->id, |
|
286
|
|
|
'recipient_id' => $recipient->id, |
|
287
|
|
|
'friendship_status' => FriendshipStatus::PENDING, |
|
288
|
|
|
]); |
|
289
|
|
|
$this->dontSeeInDatabase('friends', [ |
|
290
|
|
|
'sender_id' => $recipient->id, |
|
291
|
|
|
'recipient_id' => $sender->id, |
|
292
|
|
|
'friendship_status' => FriendshipStatus::PENDING, |
|
293
|
|
|
]); |
|
294
|
|
|
|
|
295
|
|
|
$this->assertCount(1, $sender->friends()); |
|
296
|
|
|
$this->assertCount(1, $recipient->friends()); |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
/** |
|
300
|
|
|
* @test |
|
301
|
|
|
*/ |
|
302
|
|
|
public function friends_method_returns_empty_array_after_friend_request() { |
|
303
|
|
|
$sender = factory(User::class)->create(); |
|
304
|
|
|
$recipient = factory(User::class)->create(); |
|
305
|
|
|
|
|
306
|
|
|
$sender->sendFriendRequestTo($recipient); |
|
307
|
|
|
|
|
308
|
|
|
$this->assertCount(0, $sender->friends()); |
|
309
|
|
|
$this->assertCount(0, $recipient->friends()); |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* @test |
|
314
|
|
|
*/ |
|
315
|
|
|
public function friends_method_returns_correct_count_of_friends__2_requests_and_2_accepts() { |
|
316
|
|
|
$sender = factory(User::class)->create(); |
|
317
|
|
|
$recipient1 = factory(User::class)->create(); |
|
318
|
|
|
$recipient2 = factory(User::class)->create(); |
|
319
|
|
|
|
|
320
|
|
|
$sender->sendFriendRequestTo($recipient1); |
|
321
|
|
|
$sender->sendFriendRequestTo($recipient2); |
|
322
|
|
|
$recipient1->acceptFriendRequestFrom($sender); |
|
323
|
|
|
$recipient2->acceptFriendRequestFrom($sender); |
|
324
|
|
|
|
|
325
|
|
|
$this->seeInDatabase('friends', [ |
|
326
|
|
|
'sender_id' => $sender->id, |
|
327
|
|
|
'recipient_id' => $recipient1->id, |
|
328
|
|
|
'friendship_status' => FriendshipStatus::ACCEPTED, |
|
329
|
|
|
]); |
|
330
|
|
|
$this->seeInDatabase('friends', [ |
|
331
|
|
|
'sender_id' => $sender->id, |
|
332
|
|
|
'recipient_id' => $recipient2->id, |
|
333
|
|
|
'friendship_status' => FriendshipStatus::ACCEPTED, |
|
334
|
|
|
]); |
|
335
|
|
|
$this->assertCount(2, $sender->friends()); |
|
336
|
|
|
$this->assertCount(1, $recipient1->friends()); |
|
337
|
|
|
$this->assertCount(1, $recipient2->friends()); |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* @test |
|
342
|
|
|
*/ |
|
343
|
|
|
public function friends_method_returns_correct_count_of_friends__50_requests_and_50_accepts() { |
|
344
|
|
|
$sender = factory(User::class)->create(); |
|
345
|
|
|
$recipients = factory(User::class)->times(50)->create(); |
|
346
|
|
|
|
|
347
|
|
|
foreach ($recipients as $recipient) { |
|
|
|
|
|
|
348
|
|
|
$sender->sendFriendRequestTo($recipient); |
|
349
|
|
|
$recipient->acceptFriendRequestFrom($sender); |
|
350
|
|
|
$this->assertCount(1, $recipient->friends()); |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
$this->assertCount(50, $sender->friends()); |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
/** |
|
357
|
|
|
* @test |
|
358
|
|
|
*/ |
|
359
|
|
|
public function friends_method_returns_correct_count_of_friends__50_requests_and_25_accepts() { |
|
360
|
|
|
$sender = factory(User::class)->create(); |
|
361
|
|
|
$recipients = factory(User::class)->times(50)->create(); |
|
362
|
|
|
|
|
363
|
|
|
foreach ($recipients as $key => $recipient) { |
|
|
|
|
|
|
364
|
|
|
$sender->sendFriendRequestTo($recipient); |
|
365
|
|
|
if ($key % 2) { |
|
366
|
|
|
$recipient->acceptFriendRequestFrom($sender); |
|
367
|
|
|
$this->assertCount(1, $recipient->friends()); |
|
368
|
|
|
continue; |
|
369
|
|
|
} |
|
370
|
|
|
$this->assertCount(0, $recipient->friends()); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
$this->assertCount(25, $sender->friends()); |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
/** |
|
377
|
|
|
* @test |
|
378
|
|
|
*/ |
|
379
|
|
|
public function friends_method_returns_correct_friends__2_requests_and_2_accepts() { |
|
380
|
|
|
$sender = factory(User::class)->create(); |
|
381
|
|
|
$recipient0 = factory(User::class)->create(); |
|
382
|
|
|
$recipient1 = factory(User::class)->create(); |
|
383
|
|
|
|
|
384
|
|
|
$sender->sendFriendRequestTo($recipient0); |
|
385
|
|
|
$sender->sendFriendRequestTo($recipient1); |
|
386
|
|
|
$recipient0->acceptFriendRequestFrom($sender); |
|
387
|
|
|
$recipient1->acceptFriendRequestFrom($sender); |
|
388
|
|
|
|
|
389
|
|
|
$this->seeInDatabase('friends', [ |
|
390
|
|
|
'sender_id' => $sender->id, |
|
391
|
|
|
'recipient_id' => $recipient0->id, |
|
392
|
|
|
'friendship_status' => FriendshipStatus::ACCEPTED, |
|
393
|
|
|
]); |
|
394
|
|
|
$this->seeInDatabase('friends', [ |
|
395
|
|
|
'sender_id' => $sender->id, |
|
396
|
|
|
'recipient_id' => $recipient1->id, |
|
397
|
|
|
'friendship_status' => FriendshipStatus::ACCEPTED, |
|
398
|
|
|
]); |
|
399
|
|
|
$friends = $sender->friends(); |
|
400
|
|
|
$this->assertEquals($recipient0->id, $friends[0]->id); |
|
401
|
|
|
$this->assertEquals($recipient1->id, $friends[1]->id); |
|
402
|
|
|
} |
|
403
|
|
|
|
|
404
|
|
|
/** |
|
405
|
|
|
* @test |
|
406
|
|
|
*/ |
|
407
|
|
|
public function any_friends_method_returns_1_user_after_friend_request() { |
|
408
|
|
|
$sender = factory(User::class)->create(); |
|
409
|
|
|
$recipient = factory(User::class)->create(); |
|
410
|
|
|
|
|
411
|
|
|
$sender->sendFriendRequestTo($recipient); |
|
412
|
|
|
|
|
413
|
|
|
$this->assertCount(1, $sender->any_friends()); |
|
414
|
|
|
$this->assertCount(1, $recipient->any_friends()); |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
/** |
|
418
|
|
|
* @test |
|
419
|
|
|
*/ |
|
420
|
|
|
public function any_friends_method_returns_correct_count_of_any_friends__50_requests_and_25_accepts() { |
|
421
|
|
|
$sender = factory(User::class)->create(); |
|
422
|
|
|
$recipients = factory(User::class)->times(50)->create(); |
|
423
|
|
|
|
|
424
|
|
|
foreach ($recipients as $key => $recipient) { |
|
|
|
|
|
|
425
|
|
|
$sender->sendFriendRequestTo($recipient); |
|
426
|
|
|
if ($key % 2) { |
|
427
|
|
|
$recipient->acceptFriendRequestFrom($sender); |
|
428
|
|
|
$this->assertCount(1, $recipient->any_friends()); |
|
429
|
|
|
continue; |
|
430
|
|
|
} |
|
431
|
|
|
$this->assertCount(1, $recipient->any_friends()); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
$this->assertCount(50, $sender->any_friends()); |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
/** |
|
438
|
|
|
* @test |
|
439
|
|
|
*/ |
|
440
|
|
|
public function any_friends_method_returns_correct_count_of_any_friends__50_requests_and_25_accepts_25_denies() { |
|
441
|
|
|
$sender = factory(User::class)->create(); |
|
442
|
|
|
$recipients = factory(User::class)->times(50)->create(); |
|
443
|
|
|
|
|
444
|
|
|
foreach ($recipients as $key => $recipient) { |
|
|
|
|
|
|
445
|
|
|
$sender->sendFriendRequestTo($recipient); |
|
446
|
|
|
if ($key % 2) { |
|
447
|
|
|
$recipient->acceptFriendRequestFrom($sender); |
|
448
|
|
|
$this->assertCount(1, $recipient->any_friends()); |
|
449
|
|
|
continue; |
|
450
|
|
|
} |
|
451
|
|
|
$recipient->denyFriendRequestFrom($sender); |
|
452
|
|
|
$this->assertCount(0, $recipient->any_friends()); |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
$this->assertCount(25, $sender->any_friends()); |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
/** |
|
459
|
|
|
* @test |
|
460
|
|
|
*/ |
|
461
|
|
|
public function incoming_friends_method_returns_1_user_after_friend_request() { |
|
462
|
|
|
$sender = factory(User::class)->create(); |
|
463
|
|
|
$recipient = factory(User::class)->create(); |
|
464
|
|
|
|
|
465
|
|
|
$sender->sendFriendRequestTo($recipient); |
|
466
|
|
|
|
|
467
|
|
|
$this->assertCount(0, $sender->incoming_friends()); |
|
468
|
|
|
$this->assertCount(1, $recipient->incoming_friends()); |
|
469
|
|
|
} |
|
470
|
|
|
|
|
471
|
|
|
/** |
|
472
|
|
|
* @test |
|
473
|
|
|
*/ |
|
474
|
|
|
public function incoming_friends_method_returns_correct_count_of_any_friends__50_requests_and_25_accepts() { |
|
475
|
|
|
$recipient = factory(User::class)->create(); |
|
476
|
|
|
$senders = factory(User::class)->times(50)->create(); |
|
477
|
|
|
|
|
478
|
|
|
foreach ($senders as $key => $sender) { |
|
|
|
|
|
|
479
|
|
|
$sender->sendFriendRequestTo($recipient); |
|
480
|
|
|
if ($key % 2) { |
|
481
|
|
|
$recipient->acceptFriendRequestFrom($sender); |
|
482
|
|
|
continue; |
|
483
|
|
|
} |
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
|
|
$this->assertCount(25, $recipient->incoming_friends()); |
|
487
|
|
|
} |
|
488
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.