WebServerListener::getHostName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCache package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCache\Test;
13
14
use FOS\HttpCache\Test\Legacy\WebServerListener6;
15
use PHPUnit\Framework\AssertionFailedError;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\AssertionFailedError 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...
16
use PHPUnit\Framework\Test;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\Test 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...
17
use PHPUnit\Framework\TestListener as TestListenerInterface;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestListener 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...
18
use PHPUnit\Framework\TestSuite;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestSuite 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...
19
use PHPUnit\Framework\Warning;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\Warning 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...
20
use PHPUnit\Runner\Version;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Runner\Version 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...
21
22
if (class_exists(\PHPUnit_Runner_Version::class) && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
0 ignored issues
show
Bug introduced by
The type PHPUnit_Runner_Version 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...
23
    /*
24
     * Using an early return instead of a else does not work when using the PHPUnit phar due to some weird PHP behavior
25
     * (the class gets defined without executing the code before it and so the definition is not properly conditional)
26
     */
27
    class_alias('FOS\HttpCache\Test\Legacy\WebServerListener', 'FOS\HttpCache\Test\WebServerListener');
28
} elseif (version_compare(Version::id(), '7.0.0', '<')) {
29
    class_alias(WebServerListener6::class, 'FOS\HttpCache\Test\WebServerListener');
30
} else {
31
    /**
32
     * A PHPUnit test listener that starts and stops the PHP built-in web server.
33
     *
34
     * This listener is configured with a couple of constants from the phpunit.xml
35
     * file. To define constants in the phpunit file, use this syntax:
36
     * <php>
37
     *     <const name="WEB_SERVER_HOSTNAME" value="localhost" />
38
     * </php>
39
     *
40
     * WEB_SERVER_HOSTNAME host name of the web server (required)
41
     * WEB_SERVER_PORT     port to listen on (required)
42
     * WEB_SERVER_DOCROOT  path to the document root for the server (required)
43
     */
44
    class WebServerListener implements TestListenerInterface
45
    {
46
        /** @var WebServerListenerTrait */
47
        private $trait;
48
49
        public function __construct()
50
        {
51
            $this->trait = new WebServerListenerTrait();
52
        }
53
54
        /**
55
         * Make sure the PHP built-in web server is running for tests with group
56
         * 'webserver'.
57
         */
58
        public function startTestSuite(TestSuite $suite): void
59
        {
60
            $this->trait->startTestSuite($suite);
61
        }
62
63
        /**
64
         *  We don't need these.
65
         */
66
        public function endTestSuite(TestSuite $suite): void
67
        {
68
        }
69
70
        public function addError(Test $test, \Throwable $e, float $time): void
71
        {
72
        }
73
74
        public function addFailure(Test $test, AssertionFailedError $e, float $time): void
75
        {
76
        }
77
78
        public function addIncompleteTest(Test $test, \Throwable $e, float $time): void
79
        {
80
        }
81
82
        public function addSkippedTest(Test $test, \Throwable $e, float $time): void
83
        {
84
        }
85
86
        public function startTest(Test $test): void
87
        {
88
        }
89
90
        public function endTest(Test $test, float $time): void
91
        {
92
        }
93
94
        public function addRiskyTest(Test $test, \Throwable $e, float $time): void
95
        {
96
        }
97
98
        public function addWarning(Test $test, Warning $e, float $time): void
99
        {
100
        }
101
102
        /**
103
         * Get web server hostname.
104
         *
105
         * @throws \Exception
106
         *
107
         * @return string
108
         */
109
        protected function getHostName()
110
        {
111
            return $this->trait->getHostName();
112
        }
113
114
        /**
115
         * Get web server port.
116
         *
117
         * @throws \Exception
118
         *
119
         * @return int
120
         */
121
        protected function getPort()
122
        {
123
            return $this->trait->getPort();
124
        }
125
126
        /**
127
         * Get web server port.
128
         *
129
         * @throws \Exception
130
         *
131
         * @return int
132
         */
133
        protected function getDocRoot()
134
        {
135
            return $this->trait->getDocRoot();
136
        }
137
138
        /**
139
         * Start PHP built-in web server.
140
         *
141
         * @return int PID
142
         */
143
        protected function startPhpWebServer()
144
        {
145
            return $this->trait->startPhpWebServer();
146
        }
147
148
        /**
149
         * Wait for caching proxy to be started up and reachable.
150
         *
151
         * @param string $ip
152
         * @param int    $port
153
         * @param int    $timeout Timeout in milliseconds
154
         *
155
         * @throws \RuntimeException If proxy is not reachable within timeout
156
         */
157
        protected function waitFor($ip, $port, $timeout)
158
        {
159
            $this->trait->waitFor($ip, $port, $timeout);
160
        }
161
    }
162
}
163