Skip to content

Commit fa42b7c

Browse files
committed
Merge pull request #92 from FriendsOfSymfony/process
Start Varnish through Process component
2 parents 99fa173 + 346a679 commit fa42b7c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"require-dev": {
2929
"guzzle/plugin-mock": "*",
3030
"mockery/mockery": "*",
31-
"monolog/monolog": "*"
31+
"monolog/monolog": "*",
32+
"symfony/process": "~2.3"
3233
},
3334
"suggest": {
3435
"monolog/monolog": "For logging issues while invalidating"

tests/VarnishTestCase.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace FOS\HttpCache\Tests;
1313

1414
use FOS\HttpCache\ProxyClient\Varnish;
15+
use Symfony\Component\Process\Process;
1516

1617
/**
1718
* A phpunit base class to write functional tests with varnish.
@@ -143,7 +144,8 @@ protected function tearDown()
143144
protected function stopVarnish()
144145
{
145146
if (file_exists(self::PID)) {
146-
exec('kill -9 ' . file_get_contents(self::PID));
147+
$process = new Process('kill -9 ' . file_get_contents(self::PID));
148+
$process->run(); // Ignore if command fails when Varnish wasn't running
147149
unlink(self::PID);
148150
$this->waitUntil('127.0.0.1', $this->getCachingProxyPort(), 2000);
149151
}
@@ -154,14 +156,20 @@ protected function stopVarnish()
154156
*/
155157
protected function startVarnish()
156158
{
157-
exec($this->getBinary() .
159+
$cmd = $this->getBinary() .
158160
' -a 127.0.0.1:' . $this->getCachingProxyPort() .
159161
' -T 127.0.0.1:' . $this->getVarnishMgmtPort() .
160162
' -f ' . $this->getConfigFile() .
161163
' -n ' . $this->getCacheDir() .
162164
' -p vcl_dir=' . $this->getConfigDir() .
163-
' -P ' . self::PID
164-
);
165+
' -P ' . self::PID;
166+
167+
$process = new Process($cmd);
168+
$process->run();
169+
170+
if (!$process->isSuccessful()) {
171+
throw new \RuntimeException($process->getErrorOutput());
172+
}
165173

166174
$this->waitFor('127.0.0.1', $this->getCachingProxyPort(), 2000);
167175
}

0 commit comments

Comments
 (0)