Skip to content

Commit

Permalink
Add test_it_falls_back_to_direct_diff_if_merge_base_is_not_availabe
Browse files Browse the repository at this point in the history
  • Loading branch information
bdsl committed Jan 26, 2022
1 parent 2e73331 commit 7cb0702
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/phpunit/Logger/GitHub/GitDiffFileProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Infection\Logger\GitHub\GitDiffFileProvider;
use Infection\Logger\GitHub\NoFilesInDiffToMutate;
use Infection\Process\ShellCommandLineExecutor;
use Symfony\Component\Process\Exception\ProcessFailedException;
use const PHP_OS_FAMILY;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -87,6 +88,31 @@ public function test_it_executes_diff_and_returns_filter_as_a_string(): void
$this->assertSame('src/A.php,src/B.php', $filter);
}

public function test_it_falls_back_to_direct_diff_if_merge_base_is_not_availabe(): void
{
$expectedMergeBaseCommandLine = 'git merge-base \'master\' HEAD';
$shellCommandLineExecutor = $this->createMock(ShellCommandLineExecutor::class);
$expectedDiffCommandLine = 'git diff \'master\' --diff-filter=\'AM\' --name-only | grep src/ | paste -s -d "," -';

$shellCommandLineExecutor->expects($this->any())
->method('execute')
->willReturnCallback(function (string $command) use ($expectedDiffCommandLine, $expectedMergeBaseCommandLine): string {
switch ($command) {
case $expectedMergeBaseCommandLine:
throw $this->createStub(ProcessFailedException::class);
case $expectedDiffCommandLine:
return 'src/A.php,src/B.php';
default:
$this->fail("Unexpected shell command: $command");
}
});

$diffProvider = new GitDiffFileProvider($shellCommandLineExecutor);
$filter = $diffProvider->provide('AM', 'master');

$this->assertSame('src/A.php,src/B.php', $filter);
}

public function test_it_provides_lines_filter_as_a_string(): void
{
$expectedMergeBaseCommandLine = 'git merge-base \'master\' HEAD';
Expand Down

0 comments on commit 7cb0702

Please sign in to comment.