1818namespace Codeception \Extension ;
1919
2020use Symfony \Component \Process \Process ;
21- use Symfony \Component \Process \ProcessBuilder ;
2221
2322/**
2423 * Manages the current running WireMock process.
@@ -37,11 +36,6 @@ class PhiremockProcess
3736 */
3837 private $ process ;
3938
40- /**
41- * @var resource[]
42- */
43- private $ pipes ;
44-
4539 /**
4640 * Starts a wiremock process.
4741 *
@@ -53,37 +47,44 @@ class PhiremockProcess
5347 */
5448 public function start ($ ip , $ port , $ path , $ logsPath , $ debug )
5549 {
56- $ builder = new ProcessBuilder (['-i ' , $ ip , '-p ' , $ port ]);
50+ $ phiremockPath = is_file ($ path ) ? $ path : "{$ path }/phiremock " ;
51+ $ this ->process = new Process (
52+ $ this ->getCommandPrefix ()
53+ . "{$ phiremockPath } -i {$ ip } -p {$ port }"
54+ . ($ debug ? ' -d ' : '' )
55+ );
5756 if ($ debug ) {
58- $ builder -> add ( ' -d ' ) ;
57+ echo ' Executing: ' . $ this -> process -> getCommandLine () . PHP_EOL ;
5958 }
60- $ builder ->setPrefix ("{$ path }/phiremock " );
61- $ builder ->enableOutput ();
62- $ builder ->setOption ('bypass_shell ' , true );
63-
64- $ this ->process = $ builder ->getProcess ();
6559 $ logFile = $ logsPath . DIRECTORY_SEPARATOR . self ::LOG_FILE_NAME ;
6660 $ this ->process ->start (function ($ type , $ buffer ) use ($ logFile ) {
6761 file_put_contents ($ logFile , $ buffer , FILE_APPEND );
6862 });
63+ $ this ->process ->setEnhanceSigchildCompatibility (true );
64+ if ($ this ->isWindows ()) {
65+ $ this ->process ->setEnhanceWindowsCompatibility (true );
66+ }
6967 }
7068
7169 /**
7270 * Stops the process.
7371 */
7472 public function stop ()
7573 {
76- $ this ->process ->stop (3 , SIGTERM );
74+ $ this ->process ->signal (SIGTERM );
75+ $ this ->process ->stop (3 , SIGKILL );
7776 }
7877
7978 /**
8079 * @return string
8180 */
8281 private function getCommandPrefix ()
8382 {
84- if (PHP_OS == 'WIN32 ' || PHP_OS == 'WINNT ' || PHP_OS == 'Windows ' ) {
85- return '' ;
86- }
87- return 'exec ' ;
83+ return $ this ->isWindows () ? '' : 'exec ' ;
84+ }
85+
86+ private function isWindows ()
87+ {
88+ return PHP_OS == 'WIN32 ' || PHP_OS == 'WINNT ' || PHP_OS == 'Windows ' ;
8889 }
8990}
0 commit comments