Passed
Pull Request — master (#171)
by Corey
05:48
created

ViewTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 17
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testRegisterJson() 0 21 1
1
<?php
2
3
namespace common\tests\unit\components;
4
5
use Yii;
6
use common\components\View;
7
8
/**
9
 * View test
10
 */
11
12
class ViewTest extends \Codeception\Test\Unit {
13
    use \Codeception\Specify;
14
15
    public function testRegisterJson() {
16
      $view = new View();
17
      $key = 'test';
18
      $data = [
19
        'name' => 'user one',
20
        'email' => '[email protected]'
21
      ];
22
      $view->registerJson($data, $key);
23
24
      expect("The supplied array should be encoded as JSON and set on the View obj", $this->assertEquals($data, json_decode($view->json[$view::POS_READY][$key], true)));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals($dat...OS_READY][$key], true)) 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
      $view = new View();
27
      $data = [
28
        'name' => 'user one',
29
        'email' => '[email protected]'
30
      ];
31
      $view->registerJson($data);
32
33
      $expected_key = md5(json_encode($data, true));
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type integer expected by parameter $options of json_encode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
      $expected_key = md5(json_encode($data, /** @scrutinizer ignore-type */ true));
Loading history...
34
      expect("If no key is supplied it should default to the md5 of the json_encoded data", $this->assertArrayHasKey($expected_key, $view->json[$view::POS_READY]));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertArrayHasKey...json[$view::POS_READY]) targeting PHPUnit\Framework\Assert::assertArrayHasKey() 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("If no key is supplied it should default to the md5 of the json_encoded data", $this->assertEquals(json_encode($data, true), $view->json[$view::POS_READY][$expected_key]));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(json..._READY][$expected_key]) 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...
36
    }
37
}
38