|
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\ProxyClient\HttpDispatcher; |
|
15
|
|
|
use FOS\HttpCache\ProxyClient\LiteSpeed; |
|
16
|
|
|
use FOS\HttpCache\Test\Proxy\LiteSpeedProxy; |
|
17
|
|
|
|
|
18
|
|
|
// TODO: update docs in case anything is configurable |
|
19
|
|
|
/** |
|
20
|
|
|
* Starts and clears the LiteSpeed proxy between tests. |
|
21
|
|
|
*/ |
|
22
|
|
|
trait LiteSpeedTest |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var LiteSpeed |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $proxyClient; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var LiteSpeedProxy |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $proxy; |
|
33
|
|
|
|
|
34
|
|
|
protected function setUp() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->getProxy()->clear(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
protected function tearDown() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->getProxy()->stop(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Defaults to "lswsctrl". |
|
46
|
|
|
* |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function getBinary() |
|
50
|
|
|
{ |
|
51
|
|
|
return defined('LITESPEED_BINARY') ? LITESPEED_BINARY : null; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Defaults to 80. |
|
56
|
|
|
* |
|
57
|
|
|
* @return int |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function getCachingProxyPort() |
|
60
|
|
|
{ |
|
61
|
|
|
return defined('LITESPEED_PORT') ? LITESPEED_PORT : 80; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get the hostname where your application can be reached. |
|
66
|
|
|
* |
|
67
|
|
|
* @throws \Exception |
|
68
|
|
|
* |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function getHostName() |
|
72
|
|
|
{ |
|
73
|
|
|
// @codeCoverageIgnoreStart |
|
74
|
|
|
if (!defined('WEB_SERVER_HOSTNAME')) { |
|
75
|
|
|
throw new \Exception( |
|
76
|
|
|
'To use this test, you need to define the WEB_SERVER_HOSTNAME constant in your phpunit.xml' |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
// @codeCoverageIgnoreEnd |
|
80
|
|
|
|
|
81
|
|
|
return WEB_SERVER_HOSTNAME; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return LiteSpeedProxy |
|
86
|
|
|
*/ |
|
87
|
|
|
protected function getProxy() |
|
88
|
|
|
{ |
|
89
|
|
|
if (null === $this->proxy) { |
|
90
|
|
|
$this->proxy = new LiteSpeedProxy(); |
|
91
|
|
|
$this->proxy->setPort($this->getCachingProxyPort()); |
|
92
|
|
|
|
|
93
|
|
|
if ($this->getBinary()) { |
|
94
|
|
|
$this->proxy->setBinary($this->getBinary()); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $this->proxy; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get proxy client. |
|
103
|
|
|
* |
|
104
|
|
|
* @return LiteSpeed |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function getProxyClient($purgeLocation = '') |
|
|
|
|
|
|
107
|
|
|
{ |
|
108
|
|
|
if (null === $this->proxyClient) { |
|
109
|
|
|
$httpDispatcher = new HttpDispatcher( |
|
110
|
|
|
['http://127.0.0.1:8080'] |
|
111
|
|
|
); |
|
112
|
|
|
|
|
113
|
|
|
$this->proxyClient = new LiteSpeed($httpDispatcher, [ |
|
114
|
|
|
'document_root' => '/usr/local/lsws/DEFAULT/html', // TODO |
|
115
|
|
|
]); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
return $this->proxyClient; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.