PasswordResetRequestFormTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
eloc 24
c 3
b 0
f 0
dl 0
loc 75
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getUser() 0 13 1
A testRulesShouldValidate() 0 13 1
1
<?php
2
3
namespace site\tests\unit\models;
4
5
use Yii;
6
use \site\models\PasswordResetRequestForm;
7
use \yii\base\InvalidArgumentException;
8
9
class PasswordResetRequestFormTest extends \Codeception\Test\Unit {
10
  use \Codeception\Specify;
11
12
  public function testRulesShouldValidate() {
13
    $user = $this->getUser();
14
    $form = new PasswordResetRequestForm($user);
15
16
    $form->attributes = [];
17
    expect('with no values, the form should not pass validation', $this->assertFalse($form->validate()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($form->validate()) 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...
18
    $form->attributes = ['email' => null];
19
    expect('the form should not validate if the email is not provided', $this->assertFalse($form->validate()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($form->validate()) 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...
20
    $form->attributes = ['email' => '1'];
21
    expect('the form should not validate if the email is not a valid format', $this->assertFalse($form->validate()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($form->validate()) 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...
22
    $form->attributes = ['email' => '   [email protected]  '];
23
    expect('the form should validate', $this->assertTrue($form->validate()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertTrue($form->validate()) 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...
24
    expect('the form should lowercase and trim the provided email', $this->assertEquals($form->email, '[email protected]'));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals($for...ail, '[email protected]') 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...
25
  }
26
27
  /*
28
   * temporarily commenting this out while I figure out how to fix this test
29
   * with the User::findOne() call in sendEmail()
30
   */
31
  /*
32
  public function testSendEmail() {
33
    $user = $this->getUser();
34
    $user->generatePasswordResetToken();
35
36
    $user->isGuest = false;
37
    $user
38
      ->expects($this->once())
39
      ->method('isTokenCurrent')
40
      ->willReturn(true);
41
42
    $user
43
      ->expects($this->once())
44
      ->method('findOne')
45
      ->willReturn($user);
46
47
    $user
48
      ->expects($this->once())
49
      ->method('save')
50
      ->willReturn(true);
51
52
    $form = new PasswordResetRequestForm($user);
53
54
    $form->attributes = [
55
      'email' => '  [email protected]  ',
56
    ];
57
58
    $form->validate();
59
    $form->sendEmail();
60
61
    $this->tester->seeEmailIsSent();
62
    $emailMessage = $this->tester->grabLastSentEmail();
63
    expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
64
    expect($emailMessage->getTo())->hasKey('[email protected]');
65
    expect($emailMessage->getFrom())->hasKey(Yii::$app->params['supportEmail']);
66
    expect($emailMessage->getSubject())->equals('Password reset for ' . \Yii::$app->name);
67
    expect($emailMessage->toString())->contains('Follow the link below to reset your password');
68
  }
69
   */
70
71
  private function getUser() {
72
    $user = $this->getmockbuilder('\common\models\user')
73
      ->disableoriginalconstructor()
74
      ->setmethods(['getisnewrecord', 'attributes', 'save', 'generatepasswordresettoken', 'istokencurrent', 'findOne'])
75
      ->getmock();
76
    $user->method('attributes')->willReturn([
77
      'isGuest',
78
      'email',
79
      'password',
80
      'password_reset_token',
81
      'password_hash',
82
    ]);
83
    return $user;
84
  }
85
}
86
87
/*
88
class User extends \site\tests\_support\MockUser {
89
  public static function findOne($condition) {
90
    $user = $this->getmockbuilder('\common\models\user')
91
      ->disableoriginalconstructor()
92
      ->setmethods(['getisnewrecord', 'attributes', 'save', 'generatepasswordresettoken', 'istokencurrent', 'findOne'])
93
      ->getmock();
94
    $user->method('attributes')->willReturn([
95
      'isGuest',
96
      'email',
97
      'password',
98
      'password_reset_token',
99
      'password_hash',
100
    ]);
101
    $user->email = $condition['email'] || '[email protected]';
102
    return $user;
103
  }
104
}
105
*/
106