Issues (1933)

a/test/Controller/SampleJsonControllerTest.php (3 issues)

Severity
1
<?php
2
3
namespace Anax\Controller;
4
5
use Anax\DI\DIFactoryConfig;
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