Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dev/src/Command/ComponentBreakingChangesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,12 @@ private function runRoave(string $workTree): array
$proc->setTimeout(600);
$proc->run();

return [0 !== $proc->getExitCode(), $proc->getOutput() . $proc->getErrorOutput()];
$lines = array_filter(
explode("\n", $proc->getOutput()),
fn(string $line) => str_starts_with($line, '::error')
);

return [0 !== $proc->getExitCode(), implode("\n", $lines) ?: trim($proc->getErrorOutput())];
}

private function commit(string $cwd, string $msg): void
Expand Down
31 changes: 31 additions & 0 deletions dev/tests/Unit/Command/ComponentBreakingChangesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,37 @@ public function testGaOnlyOptionFiltersOutPre10ComponentsWhenEnabled(): void
$this->assertSame(['google/beta'], $checked);
}

public function testFiltersRoaveOutputToOnlyBreakingChangeErrors(): void
{
$this->fs->dumpFile($this->rootDir . '/Alpha/src/Foo.php', '<?php class Foo { public function x(int $a) {} }');
$this->commitAll('break Alpha');

$binDir = $this->rootDir . '/bin';
$this->fs->mkdir($binDir);
$fakeRoave = $binDir . '/roave-backward-compatibility-check';
$this->fs->dumpFile($fakeRoave, <<<'SH'
#!/usr/bin/env bash
echo "No security vulnerability advisories found."
echo "::error file=/src/Foo.php,line=1,col=1::Method Foo#x() changed"
echo "#StandWithUkraine" >&2
echo "Installing dependencies from lock file" >&2
exit 3
SH);
$this->fs->chmod($fakeRoave, 0755);

$origPath = getenv('PATH');
putenv('PATH=' . $binDir . PATH_SEPARATOR . $origPath);
try {
$tester = new CommandTester(new ComponentBreakingChangesCommand($this->rootDir));
$code = $tester->execute(['--base-ref' => 'baseline'], ['capture_stderr_separately' => true]);
} finally {
putenv('PATH=' . $origPath);
}

$this->assertSame(Command::FAILURE, $code);
$this->assertSame("::error file=/src/Foo.php,line=1,col=1::Method Foo#x() changed\n", $tester->getDisplay());
}

public function testExpectBreakingChangesOptionAllowsPreGaWithGaOnlyAndFailsWhenNoBreaksDetected(): void
{
$this->fs->dumpFile($this->rootDir . '/Alpha/VERSION', "0.13.1\n");
Expand Down
Loading