From c4bf3b458384049cc6ff36c8919f95244d3a908e Mon Sep 17 00:00:00 2001 From: Ion Bazan <ion.bazan@gmail.com> Date: Thu, 21 Apr 2022 00:10:48 +0800 Subject: [PATCH 1/2] improve git error logging and fix deprecations --- src/PackageDiff.php | 5 +++-- src/Url/GitGenerator.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/PackageDiff.php b/src/PackageDiff.php index fc4691f..301b490 100644 --- a/src/PackageDiff.php +++ b/src/PackageDiff.php @@ -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; } } diff --git a/src/Url/GitGenerator.php b/src/Url/GitGenerator.php index 5aa4b68..5b0f722 100644 --- a/src/Url/GitGenerator.php +++ b/src/Url/GitGenerator.php @@ -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()); } /** From 8e6ad97c07bb060dd4fd04e141b1c1dba31e903b Mon Sep 17 00:00:00 2001 From: Ion Bazan <ion.bazan@gmail.com> Date: Thu, 21 Apr 2022 00:37:37 +0800 Subject: [PATCH 2/2] fix test --- tests/Command/DiffCommandTest.php | 11 +++++++++-- tests/Integration/DiffCommandTest.php | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/Command/DiffCommandTest.php b/tests/Command/DiffCommandTest.php index f672348..ad40b31 100644 --- a/tests/Command/DiffCommandTest.php +++ b/tests/Command/DiffCommandTest.php @@ -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; @@ -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) @@ -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) diff --git a/tests/Integration/DiffCommandTest.php b/tests/Integration/DiffCommandTest.php index 43bacc6..71e6cc3 100644 --- a/tests/Integration/DiffCommandTest.php +++ b/tests/Integration/DiffCommandTest.php @@ -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());