1 | <?php |
||
46 | trait VarnishTest |
||
47 | { |
||
48 | /** |
||
49 | * @var VarnishProxy |
||
50 | */ |
||
51 | protected $proxy; |
||
52 | |||
53 | /** |
||
54 | * @var Varnish |
||
55 | */ |
||
56 | protected $proxyClient; |
||
57 | |||
58 | /** |
||
59 | * Start Varnish and discard any cached content |
||
60 | */ |
||
61 | 23 | protected function setUp() |
|
65 | |||
66 | /** |
||
67 | * Stop Varnish |
||
68 | */ |
||
69 | 23 | protected function tearDown() |
|
73 | |||
74 | /** |
||
75 | * The default implementation looks at the constant VARNISH_FILE. |
||
76 | * |
||
77 | * @throws \Exception |
||
78 | * |
||
79 | * @return string the path to the varnish server configuration file to use with this test. |
||
80 | */ |
||
81 | 10 | protected function getConfigFile() |
|
82 | { |
||
83 | 10 | if (!defined('VARNISH_FILE')) { |
|
84 | throw new \Exception( |
||
85 | 'Specify the varnish configuration file path in phpunit.xml or override getConfigFile()' |
||
86 | ); |
||
87 | } |
||
88 | |||
89 | 10 | return VARNISH_FILE; |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * Get Varnish binary |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | 23 | protected function getBinary() |
|
101 | |||
102 | /** |
||
103 | * Get Varnish port |
||
104 | * |
||
105 | * @return int |
||
106 | */ |
||
107 | 23 | protected function getCachingProxyPort() |
|
111 | |||
112 | /** |
||
113 | * Get Varnish management port |
||
114 | * |
||
115 | * @return int |
||
116 | */ |
||
117 | 23 | protected function getVarnishMgmtPort() |
|
121 | |||
122 | /** |
||
123 | * Get Varnish cache directory |
||
124 | * |
||
125 | * @return string |
||
126 | */ |
||
127 | 23 | protected function getCacheDir() |
|
131 | |||
132 | /** |
||
133 | * Defaults to 4 |
||
134 | * |
||
135 | * @return int |
||
136 | */ |
||
137 | 13 | protected function getVarnishVersion() |
|
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | 23 | protected function getProxy() |
|
168 | |||
169 | /** |
||
170 | * Get Varnish proxy client |
||
171 | * |
||
172 | * @return Varnish |
||
173 | */ |
||
174 | 2 | protected function getProxyClient() |
|
175 | { |
||
176 | 2 | if (null === $this->proxyClient) { |
|
177 | 2 | $this->proxyClient = new Varnish( |
|
178 | 2 | ['http://127.0.0.1:' . $this->getProxy()->getPort()], |
|
179 | 2 | ['base_uri' => $this->getHostName() . ':' . $this->getProxy()->getPort()] |
|
180 | 2 | ); |
|
181 | } |
||
182 | |||
183 | return $this->proxyClient; |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * Get the hostname where your application can be reached |
||
188 | * |
||
189 | * @throws \Exception |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | 22 | protected function getHostName() |
|
203 | } |
||
204 |