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

EditProfileFormTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace site\tests\unit\models;
4
5
use Yii;
6
use \site\models\EditProfileForm;
7
8
class EditProfileFormTest extends \Codeception\Test\Unit {
9
	public $values = [
10
			'timezone' => 'America/Los_Angeles',
11
      'send_email' => true,
12
			'partner_email1' => '[email protected]',
13
			'partner_email2' => '[email protected]',
14
			'partner_email3' => '[email protected]',
15
		];
16
17
  public function testLoadUser() {
18
    $user = $this->getUser();
19
    $form = new \site\models\EditProfileForm($user);
20
    $form->loadUser();
21
    expect('timezone should be equal', $this->assertEquals($form->timezone, $user->timezone));
0 ignored issues
show
Bug introduced by
Accessing timezone on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Are you sure the usage of $this->assertEquals($for...ezone, $user->timezone) 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...
22
    expect('partner_email1 should be equal', $this->assertEquals($form->partner_email1, $user->partner_email1));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals($for... $user->partner_email1) 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...
Bug introduced by
Accessing partner_email1 on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
23
    expect('partner_email2 should be equal', $this->assertEquals($form->partner_email2, $user->partner_email2));
0 ignored issues
show
Bug introduced by
Accessing partner_email2 on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Are you sure the usage of $this->assertEquals($for... $user->partner_email2) 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...
24
    expect('partner_email3 should be equal', $this->assertEquals($form->partner_email3, $user->partner_email3));
0 ignored issues
show
Bug introduced by
Accessing partner_email3 on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Are you sure the usage of $this->assertEquals($for... $user->partner_email3) 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
    expect('send_email should be true', $this->assertTrue($form->send_email));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertTrue($form->send_email) 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...
26
  }
27
28
  public function testSaveProfile() {
29
    $user = $this->getUser();
30
    $form = new \site\models\EditProfileForm($user);
31
    $form->loadUser();
32
33
    Yii::$container
34
      ->set(\common\interfaces\UserBehaviorInterface::class, function () { return new FakeUserBehavior(); });
35
36
    $form->attributes = $this->values;
37
    expect('saveProfile should return the user', $this->assertEquals($user, $form->saveProfile()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals($user, $form->saveProfile()) 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...
38
		expect('saveProfile should set the user\'s attributes to be the form values', $this->assertEquals($this->values, $user->attributes));
0 ignored issues
show
Bug introduced by
Accessing attributes on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Are you sure the usage of $this->assertEquals($thi...ues, $user->attributes) 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...
39
40
    $form->send_email = 'not_a_boolean';
41
    expect('saveProfile should return the user with the partner-related settings equal to null', $this->assertNull($form->saveProfile()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertNull($form->saveProfile()) 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...
42
43
		$null_vals = [
44
			'partner_email1'  => null,
45
			'partner_email2'  => null,
46
			'partner_email3'  => null,
47
      'send_email'      => null,
48
			'timezone'        => 'America/Los_Angeles',
49
		];
50
    $form->send_email = false;
51
		$ret = $form->saveProfile();
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
52
    expect('saveProfile should return the user with the partner-related settings equal to null', $this->assertEquals($null_vals, $user->attributes));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals($nul...als, $user->attributes) 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...
53
54
    $form->send_email = 'not_a_boolean';
55
    expect('saveProfile should return null if the form validation fails', $this->assertNull($form->saveProfile()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertNull($form->saveProfile()) 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...
56
  }
57
58
  private function getUser() {
59
    $user = $this->getmockbuilder('\common\models\user')
60
      ->disableoriginalconstructor()
61
      ->setmethods(['getisnewrecord', 'attributes', 'save', 'findbypasswordresettoken', 'removepasswordresettoken'])
62
      ->getmock();
63
    $user->method('attributes')->willReturn([
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

63
    $user->/** @scrutinizer ignore-call */ 
64
           method('attributes')->willReturn([

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...
64
      'timezone',
65
      'partner_email1',
66
      'partner_email2',
67
      'partner_email3',
68
      'send_email',
69
    ]);
70
    $user->timezone = 'America/Los_Angeles';
0 ignored issues
show
Bug introduced by
Accessing timezone on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
71
    $user->partner_email1 = '[email protected]';
0 ignored issues
show
Bug introduced by
Accessing partner_email1 on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
72
    $user->partner_email2 = '[email protected]';
0 ignored issues
show
Bug introduced by
Accessing partner_email2 on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
73
    $user->partner_email3 = '[email protected]';
0 ignored issues
show
Bug introduced by
Accessing partner_email3 on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
74
    $user->send_email = true;
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...
75
    return $user;
76
  }
77
}
78
79
class FakeUserBehavior {
80
  public $scores = true;
81
  public function calculateScoresOfLastMonth() { return $this->scores; }
82
}
83