Completed
Pull Request — master (#173)
by Corey
02:55
created

UserTest   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 922
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 16
eloc 643
dl 0
loc 922
rs 9.957
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetIdHash() 0 9 1
A testGenerateVerifyEmailToken() 0 4 1
A setUp() 0 42 1
A testSendEmailReport() 0 24 1
A testConfirmVerifyEmailToken() 0 4 1
A testIsVerified() 0 7 1
A testGenerateChangeEmailToken() 0 4 1
A testIsTokenCurrent() 0 11 1
A testRemoveVerifyEmailToken() 0 4 1
A testCleanExportData() 0 46 1
A tearDown() 0 3 1
A testRemoveChangeEmailToken() 0 4 1
A testParseBehaviorData() 0 4 1
A testIsTokenConfirmed() 0 4 1
A testGeneratePasswordResetToken() 0 4 1
A testParseQuestionData() 0 4 1
1
<?php
2
3
namespace common\unit\models;
4
5
use Yii;
6
use Codeception\Specify;
7
use common\models\User;
8
9
date_default_timezone_set('UTC');
10
11
/**
12
 * User test
13
 */
14
15
class UserTest extends \Codeception\Test\Unit {
16
  use Specify;
17
18
  private $user;
19
  private $time;
20
  private $question;
21
22
	public $questionData = [
23
	[
24
		'id' => 641,
25
		'user_id' => 2,
26
		'behavior_id' => 13,
27
		'user_behavior_id' => 821,
28
		'question' => 1,
29
		'answer' => 'alsgn',
30
		'date' => '2016-09-10 19:27:43',
31
		'behavior' => 
32
		[
33
			'id' => 13,
34
			'name' => 'less time/energy for God, meetings, and church',
35
			'category_id' => 2,
36
		],
37
	],
38
	[
39
		'id' => 642,
40
		'user_id' => 2,
41
		'behavior_id' => 13,
42
		'user_behavior_id' => 821,
43
		'question' => 2,
44
		'answer' => 'loiun',
45
		'date' => '2016-09-10 19:27:43',
46
		'behavior' => 
47
		[
48
			'id' => 13,
49
			'name' => 'less time/energy for God, meetings, and church',
50
			'category_id' => 2,
51
		],
52
	],
53
	[
54
		'id' => 643,
55
		'user_id' => 2,
56
		'behavior_id' => 13,
57
		'user_behavior_id' => 821,
58
		'question' => 3,
59
		'answer' => 'liun',
60
		'date' => '2016-09-10 19:27:43',
61
		'behavior' => 
62
		[
63
			'id' => 13,
64
			'name' => 'less time/energy for God, meetings, and church',
65
			'category_id' => 2,
66
		],
67
	],
68
	[
69
		'id' => 644,
70
		'user_id' => 2,
71
		'behavior_id' => 29,
72
		'user_behavior_id' => 823,
73
		'question' => 1,
74
		'answer' => 'ljnb',
75
		'date' => '2016-09-10 19:27:43',
76
		'behavior' => 
77
		[
78
			'id' => 29,
79
			'name' => 'using profanity',
80
			'category_id' => 3,
81
		],
82
	],
83
	[
84
		'id' => 645,
85
		'user_id' => 2,
86
		'behavior_id' => 29,
87
		'user_behavior_id' => 823,
88
		'question' => 2,
89
		'answer' => 'liunb',
90
		'date' => '2016-09-10 19:27:43',
91
		'behavior' => 
92
		[
93
			'id' => 29,
94
			'name' => 'using profanity',
95
			'category_id' => 3,
96
		],
97
	],
98
	[
99
		'id' => 646,
100
		'user_id' => 2,
101
		'behavior_id' => 29,
102
		'user_behavior_id' => 823,
103
		'question' => 3,
104
		'answer' => 'ilub ',
105
		'date' => '2016-09-10 19:27:43',
106
		'behavior' => 
107
		[
108
			'id' => 29,
109
			'name' => 'using profanity',
110
			'category_id' => 3,
111
		],
112
	],
113
	[
114
		'id' => 647,
115
		'user_id' => 2,
116
		'behavior_id' => 48,
117
		'user_behavior_id' => 825,
118
		'question' => 1,
119
		'answer' => 'liub',
120
		'date' => '2016-09-10 19:27:43',
121
		'behavior' => 
122
		[
123
			'id' => 48,
124
			'name' => 'workaholic',
125
			'category_id' => 4,
126
		],
127
	],
128
	[
129
		'id' => 648,
130
		'user_id' => 2,
131
		'behavior_id' => 48,
132
		'user_behavior_id' => 825,
133
		'question' => 2,
134
		'answer' => 'liub',
135
		'date' => '2016-09-10 19:27:43',
136
		'behavior' => 
137
		[
138
			'id' => 48,
139
			'name' => 'workaholic',
140
			'category_id' => 4,
141
		],
142
	],
143
	[
144
		'id' => 649,
145
		'user_id' => 2,
146
		'behavior_id' => 48,
147
		'user_behavior_id' => 825,
148
		'question' => 3,
149
		'answer' => 'liub ',
150
		'date' => '2016-09-10 19:27:43',
151
		'behavior' => 
152
		[
153
			'id' => 48,
154
			'name' => 'workaholic',
155
			'category_id' => 4,
156
		],
157
	],
158
	[
159
		'id' => 650,
160
		'user_id' => 2,
161
		'behavior_id' => 89,
162
		'user_behavior_id' => 828,
163
		'question' => 1,
164
		'answer' => 'liub',
165
		'date' => '2016-09-10 19:27:43',
166
		'behavior' => 
167
		[
168
			'id' => 89,
169
			'name' => 'obsessive (stuck) thoughts',
170
			'category_id' => 5,
171
		],
172
	],
173
	[
174
		'id' => 651,
175
		'user_id' => 2,
176
		'behavior_id' => 89,
177
		'user_behavior_id' => 828,
178
		'question' => 2,
179
		'answer' => 'liuby',
180
		'date' => '2016-09-10 19:27:43',
181
		'behavior' => 
182
		[
183
			'id' => 89,
184
			'name' => 'obsessive (stuck) thoughts',
185
			'category_id' => 5,
186
		],
187
	],
188
	[
189
		'id' => 652,
190
		'user_id' => 2,
191
		'behavior_id' => 89,
192
		'user_behavior_id' => 828,
193
		'question' => 3,
194
		'answer' => 'uiylb',
195
		'date' => '2016-09-10 19:27:43',
196
		'behavior' => 
197
		[
198
			'id' => 89,
199
			'name' => 'obsessive (stuck) thoughts',
200
			'category_id' => 5,
201
		],
202
	],
203
	[
204
		'id' => 653,
205
		'user_id' => 2,
206
		'behavior_id' => 111,
207
		'user_behavior_id' => 829,
208
		'question' => 1,
209
		'answer' => 'liub',
210
		'date' => '2016-09-10 19:27:43',
211
		'behavior' => 
212
		[
213
			'id' => 111,
214
			'name' => 'seeking out old unhealthy people and places',
215
			'category_id' => 6,
216
		],
217
	],
218
	[
219
		'id' => 654,
220
		'user_id' => 2,
221
		'behavior_id' => 111,
222
		'user_behavior_id' => 829,
223
		'question' => 2,
224
		'answer' => 'liuyb',
225
		'date' => '2016-09-10 19:27:43',
226
		'behavior' => 
227
		[
228
			'id' => 111,
229
			'name' => 'seeking out old unhealthy people and places',
230
			'category_id' => 6,
231
		],
232
	],
233
	[
234
		'id' => 655,
235
		'user_id' => 2,
236
		'behavior_id' => 111,
237
		'user_behavior_id' => 829,
238
		'question' => 3,
239
		'answer' => 'iuyb',
240
		'date' => '2016-09-10 19:27:43',
241
		'behavior' => 
242
		[
243
			'id' => 111,
244
			'name' => 'seeking out old unhealthy people and places',
245
			'category_id' => 6,
246
		],
247
	],
248
	[
249
		'id' => 656,
250
		'user_id' => 2,
251
		'behavior_id' => 122,
252
		'user_behavior_id' => 831,
253
		'question' => 1,
254
		'answer' => 'iuyb',
255
		'date' => '2016-09-10 19:27:43',
256
		'behavior' => 
257
		[
258
			'id' => 122,
259
			'name' => 'returning to the place you swore you would never go again',
260
			'category_id' => 7,
261
		],
262
	],
263
	[
264
		'id' => 657,
265
		'user_id' => 2,
266
		'behavior_id' => 122,
267
		'user_behavior_id' => 831,
268
		'question' => 2,
269
		'answer' => 'iuyb',
270
		'date' => '2016-09-10 19:27:43',
271
		'behavior' => 
272
		[
273
			'id' => 122,
274
			'name' => 'returning to the place you swore you would never go again',
275
			'category_id' => 7,
276
		],
277
	],
278
	[
279
		'id' => 658,
280
		'user_id' => 2,
281
		'behavior_id' => 122,
282
		'user_behavior_id' => 831,
283
		'question' => 3,
284
		'answer' => 'liuyb',
285
		'date' => '2016-09-10 19:27:43',
286
		'behavior' => 
287
		[
288
			'id' => 122,
289
			'name' => 'returning to the place you swore you would never go again',
290
			'category_id' => 7,
291
		],
292
	],
293
];
294
public $userQuestions = [
295
	13 => [
296
		'question' => [
297
			'id' => 13,
298
			'title' => 'less time/energy for God, meetings, and church',
299
		],
300
		'answers' => [
301
			[
302
				'title' => 'How does it affect me? How do I act and feel?',
303
				'answer' => 'alsgn',
304
			], [
305
				'title' => 'How does it affect the important people in my life?',
306
				'answer' => 'loiun',
307
			], [
308
				'title' => 'Why do I do this? What is the benefit for me?',
309
				'answer' => 'liun',
310
			],
311
		],
312
	],
313
	29 => [
314
		'question' => [
315
			'id' => 29,
316
			'title' => 'using profanity',
317
		],
318
		'answers' => [
319
			[
320
				'title' => 'How does it affect me? How do I act and feel?',
321
				'answer' => 'ljnb',
322
			], [
323
				'title' => 'How does it affect the important people in my life?',
324
				'answer' => 'liunb',
325
			], [
326
				'title' => 'Why do I do this? What is the benefit for me?',
327
				'answer' => 'ilub ',
328
			],
329
		],
330
	],
331
	48 => [
332
		'question' => [
333
			'id' => 48,
334
			'title' => 'workaholic',
335
		],
336
		'answers' => [
337
			[
338
				'title' => 'How does it affect me? How do I act and feel?',
339
				'answer' => 'liub',
340
			], [
341
				'title' => 'How does it affect the important people in my life?',
342
				'answer' => 'liub',
343
			], [
344
				'title' => 'Why do I do this? What is the benefit for me?',
345
				'answer' => 'liub ',
346
			],
347
		],
348
	],
349
	89 => [
350
		'question' => [
351
			'id' => 89,
352
			'title' => 'obsessive (stuck) thoughts',
353
		],
354
		'answers' => [
355
			[
356
				'title' => 'How does it affect me? How do I act and feel?',
357
				'answer' => 'liub',
358
			], [
359
				'title' => 'How does it affect the important people in my life?',
360
				'answer' => 'liuby',
361
			], [
362
				'title' => 'Why do I do this? What is the benefit for me?',
363
				'answer' => 'uiylb',
364
			],
365
		],
366
	],
367
	111 => [
368
		'question' => [
369
			'id' => 111,
370
			'title' => 'seeking out old unhealthy people and places',
371
		],
372
		'answers' => [
373
			[
374
				'title' => 'How does it affect me? How do I act and feel?',
375
				'answer' => 'liub',
376
			], [
377
				'title' => 'How does it affect the important people in my life?',
378
				'answer' => 'liuyb',
379
			], [
380
				'title' => 'Why do I do this? What is the benefit for me?',
381
				'answer' => 'iuyb',
382
			],
383
		],
384
	],
385
	122 => [
386
		'question' => [
387
			'id' => 122,
388
			'title' => 'returning to the place you swore you would never go again',
389
		],
390
		'answers' => [
391
			[
392
				'title' => 'How does it affect me? How do I act and feel?',
393
				'answer' => 'iuyb',
394
			], [
395
				'title' => 'How does it affect the important people in my life?',
396
				'answer' => 'iuyb',
397
			], [
398
				'title' => 'Why do I do this? What is the benefit for me?',
399
				'answer' => 'liuyb',
400
			],
401
		],
402
	],
403
];
404
405
public $behaviorData = [
406
	[
407
		'id' => 820,
408
		'user_id' => 2,
409
		'behavior_id' => 7,
410
		'date' => '2016-09-10 19:26:04',
411
		'behavior' => [
412
			'id' => 7,
413
			'name' => 'making eye contact',
414
			'category_id' => 1,
415
			'category' => [
416
				'id' => 1,
417
				'name' => 'Restoration',
418
			],
419
		],
420
	], [
421
		'id' => 821,
422
		'user_id' => 2,
423
		'behavior_id' => 13,
424
		'date' => '2016-09-10 19:26:04',
425
		'behavior' => [
426
			'id' => 13,
427
			'name' => 'less time/energy for God, meetings, and church',
428
			'category_id' => 2,
429
			'category' => [
430
				'id' => 2,
431
				'name' => 'Forgetting Priorities',
432
			],
433
		],
434
	], [
435
		'id' => 822,
436
		'user_id' => 2,
437
		'behavior_id' => 18,
438
		'date' => '2016-09-10 19:26:04',
439
		'behavior' => [
440
			'id' => 18,
441
			'name' => 'changes in goals',
442
			'category_id' => 2,
443
			'category' => [
444
				'id' => 2,
445
				'name' => 'Forgetting Priorities',
446
			],
447
		],
448
	], [
449
		'id' => 823,
450
		'user_id' => 2,
451
		'behavior_id' => 29,
452
		'date' => '2016-09-10 19:26:04',
453
		'behavior' => [
454
			'id' => 29,
455
			'name' => 'using profanity',
456
			'category_id' => 3,
457
			'category' => [
458
				'id' => 3,
459
				'name' => 'Anxiety',
460
			],
461
		],
462
	], [
463
		'id' => 824,
464
		'user_id' => 2,
465
		'behavior_id' => 41,
466
		'date' => '2016-09-10 19:26:04',
467
		'behavior' => [
468
			'id' => 41,
469
			'name' => 'co-dependent rescuing',
470
			'category_id' => 3,
471
			'category' => [
472
				'id' => 3,
473
				'name' => 'Anxiety',
474
			],
475
		],
476
	], [
477
		'id' => 825,
478
		'user_id' => 2,
479
		'behavior_id' => 48,
480
		'date' => '2016-09-10 19:26:04',
481
		'behavior' => [
482
			'id' => 48,
483
			'name' => 'workaholic',
484
			'category_id' => 4,
485
			'category' => [
486
				'id' => 4,
487
				'name' => 'Speeding Up',
488
			],
489
		],
490
	], [
491
		'id' => 826,
492
		'user_id' => 2,
493
		'behavior_id' => 72,
494
		'date' => '2016-09-10 19:26:04',
495
		'behavior' => [
496
			'id' => 72,
497
			'name' => 'black and white, all or nothing thinking',
498
			'category_id' => 5,
499
			'category' => [
500
				'id' => 5,
501
				'name' => 'Ticked Off',
502
			],
503
		],
504
	], [
505
		'id' => 827,
506
		'user_id' => 2,
507
		'behavior_id' => 79,
508
		'date' => '2016-09-10 19:26:04',
509
		'behavior' => [
510
			'id' => 79,
511
			'name' => 'blaming',
512
			'category_id' => 5,
513
			'category' => [
514
				'id' => 5,
515
				'name' => 'Ticked Off',
516
			],
517
		],
518
	], [
519
		'id' => 828,
520
		'user_id' => 2,
521
		'behavior_id' => 89,
522
		'date' => '2016-09-10 19:26:04',
523
		'behavior' => [
524
			'id' => 89,
525
			'name' => 'obsessive (stuck) thoughts',
526
			'category_id' => 5,
527
			'category' => [
528
				'id' => 5,
529
				'name' => 'Ticked Off',
530
			],
531
		],
532
	], [
533
		'id' => 829,
534
		'user_id' => 2,
535
		'behavior_id' => 111,
536
		'date' => '2016-09-10 19:26:04',
537
		'behavior' => [
538
			'id' => 111,
539
			'name' => 'seeking out old unhealthy people and places',
540
			'category_id' => 6,
541
			'category' => [
542
				'id' => 6,
543
				'name' => 'Exhausted',
544
			],
545
		],
546
	], [
547
		'id' => 830,
548
		'user_id' => 2,
549
		'behavior_id' => 118,
550
		'date' => '2016-09-10 19:26:04',
551
		'behavior' => [
552
			'id' => 118,
553
			'name' => 'not returning phone calls',
554
			'category_id' => 6,
555
			'category' => [
556
				'id' => 6,
557
				'name' => 'Exhausted',
558
			],
559
		],
560
	], [
561
		'id' => 831,
562
		'user_id' => 2,
563
		'behavior_id' => 122,
564
		'date' => '2016-09-10 19:26:04',
565
		'behavior' => [
566
			'id' => 122,
567
			'name' => 'returning to the place you swore you would never go again',
568
			'category_id' => 7,
569
			'category' => [
570
				'id' => 7,
571
				'name' => 'Relapse/Moral Failure',
572
			],
573
		],
574
	],
575
];
576
577
public $userBehaviors = [
578
	1 => [
579
		'category_name' => 'Restoration',
580
		'behaviors' => [
581
			[
582
				'id' => 7,
583
				'name' => 'making eye contact',
584
			],
585
		],
586
	],
587
	2 => [
588
		'category_name' => 'Forgetting Priorities',
589
		'behaviors' => [
590
			[
591
				'id' => 13,
592
				'name' => 'less time/energy for God, meetings, and church',
593
			], [
594
				'id' => 18,
595
				'name' => 'changes in goals',
596
			],
597
		],
598
  ],
599
  3 => [
600
		'category_name' => 'Anxiety',
601
		'behaviors' => [
602
			[
603
				'id' => 29,
604
				'name' => 'using profanity',
605
			], [
606
				'id' => 41,
607
				'name' => 'co-dependent rescuing',
608
			],
609
		],
610
	],
611
	4 => [
612
		'category_name' => 'Speeding Up',
613
		'behaviors' => [
614
			[
615
				'id' => 48,
616
				'name' => 'workaholic',
617
			],
618
		],
619
	],
620
	5 => [
621
		'category_name' => 'Ticked Off',
622
		'behaviors' => [
623
			[
624
				'id' => 72,
625
				'name' => 'black and white, all or nothing thinking',
626
			], [
627
				'id' => 79,
628
				'name' => 'blaming',
629
			], [
630
				'id' => 89,
631
				'name' => 'obsessive (stuck) thoughts',
632
			],
633
		],
634
	],
635
	6 => [
636
		'category_name' => 'Exhausted',
637
		'behaviors' => [
638
			[
639
				'id' => 111,
640
				'name' => 'seeking out old unhealthy people and places',
641
			], [
642
				'id' => 118,
643
				'name' => 'not returning phone calls',
644
			],
645
		],
646
	],
647
	7 => [
648
		'category_name' => 'Relapse/Moral Failure',
649
		'behaviors' => [
650
			[
651
				'id' => 122,
652
				'name' => 'returning to the place you swore you would never go again',
653
			],
654
		],
655
	],
656
];
657
658
public $exportData = [
659
    [
660
      'id' => 485,
661
      'date' => '2017-07-29 10:40:29',
662
      'behavior_id' => 59,
663
      'question1' => 'q1',
664
      'question2' => 'q2',
665
      'question3' => 'q3',
666
      'behavior' => [
667
        'id' => 59,
668
        'name' => 'repetitive, negative thoughts',
669
        'category_id' => 4,
670
        'category' => [
671
          'id' => 4,
672
          'name' => 'Speeding Up',
673
        ],
674
      ],
675
    ], [
676
      'id' => 487,
677
      'date' => '2017-07-29 10:40:29',
678
      'behavior_id' => 106,
679
      'question1' => 'q1',
680
      'question2' => 'q2',
681
      'question3' => 'q3',
682
      'behavior' => [
683
        'id' => 106,
684
        'name' => 'tired',
685
        'category_id' => 6,
686
        'category' => [
687
          'id' => 6,
688
          'name' => 'Exhausted',
689
        ],
690
      ],
691
    ], [
692
      'id' => 488,
693
      'date' => '2017-07-29 10:40:29',
694
      'behavior_id' => 125,
695
      'question1' => 'q1',
696
      'question2' => 'q2',
697
      'question3' => 'q3',
698
      'behavior' => [
699
        'id' => 125,
700
        'name' => 'out of control',
701
        'category_id' => 7,
702
        'category' => [
703
          'id' => 7,
704
          'name' => 'Relapse/Moral Failure',
705
        ],
706
      ],
707
    ], [
708
      'id' => 486,
709
      'date' => '2017-07-29 10:40:29',
710
      'behavior_id' => 89,
711
      'question1' => 'q1',
712
      'question2' => 'q2',
713
      'question3' => 'q3',
714
      'behavior' => [
715
        'id' => 89,
716
        'name' => 'obsessive (stuck) thoughts',
717
        'category_id' => 5,
718
        'category' => [
719
          'id' => 5,
720
          'name' => 'Ticked Off',
721
        ]
722
      ],
723
    ]
724
  ];
725
726
  public function setUp() {
727
    $this->container = new \yii\di\Container;
0 ignored issues
show
Bug Best Practice introduced by
The property container does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
728
    $this->container->set('common\interfaces\UserInterface', '\site\tests\_support\MockUser');
729
    $this->container->set('common\interfaces\UserBehaviorInterface', '\site\tests\_support\MockUserBehavior');
730
    $this->container->set('common\interfaces\TimeInterface', function () {
731
      return new \common\components\Time('America/Los_Angeles');
732
    });
733
734
    $user_behavior = $this->container->get('common\interfaces\UserBehaviorInterface');
735
    $this->time    = $this->container->get('common\interfaces\TimeInterface');
736
737
    $this->question = $this->getMockBuilder('\common\models\Question')
738
      ->setMethods(['save', 'attributes'])
739
      ->getMock();
740
741
    $this->user = $this->getMockBuilder('\common\models\User')
742
      ->setConstructorArgs([$user_behavior, $this->question, $this->time])
743
      ->setMethods(['save', 'attributes'])
744
      ->getMock();
745
    $this->user->method('save')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

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

745
    $this->user->/** @scrutinizer ignore-call */ 
746
                 method('save')->willReturn(true);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
746
    $this->user->method('attributes')->willReturn([
747
      'id',
748
      'password_hash',
749
      'password_reset_token',
750
      'verify_email_token',
751
      'change_email_token',
752
      'email',
753
      'auth_key',
754
      'role',
755
      'status',
756
      'created_at',
757
      'updated_at',
758
      'password',
759
      'timezone',
760
      'send_email',
761
      'email_category',
762
      'partner_email1',
763
      'partner_email2',
764
      'partner_email3',
765
    ]);
766
767
    parent::setUp();
768
  }
769
770
  protected function tearDown() {
771
    $this->user = null;
772
    parent::tearDown();
773
  }
774
775
  public function testParseQuestionData() {
776
    $this->specify('parseQuestionData should function correctly', function () {
777
      expect('parseQuestionData should return the correct structure with expected data', $this->assertEquals($this->user->parseQuestionData($this->questionData), $this->userQuestions));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals($thi..., $this->userQuestions) targeting PHPUnit\Framework\Assert::assertEquals() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
778
      expect('parseQuestionData should return empty with the empty set', $this->assertEmpty($this->user->parseQuestionData([])));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEmpty($this...eQuestionData(array())) targeting PHPUnit\Framework\Assert::assertEmpty() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
779
    });
780
  }
781
782
  public function testParseBehaviorData() {
783
    $this->specify('parseBehaviorData should function correctly', function () {
784
      expect('parseBehaviorData should return the correct structure with expected data', $this->assertEquals($this->user->parseBehaviorData($this->behaviorData), $this->userBehaviors));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals($thi..., $this->userBehaviors) targeting PHPUnit\Framework\Assert::assertEquals() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
785
      expect('parseBehaviorData should return empty with the empty set', $this->assertEmpty($this->user->parseBehaviorData([])));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEmpty($this...eBehaviorData(array())) targeting PHPUnit\Framework\Assert::assertEmpty() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
786
    });
787
  }
788
789
  public function testIsTokenCurrent() {
790
    $this->specify('isTokenCurrent should function correctly', function () {
791
      $good_token = \Yii::$app
792
                      ->getSecurity()
793
                      ->generateRandomString() . '_' . time();
794
      expect('isTokenCurrent should return true if the token is still current/alive', $this->assertTrue($this->user->isTokenCurrent($good_token)));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertTrue($this-...enCurrent($good_token)) targeting PHPUnit\Framework\Assert::assertTrue() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
795
      $expire = \Yii::$app->params['user.passwordResetTokenExpire'];
796
      $bad_token = \Yii::$app
797
                      ->getSecurity()
798
                      ->generateRandomString() . '_' . (time() - $expire - 1); // subtract the expiration time and a little more from the current time
799
      expect('isTokenCurrent should return false if the token is expired', $this->assertFalse($this->user->isTokenCurrent($bad_token)));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($this...kenCurrent($bad_token)) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
800
    });
801
  }
802
803
  public function testIsTokenConfirmed() {
804
      expect('isTokenConfirmed should return true if the token has been confirmed', $this->assertTrue($this->user->isTokenConfirmed('token123_confirmed')));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertTrue($this-...('token123_confirmed')) targeting PHPUnit\Framework\Assert::assertTrue() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
805
      expect('isTokenConfirmed should return false if the token has not been confirmed', $this->assertFalse($this->user->isTokenConfirmed('token123')));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($this...nConfirmed('token123')) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
806
      expect('isTokenConfirmed should return false if the token has not been confirmed', $this->assertFalse($this->user->isTokenConfirmed('token123_not_blah')));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($this...d('token123_not_blah')) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
807
  }
808
809
  public function testGeneratePasswordResetToken() {
810
    expect('password_reset_token should be null by default', $this->assertNull($this->user->password_reset_token));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertNull($this-...->password_reset_token) targeting PHPUnit\Framework\Assert::assertNull() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
811
    $this->user->generatePasswordResetToken();
812
    expect('password_reset_token should now have a verification token set', $this->assertRegExp('/.*_[0-9]+/', $this->user->password_reset_token));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertRegExp('/.*...->password_reset_token) targeting PHPUnit\Framework\Assert::assertRegExp() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
813
  }
814
815
  public function testGenerateVerifyEmailToken() {
816
    expect('verify_email_token should be null by default', $this->assertNull($this->user->verify_email_token));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertNull($this-...er->verify_email_token) targeting PHPUnit\Framework\Assert::assertNull() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
817
    $this->user->generateVerifyEmailToken();
818
    expect('verify_email_token should now have a verification token set', $this->assertRegExp('/.*_[0-9]+/', $this->user->verify_email_token));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertRegExp('/.*...er->verify_email_token) targeting PHPUnit\Framework\Assert::assertRegExp() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
819
  }
820
821
  public function testConfirmVerifyEmailToken() {
822
    $this->user->verify_email_token = 'hello_world';
823
    $this->user->confirmVerifyEmailToken();
824
    expect('confirmVerifyEmailToken should append User::CONFIRMED_STRING to the end of the verify_email_token property', $this->assertEquals($this->user->verify_email_token, 'hello_world'.$this->user::CONFIRMED_STRING));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals($thi...user::CONFIRMED_STRING) targeting PHPUnit\Framework\Assert::assertEquals() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
825
  }
826
827
  public function testIsVerified() {
828
      $this->user->verify_email_token = null;
829
      expect('isVerified should return true if the token is null', $this->assertTrue($this->user->isVerified()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertTrue($this->user->isVerified()) targeting PHPUnit\Framework\Assert::assertTrue() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
830
      $this->user->verify_email_token = '';
831
      expect('isVerified should return false if the token is the empty string', $this->assertFalse($this->user->isVerified()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($this->user->isVerified()) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
832
      $this->user->verify_email_token = 'this_looks_truthy';
833
      expect('isVerified should return false if the token is still present', $this->assertFalse($this->user->isVerified()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($this->user->isVerified()) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
834
  }
835
836
  public function testRemoveVerifyEmailToken() {
837
      $this->user->verify_email_token = 'faketoken_1234';
838
      $this->user->removeVerifyEmailToken();
839
      expect('removeVerifyEmailToken should set the verify_email_token to be null', $this->assertNull($this->user->verify_email_token));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertNull($this-...er->verify_email_token) targeting PHPUnit\Framework\Assert::assertNull() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
840
  }
841
842
  public function testGetIdHash() {
843
    $hash = 'iegYQgiPZUF48kk5bneuPn9_6ZOZhkMEGJ6Y8yICgKc';
844
845
    $this->user->id = 12345;
846
    $this->user->created_at = "2017-12-31 23:59:59";
847
    expect('getIdHash should return a url-safe string', $this->assertEquals($this->user->getidHash(), $hash));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals($thi...er->getidHash(), $hash) targeting PHPUnit\Framework\Assert::assertEquals() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
848
849
    $this->user->created_at = "2018-01-01 00:00:00";
850
    expect('getIdHash should return a DIFFERENT url-safe string for different params', $this->assertNotEquals($this->user->getidHash(), $hash));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertNotEquals($...er->getidHash(), $hash) targeting PHPUnit\Framework\Assert::assertNotEquals() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
851
  }
852
853
  public function testCleanExportData() {
854
    // need this for the convertUTCToLocal call
855
    Yii::configure(Yii::$app, [
856
      'components' => [
857
        'user' => [
858
          'class' => 'yii\web\User',
859
          'identityClass' => 'common\tests\unit\FakeUser',
860
        ],
861
      ],
862
    ]);
863
    $identity = new \common\tests\unit\FakeUser();
864
    $identity->timezone = "America/Los_Angeles";
865
    // logs in the user 
866
    Yii::$app->user->setIdentity($identity);
0 ignored issues
show
Bug introduced by
The method setIdentity() does not exist on null. ( Ignorable by Annotation )

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

866
    Yii::$app->user->/** @scrutinizer ignore-call */ 
867
                     setIdentity($identity);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
867
868
    expect('cleanExportData should clean and mutate the queried data to be suitable for downloading', $this->assertEquals([
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...ata($this->exportData)) targeting PHPUnit\Framework\Assert::assertEquals() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
869
      [
870
        'date' => '2017-07-29 03:40:29',
871
        'behavior' => 'repetitive, negative thoughts',
872
        'category' => 'Speeding Up',
873
        'question1' => 'q1',
874
        'question2' => 'q2',
875
        'question3' => 'q3',
876
      ], [
877
        'date' => '2017-07-29 03:40:29',
878
        'behavior' => 'tired',
879
        'category' => 'Exhausted',
880
        'question1' => 'q1',
881
        'question2' => 'q2',
882
        'question3' => 'q3',
883
      ], [
884
        'date' => '2017-07-29 03:40:29',
885
        'behavior' => 'out of control',
886
        'category' => 'Relapse/Moral Failure',
887
        'question1' => 'q1',
888
        'question2' => 'q2',
889
        'question3' => 'q3',
890
      ], [
891
        'date' => '2017-07-29 03:40:29',
892
        'behavior' => 'obsessive (stuck) thoughts',
893
        'category' => 'Ticked Off',
894
        'question1' => 'q1',
895
        'question2' => 'q2',
896
        'question3' => 'q3',
897
      ]
898
    ], $this->user->cleanExportData($this->exportData)));
899
  }
900
901
  public function testGenerateChangeEmailToken() {
902
    expect('change_email_token should be null by default', $this->assertNull($this->user->change_email_token));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertNull($this-...er->change_email_token) targeting PHPUnit\Framework\Assert::assertNull() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
903
    $this->user->generateChangeEmailToken();
904
    expect('change_email_token should now have a verification token set', $this->assertRegExp('/.*_[0-9]+/', $this->user->change_email_token));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertRegExp('/.*...er->change_email_token) targeting PHPUnit\Framework\Assert::assertRegExp() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
905
  }
906
907
  public function testRemoveChangeEmailToken() {
908
      $this->user->change_email_token = 'faketoken_1234';
909
      $this->user->removeChangeEmailToken();
910
      expect('removeChangeEmailToken should set the change_email_token to be null', $this->assertNull($this->user->change_email_token));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertNull($this-...er->change_email_token) targeting PHPUnit\Framework\Assert::assertNull() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
911
  }
912
913
  public function testSendEmailReport() {
914
    $user_behavior = $this->getMockBuilder('common\models\UserBehavior')
915
      ->disableOriginalConstructor()
916
      ->setMethods(['save', 'attributes', 'getCheckinBreakdown'])
917
      ->getMock();
918
    $expected = require(__DIR__.'/../data/expected_getCheckinBreakdown.php');
919
    $user_behavior->method('getCheckinBreakdown')->willReturn($expected);
920
921
    $user = $this->getMockBuilder('\common\models\User')
922
      ->setConstructorArgs([$user_behavior, $this->question, $this->time])
923
      ->setMethods(['save', 'attributes'])
924
      ->getMock();
925
    $user->method('save')->willReturn(true);
926
    $user->method('attributes')->willReturn([
927
      'send_email',
928
      'email_category',
929
    ]);
930
931
    $user->send_email = false;
0 ignored issues
show
Bug introduced by
Accessing send_email on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
932
    $user->email_category = 6;
0 ignored issues
show
Bug introduced by
Accessing email_category on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
933
    expect('it should not send any emails if the user has disabled send_email', $this->assertFalse($user->sendEmailReport('2019-01-01')));
0 ignored issues
show
Bug introduced by
The method sendEmailReport() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

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

933
    expect('it should not send any emails if the user has disabled send_email', $this->assertFalse($user->/** @scrutinizer ignore-call */ sendEmailReport('2019-01-01')));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
Are you sure the usage of $this->assertFalse($user...ilReport('2019-01-01')) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
934
    expect('it should not send any emails if the user did not select any behaviors for the given day', $this->assertFalse($user->sendEmailReport('2018-01-01')));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($user...ilReport('2018-01-01')) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
935
    expect('it should not send any emails if the user did not select any behaviors for the given day', $this->assertFalse($user->sendEmailReport('2018-03-02')));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($user...ilReport('2018-03-02')) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
936
    expect('it should not send any emails if the user did not meet or exceed their email_category', $this->assertFalse($user->sendEmailReport('2019-03-01')));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($user...ilReport('2019-03-01')) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
937
  }
938
}
939