Test Setup Failed
Branch master (97a7ce)
by Anton
02:01
created

JsonControllerTest::testRenderPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 72
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 50
nc 1
nop 0
dl 0
loc 72
rs 9.0909
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace EVB\Weather;
4
5
// use Anax\DI\DIFactoryConfig;
6
use PHPUnit\Framework\TestCase;
7
use AnaxMocks\MockDI;
8
use AnaxMocks\MockPage;
9
10
/**
11
 * Test JsonController for Weather.
12
 */
13
class JsonControllerTest extends TestCase
14
{
15
    /**
16
     * Subject under test.
17
     *
18
     * @var JsonController
19
     */
20
    private $sut;
21
22
    /**
23
     * DI container / Service Locator mock.
24
     *
25
     * @var MockDI
26
     */
27
    private $di;
28
29
    /**
30
     * Setup before each test.
31
     *
32
     * @return void
33
     */
34
    public function setUp()
35
    {
36
        $this->di = new MockDI();
37
        $this->sut = new JsonController();
38
        $this->sut->setDI($this->di);
39
    }
40
41
    /**
42
     * Test the route "doc" (GET).
43
     */
44
    public function testDocAction()
45
    {
46
        $page = new MockPage();
47
48
        $this->di->set("page", $page);
49
        
50
51
        $result = $this->sut->docActionGet();
52
53
        $this->assertInternalType("array", $result->args);
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

53
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType("array", $result->args);

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...
54
        $this->assertArrayHasKey("title", $result->args);
55
        $this->assertInternalType("string", $result->args["title"]);
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

55
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType("string", $result->args["title"]);

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...
56
        $this->assertNotEmpty($result->adds);
57
    }
58
59
    /**
60
     * Test the "renderPage" method.
61
     * No errors.
62
     */
63
    public function testRenderPage()
64
    {
65
        $argSearch = [];
66
        $argResult = [
67
            [
68
                "currently" => [
69
                    "summary" => "test",
70
                    "precipProbability" => 1,
71
                    "temperature" => 1,
72
                    "apparentTemperature" => 1,
73
                    "windSpeed" => 1,
74
                    "windGust" => 1
75
                ],
76
                "hourly" => [
77
                    "summary" => "test",
78
                    "data" => [
79
                        [
80
                            "time" => 1576249313,
81
                            "summary" => "test",
82
                            "precipProbability" => 1,
83
                            "temperature" => 1,
84
                            "apparentTemperature" => 1,
85
                            "windSpeed" => 1,
86
                            "windGust" => 1
87
                        ]
88
                    ]
89
                ],
90
                "daily" => [
91
                    "summary" => "test",
92
                    "data" => [
93
                        [
94
                            "time" => 1576249313,
95
                            "summary" => "test",
96
                            "precipProbability" => 1,
97
                            "temperatureMin" => 1,
98
                            "temperatureMax" => 1,
99
                            "apparentTemperatureMin" => 1,
100
                            "apparentTemperatureMax" => 1,
101
                            "windSpeed" => 1,
102
                            "windGust" => 1
103
                        ]
104
                    ]
105
                ],
106
            ],
107
            [
108
                "daily" => [
109
                    "data" => [
110
                        [
111
                            "time" => 1576249313,
112
                            "summary" => "test",
113
                            "precipProbability" => 1,
114
                            "temperatureMin" => 1,
115
                            "temperatureMax" => 1,
116
                            "apparentTemperatureMin" => 1,
117
                            "apparentTemperatureMax" => 1,
118
                            "windSpeed" => 1,
119
                            "windGust" => 1
120
                        ]
121
                    ]
122
                ]
123
            ]
124
        ];
125
        $argMapLink = "test";
126
        $argError = "";
127
128
        $result = $this->sut->renderPage($argSearch, $argResult, $argMapLink, $argError);
129
130
        $this->assertInternalType("array", $result);
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

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

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...
131
        $this->assertInternalType("array", $result[0]);
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

131
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType("array", $result[0]);

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...
132
        $this->assertArrayHasKey("forecast", $result[0]);
133
        $this->assertArrayHasKey("historical", $result[0]);
134
        $this->assertArrayHasKey("poweredBy", $result[0]);
135
    }
136
137
    /**
138
     * Test the "renderPage" method.
139
     * With errors.
140
     *
141
     * @return void
142
     */
143
    public function testRenderPageError()
144
    {
145
        $result = $this->sut->renderPage([], [], "test", "test");
146
147
        $this->assertInternalType("array", $result);
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

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

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...
148
        $this->assertInternalType("array", $result[0]);
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

148
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType("array", $result[0]);

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...
149
        $this->assertArrayHasKey("error", $result[0]);
150
        $this->assertEquals("test", $result[0]["error"]);
151
    }
152
}
153