Skip to content

Commit 8d2530a

Browse files
committed
wip
1 parent 6b03b19 commit 8d2530a

3 files changed

Lines changed: 27 additions & 9 deletions

File tree

tests/Util/RemoteWorker.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
use PHPUnit\Framework\Assert;
1010
use Symfony\Component\Process\InputStream;
1111
use Symfony\Component\Process\Process;
12+
use Throwable;
1213

14+
use function dirname;
1315
use function explode;
16+
use function extension_loaded;
1417
use function implode;
1518
use function json_encode;
1619
use 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
}

tests/Util/worker.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414
use Brick\Lock\Tests\Util\LockDriverFactoryException;
1515

1616
use function Opis\Closure\unserialize;
17+
use function pcov\collect;
18+
use function pcov\start;
19+
use function pcov\stop;
20+
21+
use const pcov\all;
1722

1823
require __DIR__ . '/../../vendor/autoload.php';
1924

2025
if (extension_loaded('pcov')) {
21-
\pcov\start();
22-
$pcovSrcDir = dirname(__DIR__, 2) . '/src';
23-
register_shutdown_function(function () use ($pcovSrcDir): void {
24-
\pcov\stop();
25-
$coverage = \pcov\collect(\pcov\inclusive, [$pcovSrcDir]);
26+
start();
27+
register_shutdown_function(function (): void {
28+
stop();
29+
$coverage = collect(all);
2630
file_put_contents(
2731
sys_get_temp_dir() . '/brick-lock-worker-coverage-' . getmypid() . '.bin',
2832
serialize($coverage),

tools/merge-coverage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
}
3636

3737
$rawData = RawCodeCoverageData::fromXdebugWithoutPathCoverage($workerData);
38-
$coverage->append($rawData, basename($file, '.bin'), linesToBeCovered: false);
38+
$coverage->append($rawData, basename($file, '.bin'));
3939

4040
unlink($file);
4141
}

0 commit comments

Comments
 (0)