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\Legacy; |
13
|
|
|
|
14
|
|
|
use FOS\HttpCache\Test\WebServerListenerTrait; |
15
|
|
|
use PHPUnit\Framework\TestListener; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* A PHPUnit test listener that starts and stops the PHP built-in web server. |
19
|
|
|
* |
20
|
|
|
* This listener is configured with a couple of constants from the phpunit.xml |
21
|
|
|
* file. To define constants in the phpunit file, use this syntax: |
22
|
|
|
* <php> |
23
|
|
|
* <const name="WEB_SERVER_HOSTNAME" value="localhost" /> |
24
|
|
|
* </php> |
25
|
|
|
* |
26
|
|
|
* WEB_SERVER_HOSTNAME host name of the web server (required) |
27
|
|
|
* WEB_SERVER_PORT port to listen on (required) |
28
|
|
|
* WEB_SERVER_DOCROOT path to the document root for the server (required) |
29
|
|
|
*/ |
30
|
|
View Code Duplication |
class WebServerListener implements TestListener |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
/** @var WebServerListenerTrait */ |
33
|
|
|
private $trait; |
34
|
|
|
|
35
|
|
|
public function __construct() |
36
|
|
|
{ |
37
|
|
|
$this->trait = new WebServerListenerTrait(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Make sure the PHP built-in web server is running for tests with group |
42
|
|
|
* 'webserver'. |
43
|
|
|
*/ |
44
|
|
|
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite) |
45
|
|
|
{ |
46
|
|
|
$this->trait->startTestSuite($suite); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* We don't need these. |
51
|
|
|
*/ |
52
|
|
|
public function endTestSuite(\PHPUnit_Framework_TestSuite $suite) |
53
|
|
|
{ |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time) |
57
|
|
|
{ |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time) |
61
|
|
|
{ |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function addIncompleteTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) |
65
|
|
|
{ |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) |
69
|
|
|
{ |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function startTest(\PHPUnit_Framework_Test $test) |
73
|
|
|
{ |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function endTest(\PHPUnit_Framework_Test $test, $time) |
77
|
|
|
{ |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function addRiskyTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) |
81
|
|
|
{ |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get web server hostname. |
86
|
|
|
* |
87
|
|
|
* @throws \Exception |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
protected function getHostName() |
92
|
|
|
{ |
93
|
|
|
return $this->trait->getHostName(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get web server port. |
98
|
|
|
* |
99
|
|
|
* @throws \Exception |
100
|
|
|
* |
101
|
|
|
* @return int |
102
|
|
|
*/ |
103
|
|
|
protected function getPort() |
104
|
|
|
{ |
105
|
|
|
return $this->trait->getPort(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Get web server port. |
110
|
|
|
* |
111
|
|
|
* @throws \Exception |
112
|
|
|
* |
113
|
|
|
* @return int |
114
|
|
|
*/ |
115
|
|
|
protected function getDocRoot() |
116
|
|
|
{ |
117
|
|
|
return $this->trait->getDocRoot(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Start PHP built-in web server. |
122
|
|
|
* |
123
|
|
|
* @return int PID |
124
|
|
|
*/ |
125
|
|
|
protected function startPhpWebServer() |
126
|
|
|
{ |
127
|
|
|
return $this->trait->startPhpWebServer(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Wait for caching proxy to be started up and reachable. |
132
|
|
|
* |
133
|
|
|
* @param string $ip |
134
|
|
|
* @param int $port |
135
|
|
|
* @param int $timeout Timeout in milliseconds |
136
|
|
|
* |
137
|
|
|
* @throws \RuntimeException If proxy is not reachable within timeout |
138
|
|
|
*/ |
139
|
|
|
protected function waitFor($ip, $port, $timeout) |
140
|
|
|
{ |
141
|
|
|
$this->trait->waitFor($ip, $port, $timeout); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|