Skip to content

Commit 12e3984

Browse files
authored
Remove JBZoo/Utils from PHP deps (composer.json) (#6)
* `jbzoo/utils` is used only as dev requirement. * Fixed PHP dependencies conflict in CI
1 parent 9e34db1 commit 12e3984

File tree

6 files changed

+76
-8
lines changed

6 files changed

+76
-8
lines changed

.phan/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
'src',
2121

2222
'vendor/jbzoo/data/src',
23-
'vendor/jbzoo/utils/src',
2423
'vendor/symfony/console',
24+
'vendor/symfony/process',
2525
'vendor/composer/semver/src',
2626
]
2727
]);

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@
2424
"ext-filter" : "*",
2525

2626
"jbzoo/data" : "^4.1.3",
27-
"jbzoo/utils" : "^4.2.3",
2827
"symfony/console" : ">=4.4",
2928
"symfony/process" : ">=4.4",
3029
"composer/semver" : ">=1.0"
3130
},
3231

3332
"require-dev" : {
34-
"jbzoo/toolbox-dev" : "^2.6.2"
33+
"jbzoo/utils" : "^4.2.3",
34+
"jbzoo/phpunit" : "^4.6.2",
35+
"jbzoo/codestyle" : "^2.10.0",
36+
"jbzoo/toolbox-ci" : "^1.3.5",
37+
"symfony/var-dumper" : "^4.4|^5.2.5",
38+
"php-coveralls/php-coveralls" : "^2.4.3"
3539
},
3640

3741
"autoload" : {

src/Comparator.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
namespace JBZoo\ComposerDiff;
1717

18-
use JBZoo\Utils\Cli;
18+
use Symfony\Component\Process\Exception\ProcessFailedException;
19+
use Symfony\Component\Process\Process;
1920

2021
use function JBZoo\Data\json;
2122

@@ -96,16 +97,33 @@ private static function load(string $composerFile): ComposerLock
9697
) {
9798
throw new Exception("There is no stream wrapper to open \"{$composerFile}\"");
9899
}
100+
99101
if (file_exists($composerFile)) {
100102
$json = json(file_get_contents($composerFile));
101103
return new ComposerLock($json->getArrayCopy());
102104
}
103105

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

109111
throw new Exception("Composer lock file \"{$composerFile}\" not found");
110112
}
113+
114+
/**
115+
* @param string $command
116+
* @return string
117+
*/
118+
private static function exec(string $command): string
119+
{
120+
$process = Process::fromShellCommandline($command);
121+
$process->run();
122+
123+
if ($process->isSuccessful()) {
124+
return $process->getOutput();
125+
}
126+
127+
throw new ProcessFailedException($process);
128+
}
111129
}

tests/ComposerDiffTest.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
use JBZoo\ComposerDiff\Comparator;
2020
use JBZoo\ComposerDiff\Diff;
2121
use JBZoo\ComposerDiff\Url;
22-
use JBZoo\ToolboxCI\Commands\Convert;
23-
use JBZoo\ToolboxCI\Commands\ConvertMap;
2422
use JBZoo\Utils\Cli;
2523
use JBZoo\Utils\Sys;
2624
use Symfony\Component\Console\Application;
2725
use Symfony\Component\Console\Input\StringInput;
2826
use Symfony\Component\Console\Output\BufferedOutput;
27+
use Symfony\Component\Process\Exception\ProcessFailedException;
2928

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

534+
public function testComparingWithGitVersionPositive()
535+
{
536+
$output = $this->task([
537+
'source' => 'HEAD:tests/fixtures/testComparingWithGitVersionPositive/composer-from-lock.json',
538+
'target' => __DIR__ . '/fixtures/testComparingWithGitVersionPositive/composer-to-lock.json'
539+
]);
540+
541+
isSame(implode("\n", [
542+
'There is no difference (require)',
543+
'There is no difference (require-dev)'
544+
]), trim($output));
545+
}
546+
547+
public function testComparingWithGitVersionNegative()
548+
{
549+
$this->expectException(ProcessFailedException::class);
550+
551+
// File not found in git!
552+
$this->taskReal(['source' => 'HEAD:invalid_path/composer.lock']);
553+
}
554+
535555
#### Testing Tools /////////////////////////////////////////////////////////////////////////////////////////////////
536556

537557
/**
@@ -554,7 +574,7 @@ private function toArray(array $fullDiff)
554574
}
555575

556576
/**
557-
* @param array $params
577+
* @param array $params
558578
* @return string
559579
* @throws \Exception
560580
*/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"packages" : [
3+
{
4+
"name" : "vendor-1/package-1",
5+
"version" : "1.0.0",
6+
"source" : {
7+
"type" : "git",
8+
"url" : "[email protected]:vendor-1/package-1.git",
9+
"reference" : "4121ea4a825bbc0fba999014432ff2f928045a3e"
10+
}
11+
}
12+
]
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"packages" : [
3+
{
4+
"name" : "vendor-1/package-1",
5+
"version" : "1.0.0",
6+
"source" : {
7+
"type" : "git",
8+
"url" : "[email protected]:vendor-1/package-1.git",
9+
"reference" : "4121ea4a825bbc0fba999014432ff2f928045a3e"
10+
}
11+
}
12+
]
13+
}

0 commit comments

Comments
 (0)