Completed
Pull Request — master (#163)
by Corey
02:42
created

UserTest::testConfirmVerifyEmailToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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

743
    $this->user->/** @scrutinizer ignore-call */ 
744
                 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...
744
    $this->user->method('attributes')->willReturn([
745
      'id',
746
      'password_hash',
747
      'password_reset_token',
748
      'verify_email_token',
749
      'change_email_token',
750
      'email',
751
      'auth_key',
752
      'role',
753
      'status',
754
      'created_at',
755
      'updated_at',
756
      'password',
757
      'timezone',
758
      'email_threshold',
759
      'partner_email1',
760
      'partner_email2',
761
      'partner_email3',
762
    ]);
763
764
    parent::setUp();
765
  }
766
767
  protected function tearDown() {
768
    $this->user = null;
769
    parent::tearDown();
770
  }
771
772
  public function testParseQuestionData() {
773
    $this->specify('parseQuestionData should function correctly', function () {
774
      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...
775
      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...
776
    });
777
  }
778
779
  public function testParseBehaviorData() {
780
    $this->specify('parseBehaviorData should function correctly', function () {
781
      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...
782
      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...
783
    });
784
  }
785
786
  public function testIsTokenCurrent() {
787
    $this->specify('isTokenCurrent should function correctly', function () {
788
      $good_token = \Yii::$app
789
                      ->getSecurity()
790
                      ->generateRandomString() . '_' . time();
791
      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...
792
      $expire = \Yii::$app->params['user.passwordResetTokenExpire'];
793
      $bad_token = \Yii::$app
794
                      ->getSecurity()
795
                      ->generateRandomString() . '_' . (time() - $expire - 1); // subtract the expiration time and a little more from the current time
796
      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...
797
    });
798
  }
799
800
  public function testIsTokenConfirmed() {
801
      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...
802
      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...
803
      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...
804
  }
805
806
  public function testGeneratePasswordResetToken() {
807
    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...
808
    $this->user->generatePasswordResetToken();
809
    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...
810
  }
811
812
  public function testGenerateVerifyEmailToken() {
813
    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...
814
    $this->user->generateVerifyEmailToken();
815
    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...
816
  }
817
818
  public function testConfirmVerifyEmailToken() {
819
    $this->user->verify_email_token = 'hello_world';
820
    $this->user->confirmVerifyEmailToken();
821
    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...
822
  }
823
824
  public function testIsVerified() {
825
      $this->user->verify_email_token = null;
826
      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...
827
      $this->user->verify_email_token = '';
828
      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...
829
      $this->user->verify_email_token = 'this_looks_truthy';
830
      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...
831
  }
832
833
  public function testRemoveVerifyEmailToken() {
834
      $this->user->verify_email_token = 'faketoken_1234';
835
      $this->user->removeVerifyEmailToken();
836
      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...
837
  }
838
839
  public function testGetIdHash() {
840
    $hash = 'iegYQgiPZUF48kk5bneuPn9_6ZOZhkMEGJ6Y8yICgKc';
841
842
    $this->user->id = 12345;
843
    $this->user->created_at = "2017-12-31 23:59:59";
844
    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...
845
846
    $this->user->created_at = "2018-01-01 00:00:00";
847
    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...
848
  }
849
850
  public function testCleanExportData() {
851
    // need this for the convertUTCToLocal call
852
    Yii::configure(Yii::$app, [
853
      'components' => [
854
        'user' => [
855
          'class' => 'yii\web\User',
856
          'identityClass' => 'common\tests\unit\FakeUser',
857
        ],
858
      ],
859
    ]);
860
    $identity = new \common\tests\unit\FakeUser();
861
    $identity->timezone = "America/Los_Angeles";
862
    // logs in the user 
863
    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

863
    Yii::$app->user->/** @scrutinizer ignore-call */ 
864
                     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...
864
865
    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...
866
      [
867
        'date' => '2017-07-29 03:40:29',
868
        'behavior' => 'repetitive, negative thoughts',
869
        'category' => 'Speeding Up',
870
        'question1' => 'q1',
871
        'question2' => 'q2',
872
        'question3' => 'q3',
873
      ], [
874
        'date' => '2017-07-29 03:40:29',
875
        'behavior' => 'tired',
876
        'category' => 'Exhausted',
877
        'question1' => 'q1',
878
        'question2' => 'q2',
879
        'question3' => 'q3',
880
      ], [
881
        'date' => '2017-07-29 03:40:29',
882
        'behavior' => 'out of control',
883
        'category' => 'Relapse/Moral Failure',
884
        'question1' => 'q1',
885
        'question2' => 'q2',
886
        'question3' => 'q3',
887
      ], [
888
        'date' => '2017-07-29 03:40:29',
889
        'behavior' => 'obsessive (stuck) thoughts',
890
        'category' => 'Ticked Off',
891
        'question1' => 'q1',
892
        'question2' => 'q2',
893
        'question3' => 'q3',
894
      ]
895
    ], $this->user->cleanExportData($this->exportData)));
896
  }
897
898
  public function testGenerateChangeEmailToken() {
899
    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...
900
    $this->user->generateChangeEmailToken();
901
    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...
902
  }
903
904
  public function testRemoveChangeEmailToken() {
905
      $this->user->change_email_token = 'faketoken_1234';
906
      $this->user->removeChangeEmailToken();
907
      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...
908
  }
909
}
910