Skip to content

Commit

Permalink
Merge pull request #19 from IonBazan/debug
Browse files Browse the repository at this point in the history
improve git error logging and fix deprecations
  • Loading branch information
IonBazan authored Apr 20, 2022
2 parents 7500fe0 + 8e6ad97 commit 87063f9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/PackageDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ private function getFileContents($path)

$output = array();
@exec(sprintf('git show %s 2>&1', escapeshellarg($path)), $output, $exit);
$outputString = implode("\n", $output);

if (0 !== $exit) {
throw new \RuntimeException(sprintf('Could not open file %s or find it in git as %s', $originalPath, $path));
throw new \RuntimeException(sprintf('Could not open file %s or find it in git as %s: %s', $originalPath, $path, $outputString));
}

return implode("\n", $output);
return $outputString;
}
}
2 changes: 1 addition & 1 deletion src/Url/GitGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class GitGenerator implements UrlGenerator
*/
public function supportsPackage(PackageInterface $package)
{
return false !== strpos($package->getSourceUrl(), $this->getDomain());
return false !== strpos((string) $package->getSourceUrl(), $this->getDomain());
}

/**
Expand Down
11 changes: 9 additions & 2 deletions tests/Command/DiffCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Composer\DependencyResolver\Operation\UninstallOperation;
use Composer\DependencyResolver\Operation\UpdateOperation;
use IonBazan\ComposerDiff\Command\DiffCommand;
use IonBazan\ComposerDiff\Tests\Integration\ComposerApplication;
use IonBazan\ComposerDiff\Tests\TestCase;
use Symfony\Component\Console\Tester\CommandTester;

Expand All @@ -20,7 +21,10 @@ class DiffCommandTest extends TestCase
public function testItGeneratesReportInGivenFormat($expectedOutput, array $options)
{
$diff = $this->getMockBuilder('IonBazan\ComposerDiff\PackageDiff')->getMock();
$tester = new CommandTester(new DiffCommand($diff, array('gitlab2.org')));
$application = new ComposerApplication();
$command = new DiffCommand($diff, array('gitlab2.org'));
$command->setApplication($application);
$tester = new CommandTester($command);
$diff->expects($this->once())
->method('getPackageDiff')
->with($this->isType('string'), $this->isType('string'), false, false)
Expand Down Expand Up @@ -49,7 +53,10 @@ public function testItGeneratesReportInGivenFormat($expectedOutput, array $optio
public function testStrictMode($exitCode, array $prodOperations, array $devOperations)
{
$diff = $this->getMockBuilder('IonBazan\ComposerDiff\PackageDiff')->getMock();
$tester = new CommandTester(new DiffCommand($diff, array('gitlab2.org')));
$application = new ComposerApplication();
$command = new DiffCommand($diff, array('gitlab2.org'));
$command->setApplication($application);
$tester = new CommandTester($command);
$diff->expects($this->exactly(2))
->method('getPackageDiff')
->with($this->isType('string'), $this->isType('string'), $this->isType('boolean'), false)
Expand Down
5 changes: 4 additions & 1 deletion tests/Integration/DiffCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class DiffCommandTest extends TestCase
*/
public function testCommand($expectedOutput, array $input)
{
$tester = new CommandTester(new DiffCommand(new PackageDiff()));
$application = new ComposerApplication();
$command = new DiffCommand(new PackageDiff());
$command->setApplication($application);
$tester = new CommandTester($command);
$result = $tester->execute($input);
$this->assertSame(0, $result);
$this->assertSame($expectedOutput, $tester->getDisplay());
Expand Down

0 comments on commit 87063f9

Please sign in to comment.