99use PHPUnit \Framework \Assert ;
1010use Symfony \Component \Process \InputStream ;
1111use Symfony \Component \Process \Process ;
12+ use Throwable ;
1213
14+ use function dirname ;
1315use function explode ;
16+ use function extension_loaded ;
1417use function implode ;
1518use function json_encode ;
1619use function microtime ;
@@ -36,7 +39,18 @@ final class RemoteWorker
3639
3740 public function __construct ()
3841 {
39- $ this ->process = new Process (['php ' , 'worker.php ' ], __DIR__ );
42+ $ command = ['php ' ];
43+
44+ if (extension_loaded ('pcov ' )) {
45+ // pcov.directory defaults to the process CWD (tests/Util/), which excludes src/.
46+ // Set it explicitly so pcov tracks the library source files.
47+ $ command [] = '-d ' ;
48+ $ command [] = 'pcov.directory= ' . dirname (__DIR__ , 2 ) . '/src ' ;
49+ }
50+
51+ $ command [] = 'worker.php ' ;
52+
53+ $ this ->process = new Process ($ command , __DIR__ );
4054 $ this ->input = new InputStream ();
4155
4256 $ this ->process ->setInput ($ this ->input );
@@ -235,14 +249,14 @@ private function parseDuration(string $duration): float
235249
236250 public function __destruct ()
237251 {
238- if (!$ this ->isKilled && $ this ->process ->isRunning ()) {
252+ if (! $ this ->isKilled && $ this ->process ->isRunning ()) {
239253 try {
240254 $ this ->sendCommand (new Command \Shutdown ());
241255 $ deadline = microtime (true ) + 1.0 ;
242256 while ($ this ->process ->isRunning () && microtime (true ) < $ deadline ) {
243257 usleep (10_000 );
244258 }
245- } catch (\ Throwable ) {
259+ } catch (Throwable ) {
246260 // Best effort; fall through to stop().
247261 }
248262 }
0 commit comments