1212namespace FOS \HttpCache \Tests ;
1313
1414use 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