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
2 changes: 1 addition & 1 deletion .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
'src',

'vendor/jbzoo/data/src',
'vendor/jbzoo/utils/src',
'vendor/symfony/console',
'vendor/symfony/process',
'vendor/composer/semver/src',
]
]);
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@
"ext-filter" : "*",

"jbzoo/data" : "^4.1.3",
"jbzoo/utils" : "^4.2.3",
"symfony/console" : ">=4.4",
"symfony/process" : ">=4.4",
"composer/semver" : ">=1.0"
},

"require-dev" : {
"jbzoo/toolbox-dev" : "^2.6.2"
"jbzoo/utils" : "^4.2.3",
"jbzoo/phpunit" : "^4.6.2",
"jbzoo/codestyle" : "^2.10.0",
"jbzoo/toolbox-ci" : "^1.3.5",
"symfony/var-dumper" : "^4.4|^5.2.5",
"php-coveralls/php-coveralls" : "^2.4.3"
},

"autoload" : {
Expand Down
22 changes: 20 additions & 2 deletions src/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

namespace JBZoo\ComposerDiff;

use JBZoo\Utils\Cli;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

use function JBZoo\Data\json;

Expand Down Expand Up @@ -96,16 +97,33 @@ private static function load(string $composerFile): ComposerLock
) {
throw new Exception("There is no stream wrapper to open \"{$composerFile}\"");
}

if (file_exists($composerFile)) {
$json = json(file_get_contents($composerFile));
return new ComposerLock($json->getArrayCopy());
}

if (strpos($composerFile, ':') !== false) {
$json = json(Cli::exec('git show ' . escapeshellarg($composerFile)));
$json = json(self::exec('git show ' . escapeshellarg($composerFile)));
return new ComposerLock($json->getArrayCopy());
}

throw new Exception("Composer lock file \"{$composerFile}\" not found");
}

/**
* @param string $command
* @return string
*/
private static function exec(string $command): string
{
$process = Process::fromShellCommandline($command);
$process->run();

if ($process->isSuccessful()) {
return $process->getOutput();
}

throw new ProcessFailedException($process);
}
}
26 changes: 23 additions & 3 deletions tests/ComposerDiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
use JBZoo\ComposerDiff\Comparator;
use JBZoo\ComposerDiff\Diff;
use JBZoo\ComposerDiff\Url;
use JBZoo\ToolboxCI\Commands\Convert;
use JBZoo\ToolboxCI\Commands\ConvertMap;
use JBZoo\Utils\Cli;
use JBZoo\Utils\Sys;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Process\Exception\ProcessFailedException;

use function JBZoo\Data\json;
use function JBZoo\Data\phpArray;
Expand Down Expand Up @@ -532,6 +531,27 @@ public function testHelpInReadme()
isContain("```\n./vendor/bin/composer-diff --help\n\n{$helpOutput}\n```", $readmeContent);
}

public function testComparingWithGitVersionPositive()
{
$output = $this->task([
'source' => 'HEAD:tests/fixtures/testComparingWithGitVersionPositive/composer-from-lock.json',
'target' => __DIR__ . '/fixtures/testComparingWithGitVersionPositive/composer-to-lock.json'
]);

isSame(implode("\n", [
'There is no difference (require)',
'There is no difference (require-dev)'
]), trim($output));
}

public function testComparingWithGitVersionNegative()
{
$this->expectException(ProcessFailedException::class);

// File not found in git!
$this->taskReal(['source' => 'HEAD:invalid_path/composer.lock']);
}

#### Testing Tools /////////////////////////////////////////////////////////////////////////////////////////////////

/**
Expand All @@ -554,7 +574,7 @@ private function toArray(array $fullDiff)
}

/**
* @param array $params
* @param array $params
* @return string
* @throws \Exception
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"packages" : [
{
"name" : "vendor-1/package-1",
"version" : "1.0.0",
"source" : {
"type" : "git",
"url" : "git@gitlab.com:vendor-1/package-1.git",
"reference" : "4121ea4a825bbc0fba999014432ff2f928045a3e"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"packages" : [
{
"name" : "vendor-1/package-1",
"version" : "1.0.0",
"source" : {
"type" : "git",
"url" : "git@gitlab.com:vendor-1/package-1.git",
"reference" : "4121ea4a825bbc0fba999014432ff2f928045a3e"
}
}
]
}