Passed
Push — master ( fa46b3...ce6672 )
by Ylva
05:16 queued 02:30
created

SampleJsonControllerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
nc 1
nop 0
dl 0
loc 18
c 1
b 0
f 0
cc 1
rs 10
1
<?php
2
3
namespace Anax\Controller;
4
5
use Anax\DI\DIFactoryConfig;
0 ignored issues
show
Bug introduced by
The type Anax\DI\DIFactoryConfig was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * Test the SampleJsonController.
10
 */
11
class SampleJsonControllerTest extends TestCase
12
{
13
    
14
    // Create the di container.
15
    protected $di;
16
    protected $controller;
17
18
19
20
    /**
21
     * Prepare before each test.
22
     */
23
    protected function setUp()
24
    {
25
        global $di;
26
27
        // Setup di
28
        $this->di = new DIFactoryConfig();
29
        $this->di->loadServices(ANAX_INSTALL_PATH . "/config/di");
30
31
        // Use a different cache dir for unit test
32
        $this->di->get("cache")->setPath(ANAX_INSTALL_PATH . "/test/cache");
33
34
        // View helpers uses the global $di so it needs its value
35
        $di = $this->di;
36
37
        // Setup the controller
38
        $this->controller = new SampleJsonController();
39
        $this->controller->setDI($this->di);
40
        $this->controller->initialize();
41
    }
42
43
44
45
    /**
46
     * Test the route "index".
47
     */
48
    public function testIndexAction()
49
    {
50
        $res = $this->controller->indexActionGet();
51
        $this->assertInternalType("array", $res);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

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

51
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType("array", $res);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
52
53
        $json = $res[0];
54
        $exp = "db is active";
55
        $this->assertContains($exp, $json["message"]);
56
    }
57
58
59
60
    /**
61
     * Test the route "dump-di".
62
     */
63
    public function testDumpDiActionGet()
64
    {
65
        $res = $this->controller->dumpDiActionGet();
66
        $this->assertInternalType("array", $res);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

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

66
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType("array", $res);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
67
68
        $json = $res[0];
69
        $exp = "di contains";
70
        $this->assertContains($exp, $json["message"]);
71
        $this->assertContains("configuration", $json["di"]);
72
        $this->assertContains("request", $json["di"]);
73
        $this->assertContains("response", $json["di"]);
74
    }
75
76
77
78
    /**
79
     * Test the route "forbidden".
80
     */
81
    public function testForbiddenAction()
82
    {
83
        $res = $this->controller->forbiddenAction();
84
        $this->assertInternalType("array", $res);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

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

84
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType("array", $res);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
85
86
        $json = $res[0];
87
        $status = $res[1];
88
89
        $exp = "forbidden to access";
90
        $this->assertContains($exp, $json["message"]);
91
        $this->assertEquals(403, $status);
92
    }
93
}
94