Completed
Pull Request — master (#171)
by Corey
02:59
created

FakeUserBehavior   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 3
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A calculateScoresOfLastMonth() 0 1 1
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 $graph;
10
	public $values = [
11
			'timezone' => 'America/Los_Angeles',
12
			'email_threshold' => 5,
13
			'partner_email1' => '[email protected]',
14
			'partner_email2' => '[email protected]',
15
			'partner_email3' => '[email protected]',
16
			'expose_graph' => true,
17
		];
18
19
	public function setUp() {
20
		$this->graph = $this->getMockBuilder(common\components\Graph::class)
0 ignored issues
show
Bug introduced by
The type site\tests\unit\models\common\components\Graph was not found. Did you mean common\components\Graph? If so, make sure to prefix the type with \.
Loading history...
21
			->setMethods(['create', 'destroy'])
22
			->getMock();
23
		parent::setUp();
24
	}
25
26
  public function testLoadUser() {
27
    $user = $this->getUser();
28
    $form = new \site\models\EditProfileForm($user);
29
    $form->loadUser();
30
    expect('timezone should be equal', $this->assertEquals($form->timezone, $user->timezone));
0 ignored issues
show
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...
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...
31
    expect('email_threshold should be equal', $this->assertEquals($form->email_threshold, $user->email_threshold));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals($for...$user->email_threshold) 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 email_threshold on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
32
    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...
33
    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...
34
    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...
35
    expect('expose_graph should be equal', $this->assertEquals($form->expose_graph, $user->expose_graph));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals($for...h, $user->expose_graph) 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 expose_graph on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
36
    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...
37
38
    $user->email_threshold = null;
39
    $form->loadUser();
40
    expect('send_email should be false', $this->assertFalse($form->send_email));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($form->send_email) 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...
41
42
    $user->partner_email1 = null;
43
    $user->partner_email2 = null;
44
    $user->partner_email3 = null;
45
    $form->loadUser();
46
    expect('send_email should be false', $this->assertFalse($form->send_email));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($form->send_email) 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...
47
  }
48
49
  public function testSaveProfile() {
50
    $user = $this->getUser();
51
    $form = new \site\models\EditProfileForm($user);
52
    $form->loadUser();
53
54
    Yii::$container
55
      ->set(\common\components\Graph::class, function () { return $this->graph; });
56
    Yii::$container
57
      ->set(\common\interfaces\UserBehaviorInterface::class, function () { return new FakeUserBehavior(); });
58
59
    $form->attributes = $this->values;
60
    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...
61
		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
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...
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...
62
63
    $form->send_email = 'not_a_boolean';
64
		$ret = $form->saveProfile();
65
    expect('saveProfile should return the user with the partner-related settings equal to null', $this->assertNull($ret));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertNull($ret) 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...
66
67
		$null_vals = [
68
			'email_threshold' => null,
69
			'partner_email1'  => null,
70
			'partner_email2'  => null,
71
			'partner_email3'  => null,
72
			'timezone'        => 'America/Los_Angeles',
73
			'expose_graph'    => true,
74
		];
75
    $form->send_email = false;
76
		$ret = $form->saveProfile();
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
77
    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...
78
79
		$this->graph
80
			->expects($this->once())
81
			->method('destroy');
82
		$form->expose_graph = false;
83
		$ret = $form->saveProfile();
84
		expect('if form->expose_graph is set to false, destroy the graph and set user->expose_graph to false', $this->assertFalse($ret->expose_graph));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($ret->expose_graph) 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...
85
86
		$this->graph
87
			->expects($this->once())
88
			->method('create');
89
		$form->expose_graph = true;
90
		$ret = $form->saveProfile();
91
		expect('if form->expose_graph is set to true, create the graph and set user->expose_graph to true', $this->assertTrue($ret->expose_graph));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertTrue($ret->expose_graph) 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...
92
		
93
    $form->send_email = 'not_a_boolean';
94
    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...
95
  }
96
97
  private function getUser() {
98
    $user = $this->getmockbuilder('\common\models\user')
99
      ->disableoriginalconstructor()
100
      ->setmethods(['getisnewrecord', 'attributes', 'save', 'findbypasswordresettoken', 'removepasswordresettoken'])
101
      ->getmock();
102
    $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

102
    $user->/** @scrutinizer ignore-call */ 
103
           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...
103
      'timezone',
104
      'email_threshold',
105
      'partner_email1',
106
      'partner_email2',
107
      'partner_email3',
108
      'expose_graph',
109
    ]);
110
    $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...
111
    $user->email_threshold = 5;
0 ignored issues
show
Bug introduced by
Accessing email_threshold on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
112
    $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...
113
    $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...
114
    $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...
115
    $user->expose_graph = true;
0 ignored issues
show
Bug introduced by
Accessing expose_graph on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
116
    return $user;
117
  }
118
}
119
120
class FakeUserBehavior {
121
  public $scores = true;
122
  public function calculateScoresOfLastMonth() { return $this->scores; }
123
}
124