Skip to content

Commit ae1fca2

Browse files
authored
Merge pull request #2 from IonBazan/bugfix/platform-versions
fix parsing platform versions as they may contain the constraints there
2 parents e6703e6 + 124cbec commit ae1fca2

File tree

6 files changed

+42
-20
lines changed

6 files changed

+42
-20
lines changed

src/Command/DiffCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ protected function configure()
6262
*/
6363
protected function execute(InputInterface $input, OutputInterface $output)
6464
{
65-
$base = $input->getArgument('base') !== null ? $input->getArgument('base') : $input->getOption('base');
66-
$target = $input->getArgument('target') !== null ? $input->getArgument('target') :$input->getOption('target');
65+
$base = null !== $input->getArgument('base') ? $input->getArgument('base') : $input->getOption('base');
66+
$target = null !== $input->getArgument('target') ? $input->getArgument('target') : $input->getOption('target');
6767
$withPlatform = $input->getOption('with-platform');
6868
$withUrls = $input->getOption('with-links');
6969
$this->gitlabDomains = array_merge($this->gitlabDomains, $input->getOption('gitlab-domains'));

src/Formatter/AbstractFormatter.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Composer\Semver\VersionParser;
1212
use IonBazan\ComposerDiff\Url\GeneratorContainer;
1313
use Symfony\Component\Console\Output\OutputInterface;
14+
use UnexpectedValueException;
1415

1516
abstract class AbstractFormatter implements Formatter
1617
{
@@ -80,9 +81,12 @@ private function getReleaseUrl(PackageInterface $package)
8081
protected static function isUpgrade(UpdateOperation $operation)
8182
{
8283
$versionParser = new VersionParser();
83-
$normalizedFrom = $versionParser->normalize($operation->getInitialPackage()->getVersion());
84-
$normalizedTo = $versionParser->normalize($operation->getTargetPackage()->getVersion());
85-
84+
try {
85+
$normalizedFrom = $versionParser->normalize($operation->getInitialPackage()->getVersion());
86+
$normalizedTo = $versionParser->normalize($operation->getTargetPackage()->getVersion());
87+
} catch (UnexpectedValueException $e) {
88+
return true; // Consider as upgrade if versions are not parsable
89+
}
8690
$sorted = Semver::sort(array($normalizedTo, $normalizedFrom));
8791

8892
return $sorted[0] === $normalizedFrom;

tests/Formatter/FormatterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function testItRendersTheListOfOperations($withUrls)
4747
new UpdateOperation($this->getPackage('a/package-2', '1.0.0'), $this->getPackage('a/package-2', '1.2.0')),
4848
new UpdateOperation($this->getPackage('a/package-3', '2.0.0'), $this->getPackage('a/package-3', '1.1.1')),
4949
new UpdateOperation($this->getPackage('a/no-link-2', '2.0.0'), $this->getPackage('a/no-link-2', '1.1.1')),
50+
new UpdateOperation($this->getPackage('php', '>=7.4.6'), $this->getPackage('php', '^8.0')),
5051
);
5152
$devPackages = array(
5253
new UpdateOperation($this->getPackage('a/package-5', 'dev-master', 'dev-master 1234567'), $this->getPackage('a/package-5', '1.1.1')),
@@ -114,7 +115,7 @@ protected function getGenerators()
114115
->getMock();
115116
$generators->method('get')
116117
->willReturnCallback(function (PackageInterface $package) use ($generator) {
117-
if (false !== strpos($package->getName(), 'a/no-link')) {
118+
if ('php' === $package->getName() || false !== strpos($package->getName(), 'a/no-link')) {
118119
return null;
119120
}
120121

tests/Formatter/JsonFormatterTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ protected function getSampleOutput($withUrls)
121121
'version_target' => '1.1.1',
122122
'compare' => null,
123123
),
124+
'php' => array(
125+
'name' => 'php',
126+
'operation' => 'upgrade',
127+
'version_base' => '>=7.4.6',
128+
'version_target' => '^8.0',
129+
'compare' => null,
130+
),
124131
),
125132
'packages-dev' => array(
126133
'a/package-5' => array(
@@ -180,6 +187,12 @@ protected function getSampleOutput($withUrls)
180187
'version_base' => '2.0.0',
181188
'version_target' => '1.1.1',
182189
),
190+
'php' => array(
191+
'name' => 'php',
192+
'operation' => 'upgrade',
193+
'version_base' => '>=7.4.6',
194+
'version_target' => '^8.0',
195+
),
183196
),
184197
'packages-dev' => array(
185198
'a/package-5' => array(

tests/Formatter/MarkdownListFormatterTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ protected function getSampleOutput($withUrls)
2020
- Upgrade a/package-2 (1.0.0 => 1.2.0) [Compare](https://example.com/c/1.0.0..1.2.0)
2121
- Downgrade a/package-3 (2.0.0 => 1.1.1) [Compare](https://example.com/c/2.0.0..1.1.1)
2222
- Downgrade a/no-link-2 (2.0.0 => 1.1.1)
23+
- Upgrade php (>=7.4.6 => ^8.0)
2324
2425
Dev Packages
2526
============
@@ -41,6 +42,7 @@ protected function getSampleOutput($withUrls)
4142
- Upgrade a/package-2 (1.0.0 => 1.2.0)
4243
- Downgrade a/package-3 (2.0.0 => 1.1.1)
4344
- Downgrade a/no-link-2 (2.0.0 => 1.1.1)
45+
- Upgrade php (>=7.4.6 => ^8.0)
4446
4547
Dev Packages
4648
============

tests/Formatter/MarkdownTableFormatterTest.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ protected function getSampleOutput($withUrls)
1212
{
1313
if ($withUrls) {
1414
return <<<OUTPUT
15-
| Prod Packages | Operation | Base | Target | Link |
16-
|---------------|------------|-------|--------|-----------------------------------------------|
17-
| a/package-1 | New | - | 1.0.0 | [Compare](https://example.com/r/1.0.0) |
18-
| a/no-link-1 | New | - | 1.0.0 | |
19-
| a/package-2 | Upgraded | 1.0.0 | 1.2.0 | [Compare](https://example.com/c/1.0.0..1.2.0) |
20-
| a/package-3 | Downgraded | 2.0.0 | 1.1.1 | [Compare](https://example.com/c/2.0.0..1.1.1) |
21-
| a/no-link-2 | Downgraded | 2.0.0 | 1.1.1 | |
15+
| Prod Packages | Operation | Base | Target | Link |
16+
|---------------|------------|---------|--------|-----------------------------------------------|
17+
| a/package-1 | New | - | 1.0.0 | [Compare](https://example.com/r/1.0.0) |
18+
| a/no-link-1 | New | - | 1.0.0 | |
19+
| a/package-2 | Upgraded | 1.0.0 | 1.2.0 | [Compare](https://example.com/c/1.0.0..1.2.0) |
20+
| a/package-3 | Downgraded | 2.0.0 | 1.1.1 | [Compare](https://example.com/c/2.0.0..1.1.1) |
21+
| a/no-link-2 | Downgraded | 2.0.0 | 1.1.1 | |
22+
| php | Upgraded | >=7.4.6 | ^8.0 | |
2223
2324
| Dev Packages | Operation | Base | Target | Link |
2425
|--------------|------------|--------------------|--------|----------------------------------------------------|
@@ -31,13 +32,14 @@ protected function getSampleOutput($withUrls)
3132
}
3233

3334
return <<<OUTPUT
34-
| Prod Packages | Operation | Base | Target |
35-
|---------------|------------|-------|--------|
36-
| a/package-1 | New | - | 1.0.0 |
37-
| a/no-link-1 | New | - | 1.0.0 |
38-
| a/package-2 | Upgraded | 1.0.0 | 1.2.0 |
39-
| a/package-3 | Downgraded | 2.0.0 | 1.1.1 |
40-
| a/no-link-2 | Downgraded | 2.0.0 | 1.1.1 |
35+
| Prod Packages | Operation | Base | Target |
36+
|---------------|------------|---------|--------|
37+
| a/package-1 | New | - | 1.0.0 |
38+
| a/no-link-1 | New | - | 1.0.0 |
39+
| a/package-2 | Upgraded | 1.0.0 | 1.2.0 |
40+
| a/package-3 | Downgraded | 2.0.0 | 1.1.1 |
41+
| a/no-link-2 | Downgraded | 2.0.0 | 1.1.1 |
42+
| php | Upgraded | >=7.4.6 | ^8.0 |
4143
4244
| Dev Packages | Operation | Base | Target |
4345
|--------------|------------|--------------------|--------|

0 commit comments

Comments
 (0)