From 346a679ae065b7994971be80e334b09e400fffa4 Mon Sep 17 00:00:00 2001 From: David de Boer Date: Fri, 20 Jun 2014 12:53:18 +0200 Subject: [PATCH] Start Varnish through Process component (fix #85) --- composer.json | 3 ++- tests/VarnishTestCase.php | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 2040802c..5376e81f 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "require-dev": { "guzzle/plugin-mock": "*", "mockery/mockery": "*", - "monolog/monolog": "*" + "monolog/monolog": "*", + "symfony/process": "~2.3" }, "suggest": { "monolog/monolog": "For logging issues while invalidating" diff --git a/tests/VarnishTestCase.php b/tests/VarnishTestCase.php index ebd85809..b020a554 100644 --- a/tests/VarnishTestCase.php +++ b/tests/VarnishTestCase.php @@ -12,6 +12,7 @@ namespace FOS\HttpCache\Tests; use FOS\HttpCache\ProxyClient\Varnish; +use Symfony\Component\Process\Process; /** * A phpunit base class to write functional tests with varnish. @@ -143,7 +144,8 @@ protected function tearDown() protected function stopVarnish() { if (file_exists(self::PID)) { - exec('kill -9 ' . file_get_contents(self::PID)); + $process = new Process('kill -9 ' . file_get_contents(self::PID)); + $process->run(); // Ignore if command fails when Varnish wasn't running unlink(self::PID); $this->waitUntil('127.0.0.1', $this->getCachingProxyPort(), 2000); } @@ -154,14 +156,20 @@ protected function stopVarnish() */ protected function startVarnish() { - exec($this->getBinary() . + $cmd = $this->getBinary() . ' -a 127.0.0.1:' . $this->getCachingProxyPort() . ' -T 127.0.0.1:' . $this->getVarnishMgmtPort() . ' -f ' . $this->getConfigFile() . ' -n ' . $this->getCacheDir() . ' -p vcl_dir=' . $this->getConfigDir() . - ' -P ' . self::PID - ); + ' -P ' . self::PID; + + $process = new Process($cmd); + $process->run(); + + if (!$process->isSuccessful()) { + throw new \RuntimeException($process->getErrorOutput()); + } $this->waitFor('127.0.0.1', $this->getCachingProxyPort(), 2000); }