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

ValidateIpControllerTest::testIpv4Valid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
nc 1
nop 0
dl 0
loc 6
c 1
b 0
f 0
cc 1
rs 10
1
<?php
2
3
namespace Ylvan\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 SampleController.
10
 */
11
class ValidateIpControllerTest 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 ValidateIpController();
39
        $this->controller->setDI($this->di);
40
        //$this->controller->initialize();
41
    }
42
43
44
    /**
45
     * Test the route "index".
46
     */
47
    public function testIndexActionType()
48
    {
49
        $res = $this->controller->indexAction();
50
        // $this->assertInstanceOf("\Anax\Response\Response", $res);
51
52
        // $body = $res->getBody();
53
        // $exp = "Validera IP</title>";
54
        $this->assertIsObject($res);
55
    }
56
57
58
    /**
59
     * Test the ipv4 validation method.
60
     */
61
    public function testIpv4Invalid()
62
    {
63
        $controller = new ValidateIpController();
64
        // $controller->ipv4();
65
        $res = $controller->ipv4("invalid");
66
        $this->assertContains("Validerar ej", $res);
67
    }
68
69
70
    /**
71
     * Test the ipv4 validation method.
72
     */
73
    public function testIpv4Valid()
74
    {
75
        $controller = new ValidateIpController();
76
        // $controller->ipv4();
77
        $res = $controller->ipv4("8.8.8.8");
78
        $this->assertContains("Validerar", $res);
79
    }
80
81
82
    /**
83
     * Test the ipv4 validation method.
84
     */
85
    public function testIpv4Type()
86
    {
87
        $controller = new ValidateIpController();
88
        // $controller->ipv4();
89
        $res = $controller->ipv4("8.8.8.8");
90
        $this->assertIsString($res);
91
    }
92
93
94
    /**
95
     * Test the ipv6 validation method.
96
     */
97
    public function testIpv6Invalid()
98
    {
99
        $controller = new ValidateIpController();
100
        // $controller->ipv6();
101
        $res = $controller->ipv6("invalid");
102
        $this->assertContains("Validerar ej", $res);
103
    }
104
105
106
107
    /**
108
     * Test the ipv6 validation method.
109
     */
110
    public function testIpv6Valid()
111
    {
112
        $controller = new ValidateIpController();
113
        // $controller->ipv6();
114
        $res = $controller->ipv6("2001:4860:4860::8888");
115
        $this->assertContains("Validerar", $res);
116
    }
117
118
119
    /**
120
     * Test the ipv6 validation method.
121
     */
122
    public function testIpv6Type()
123
    {
124
        $controller = new ValidateIpController();
125
        // $controller->ipv6();
126
        $res = $controller->ipv6("2001:4860:4860::8888");
127
        $this->assertIsString($res);
128
    }
129
130
131
    /**
132
     * Test the domain name checker method.
133
     */
134
    public function testDomainNameInvalid()
135
    {
136
        $controller = new ValidateIpController();
137
        // $controller->domainName();
138
        $res = $controller->domainName("invalid");
139
        $this->assertContains("ip ej validerad", $res);
140
    }
141
142
143
    /**
144
     * Test the domain name checker method.
145
     */
146
    public function testDomainNameValid()
147
    {
148
        $controller = new ValidateIpController();
149
        // $controller->domainName();
150
        $res = $controller->domainName("8.8.8.8");
151
        $this->assertContains("dns.google", $res);
152
    }
153
154
155
    /**
156
     * Test the domain name checker method.
157
     */
158
    public function testDomainNameType()
159
    {
160
        $controller = new ValidateIpController();
161
        // $controller->domainName();
162
        $res = $controller->domainName("8.8.8.8");
163
        $this->assertIsString($res);
164
    }
165
}
166