Skip to content

Commit 060ca17

Browse files
committed
Merge pull request #115 from FriendsOfSymfony/nginx-cache-dir
Make Nginx cache dir optional
2 parents c5046ba + fbca68f commit 060ca17

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

phpunit.xml.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
<php>
2727
<const name="NGINX_FILE" value="./tests/Functional/Fixtures/nginx/fos.conf" />
28-
<const name="NGINX_CACHE_PATH" value="/tmp/fos_nginx_cache/" />
2928
<const name="WEB_SERVER_HOSTNAME" value="localhost" />
3029
<const name="WEB_SERVER_PORT" value="8080" />
3130
<const name="WEB_SERVER_DOCROOT" value="./tests/Functional/Fixtures/web" />

src/Test/NginxTestCase.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,11 @@ protected function getCachingProxyPort()
8282
}
8383

8484
/**
85-
* Get NGINX cache path
85+
* Get Nginx cache directory
8686
*/
8787
protected function getCacheDir()
8888
{
89-
if (!defined('NGINX_CACHE_PATH')) {
90-
throw new \Exception('Specify the NGINX_CACHE_PATH in phpunit.xml or override getCacheDir()');
91-
}
92-
93-
return NGINX_CACHE_PATH;
89+
return defined('NGINX_CACHE_PATH') ? NGINX_CACHE_PATH : null;
9490
}
9591

9692
/**
@@ -100,6 +96,7 @@ protected function getProxy()
10096
{
10197
if (null === $this->proxy) {
10298
$this->proxy = new NginxProxy($this->getConfigFile());
99+
$this->proxy->setPort($this->getCachingProxyPort());
103100

104101
if ($this->getBinary()) {
105102
$this->proxy->setBinary($this->getBinary());
@@ -108,10 +105,6 @@ protected function getProxy()
108105
if ($this->getCacheDir()) {
109106
$this->proxy->setCacheDir($this->getCacheDir());
110107
}
111-
112-
if ($this->getCachingProxyPort()) {
113-
$this->proxy->setPort($this->getCachingProxyPort());
114-
}
115108
}
116109

117110
return $this->proxy;
@@ -120,11 +113,11 @@ protected function getProxy()
120113
/**
121114
* Get proxy client
122115
*
123-
* @param bool|string $purgeLocation Optional purgeLocation
116+
* @param string $purgeLocation Optional purgeLocation
124117
*
125-
* @return \FOS\HttpCache\ProxyClient\Nginx
118+
* @return Nginx
126119
*/
127-
protected function getProxyClient($purgeLocation = false)
120+
protected function getProxyClient($purgeLocation = '')
128121
{
129122
if (null === $this->proxyClient) {
130123
$this->proxyClient = new Nginx(

src/Test/Proxy/NginxProxy.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ class NginxProxy extends Abstractproxy
1919
protected $pid = '/tmp/foshttpcache-nginx.pid';
2020
protected $cacheDir;
2121

22+
/**
23+
* Constructor
24+
*
25+
* @param string $configFile Path to Nginx configuration file
26+
*/
2227
public function __construct($configFile)
2328
{
2429
$this->setConfigFile($configFile);
30+
$this->setCacheDir(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'foshttpcache-nginx');
2531
}
2632

2733
/**

src/Test/Proxy/VarnishProxy.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ class VarnishProxy extends AbstractProxy
3131
*/
3232
public function __construct($configFile)
3333
{
34-
$this->cacheDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'foshttpcache-test';
35-
3634
$this->setConfigFile($configFile);
35+
$this->setCacheDir(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'foshttpcache-varnish');
3736
}
3837

3938
/**

tests/Functional/Fixtures/nginx/fos.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ http {
1414
error_log /tmp/fos_nginx_error.log debug;
1515
access_log /tmp/fos_nginx_access.log proxy_cache;
1616

17-
proxy_cache_path /tmp/fos_nginx_cache keys_zone=FOS_CACHE:10m;
17+
proxy_cache_path /tmp/foshttpcache-nginx keys_zone=FOS_CACHE:10m;
1818

1919
# Add an HTTP header with the cache status. Required for FOSHttpCache tests.
2020
add_header X-Cache $upstream_cache_status;

0 commit comments

Comments
 (0)