Passed
Push — master ( 41f848...de078e )
by Corey
05:23 queued 02:26
created

CheckinFormTest::testMergeWithDefault()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 17
rs 9.9
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 yii\helpers\ArrayHelper as AH;
7
8
class CheckinFormTest extends \Codeception\Test\Unit
9
{
10
    use \Codeception\Specify;
11
12
    public $behaviors = [
13
      1 => [
14
        'making eye contact' => [
15
          'id' => 7,
16
          'name' => 'making eye contact',
17
        ],
18
      ],
19
      2 => [
20
        'bored' => [
21
          'id' => 12,
22
          'name' => 'bored',
23
        ],
24
        'less time/energy for God, meetings, and church' => [
25
          'id' => 13,
26
          'name' => 'less time/energy for God, meetings, and church',
27
        ],
28
        'isolating yourself' => [
29
          'id' => 17,
30
          'name' => 'isolating yourself',
31
        ],
32
        'changes in goals' => [
33
          'id' => 18,
34
          'name' => 'changes in goals',
35
        ],
36
      ],
37
      3 => [
38
        'worry' => [
39
          'id' => 28,
40
          'name' => 'worry',
41
        ],
42
        'fantasy' => [
43
          'id' => 38,
44
          'name' => 'fantasy',
45
        ],
46
        'using over-the-counter medication for pain, sleep, and weight control' => [
47
          'id' => 46,
48
          'name' => 'using over-the-counter medication for pain, sleep, and weight control',
49
        ],
50
      ],
51
      4 => [
52
        'super busy' => [
53
          'id' => 47,
54
          'name' => 'super busy',
55
        ],
56
        'binge eating (usually at night]' => [
57
          'id' => 56,
58
          'name' => 'binge eating (usually at night]',
59
        ],
60
        'dramatic mood swings' => [
61
          'id' => 62,
62
          'name' => 'dramatic mood swings',
63
        ],
64
      ],
65
      5 => [
66
        'increased isolation' => [
67
          'id' => 78,
68
          'name' => 'increased isolation',
69
        ],
70
        'blaming' => [
71
          'id' => 79,
72
          'name' => 'blaming',
73
        ],
74
      ],
75
      6 => [
76
        'pessimistic' => [
77
          'id' => 104,
78
          'name' => 'pessimistic',
79
        ],
80
      ],
81
      7 => [
82
        'feeling you just can\'t manage without your coping behavior, at least for now' => [
83
          'id' => 128,
84
          'name' => 'feeling you just can\'t manage without your coping behavior, at least for now',
85
        ],
86
      ],
87
    ];
88
89
    protected function setUp() {
90
      $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...
91
      $this->container->set('common\interfaces\UserBehaviorInterface', '\site\tests\_support\MockUserBehavior');
92
    $this->container->set('common\interfaces\TimeInterface', function () {
93
      return new \common\components\Time('America/Los_Angeles');
94
    });
95
      parent::setUp();
96
    }
97
98
		public function testAttributeLabels()
99
		{
100
        $this->specify('attributeLabels should function properly', function () {
101
          $model = $this->container->get('\site\models\CheckinForm');
102
          expect('attributeLabels should be correct', $this->assertEquals([
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...del->attributeLabels()) 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...
103
            'behaviors1' => 'Restoration',
104
            'behaviors2' => 'Forgetting Priorities',
105
            'behaviors3' => 'Anxiety',
106
            'behaviors4' => 'Speeding Up',
107
            'behaviors5' => 'Ticked Off',
108
            'behaviors6' => 'Exhausted',
109
            'behaviors7' => 'Relapsed/Moral Failure'
110
          ], $model->attributeLabels()));
111
        });
112
    }
113
114
    public function testSetBehaviors()
115
    {
116
        $this->specify('setBehaviors should function properly', function () {
117
          $model = $this->container->get('\site\models\CheckinForm');
118
119
					$model->setBehaviors($this->behaviors);
120
          expect('behaviors1 should be correct', $this->assertEquals([ 0 => 7 ], $model->behaviors1));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...7), $model->behaviors1) 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...
121
          expect('behaviors2 should be correct', $this->assertEquals([ 0 => 12, 1 => 13, 2 => 17, 3 => 18 ], $model->behaviors2));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...8), $model->behaviors2) 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...
122
          expect('behaviors3 should be correct', $this->assertEquals([ 0 => 28, 1 => 38, 2 => 46 ], $model->behaviors3));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...6), $model->behaviors3) 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...
123
          expect('behaviors4 should be correct', $this->assertEquals([ 0 => 47, 1 => 56, 2 => 62 ], $model->behaviors4));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...2), $model->behaviors4) 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...
124
          expect('behaviors5 should be correct', $this->assertEquals([ 0 => 78, 1 => 79 ], $model->behaviors5));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...9), $model->behaviors5) 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...
125
          expect('behaviors6 should be correct', $this->assertEquals([ 0 => 104 ], $model->behaviors6));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...4), $model->behaviors6) 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...
126
          expect('behaviors7 should be correct', $this->assertEquals([ 0 => 128 ], $model->behaviors7));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...8), $model->behaviors7) 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...
127
128
					$model->setBehaviors($this->behaviors);
129
          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 7 ], $model->behaviors1));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...7), $model->behaviors1) 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...
130
          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 12, 1 => 13, 2 => 17, 3 => 18 ], $model->behaviors2));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...8), $model->behaviors2) 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...
131
          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 28, 1 => 38, 2 => 46 ], $model->behaviors3));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...6), $model->behaviors3) 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...
132
          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 47, 1 => 56, 2 => 62 ], $model->behaviors4));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...2), $model->behaviors4) 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...
133
          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 78, 1 => 79 ], $model->behaviors5));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...9), $model->behaviors5) 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...
134
          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 104 ], $model->behaviors6));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...4), $model->behaviors6) 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...
135
          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 128 ], $model->behaviors7));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...8), $model->behaviors7) 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...
136
        });
137
    }
138
139
		public function testValidateBehaviors()
140
		{
141
        $this->specify('validateBehaviors should function properly', function () {
142
          $model = $this->container->get('\site\models\CheckinForm');
143
					$model->setBehaviors($this->behaviors);
144
          expect('validation should be good', $this->assertTrue($model->validate()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertTrue($model->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...
145
146
          $model->behaviors1[0] = 'bad';
147
          expect('validation should be bad', $this->assertFalse($model->validate()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($model->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...
148
        });
149
		}
150
151
		public function testCompileBehaviors()
152
    {
153
      $model = $this->container->get('\site\models\CheckinForm');
154
      $model->setBehaviors($this->behaviors);
155
      expect('compiling behaviors should be return a correct array', $this->assertEquals([
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...el->compileBehaviors()) 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...
156
        0 => 7,
157
        1 => 12,
158
        2 => 13,
159
        3 => 17,
160
        4 => 18,
161
        5 => 28,
162
        6 => 38,
163
        7 => 46,
164
        8 => 47,
165
        9 => 56,
166
        10 => 62,
167
        11 => 78,
168
        12 => 79,
169
        13 => 104,
170
        14 => 128,
171
      ], $model->compileBehaviors()));
172
173
      $model = $this->container->get('\site\models\CheckinForm');
174
      $model->setBehaviors($this->behaviors);
175
      $model->behaviors1[0] = null;
176
      $model->behaviors2[0] = null;
177
      $model->behaviors3[0] = null;
178
      expect('compiling behaviors should strip out any falsy values', $this->assertEquals([
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...el->compileBehaviors()) 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...
179
        2 => 13,
180
        3 => 17,
181
        4 => 18,
182
        6 => 38,
183
        7 => 46,
184
        8 => 47,
185
        9 => 56,
186
        10 => 62,
187
        11 => 78,
188
        12 => 79,
189
        13 => 104,
190
        14 => 128,
191
      ], $model->compileBehaviors()));
192
193
      $model = $this->container->get('\site\models\CheckinForm');
194
      $model->setBehaviors([]);
195
      expect('compiling behaviors should return an empty array when no behaviors are set', $this->assertEmpty($model->compileBehaviors()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEmpty($model->compileBehaviors()) 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...
196
    }
197
198
    public function testMergeWithDefault() {
199
      $model = $this->container->get('\site\models\CheckinForm');
200
201
      $base_behaviors = AH::index(Yii::$container->get(\common\models\Behavior::class)::$behaviors, 'name', "category_id");
202
      expect('mergeWithDefault should return the base behaviors when given an empty array', $this->assertEquals($base_behaviors, $model->mergeWithDefault([])));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals($bas...geWithDefault(array())) 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...
203
204
      $other_behaviors = [
205
        'some kind of really bad making eye contact' => [
206
          'id' => 400,
207
          'name' => 'some kind of really bad making eye contact',
208
          'category_id' => 7
209
        ]
210
      ];
211
      $expected_behaviors = $base_behaviors;
212
      $expected_behaviors[7] += $other_behaviors;
213
214
       expect('mergeWithDefault should return the given behaviors merged in with the base behaviors', $this->assertEquals($base_behaviors, $model->mergeWithDefault($other_behaviors)));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals($bas...ault($other_behaviors)) 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...
215
    }
216
}
217