Skip to content

Commit

Permalink
Merge pull request #2 from IonBazan/bugfix/platform-versions
Browse files Browse the repository at this point in the history
fix parsing platform versions as they may contain the constraints there
  • Loading branch information
IonBazan authored Apr 22, 2021
2 parents e6703e6 + 124cbec commit ae1fca2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/Command/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$base = $input->getArgument('base') !== null ? $input->getArgument('base') : $input->getOption('base');
$target = $input->getArgument('target') !== null ? $input->getArgument('target') :$input->getOption('target');
$base = null !== $input->getArgument('base') ? $input->getArgument('base') : $input->getOption('base');
$target = null !== $input->getArgument('target') ? $input->getArgument('target') : $input->getOption('target');
$withPlatform = $input->getOption('with-platform');
$withUrls = $input->getOption('with-links');
$this->gitlabDomains = array_merge($this->gitlabDomains, $input->getOption('gitlab-domains'));
Expand Down
10 changes: 7 additions & 3 deletions src/Formatter/AbstractFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Composer\Semver\VersionParser;
use IonBazan\ComposerDiff\Url\GeneratorContainer;
use Symfony\Component\Console\Output\OutputInterface;
use UnexpectedValueException;

abstract class AbstractFormatter implements Formatter
{
Expand Down Expand Up @@ -80,9 +81,12 @@ private function getReleaseUrl(PackageInterface $package)
protected static function isUpgrade(UpdateOperation $operation)
{
$versionParser = new VersionParser();
$normalizedFrom = $versionParser->normalize($operation->getInitialPackage()->getVersion());
$normalizedTo = $versionParser->normalize($operation->getTargetPackage()->getVersion());

try {
$normalizedFrom = $versionParser->normalize($operation->getInitialPackage()->getVersion());
$normalizedTo = $versionParser->normalize($operation->getTargetPackage()->getVersion());
} catch (UnexpectedValueException $e) {
return true; // Consider as upgrade if versions are not parsable
}
$sorted = Semver::sort(array($normalizedTo, $normalizedFrom));

return $sorted[0] === $normalizedFrom;
Expand Down
3 changes: 2 additions & 1 deletion tests/Formatter/FormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function testItRendersTheListOfOperations($withUrls)
new UpdateOperation($this->getPackage('a/package-2', '1.0.0'), $this->getPackage('a/package-2', '1.2.0')),
new UpdateOperation($this->getPackage('a/package-3', '2.0.0'), $this->getPackage('a/package-3', '1.1.1')),
new UpdateOperation($this->getPackage('a/no-link-2', '2.0.0'), $this->getPackage('a/no-link-2', '1.1.1')),
new UpdateOperation($this->getPackage('php', '>=7.4.6'), $this->getPackage('php', '^8.0')),
);
$devPackages = array(
new UpdateOperation($this->getPackage('a/package-5', 'dev-master', 'dev-master 1234567'), $this->getPackage('a/package-5', '1.1.1')),
Expand Down Expand Up @@ -114,7 +115,7 @@ protected function getGenerators()
->getMock();
$generators->method('get')
->willReturnCallback(function (PackageInterface $package) use ($generator) {
if (false !== strpos($package->getName(), 'a/no-link')) {
if ('php' === $package->getName() || false !== strpos($package->getName(), 'a/no-link')) {
return null;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Formatter/JsonFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ protected function getSampleOutput($withUrls)
'version_target' => '1.1.1',
'compare' => null,
),
'php' => array(
'name' => 'php',
'operation' => 'upgrade',
'version_base' => '>=7.4.6',
'version_target' => '^8.0',
'compare' => null,
),
),
'packages-dev' => array(
'a/package-5' => array(
Expand Down Expand Up @@ -180,6 +187,12 @@ protected function getSampleOutput($withUrls)
'version_base' => '2.0.0',
'version_target' => '1.1.1',
),
'php' => array(
'name' => 'php',
'operation' => 'upgrade',
'version_base' => '>=7.4.6',
'version_target' => '^8.0',
),
),
'packages-dev' => array(
'a/package-5' => array(
Expand Down
2 changes: 2 additions & 0 deletions tests/Formatter/MarkdownListFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protected function getSampleOutput($withUrls)
- Upgrade a/package-2 (1.0.0 => 1.2.0) [Compare](https://example.com/c/1.0.0..1.2.0)
- Downgrade a/package-3 (2.0.0 => 1.1.1) [Compare](https://example.com/c/2.0.0..1.1.1)
- Downgrade a/no-link-2 (2.0.0 => 1.1.1)
- Upgrade php (>=7.4.6 => ^8.0)
Dev Packages
============
Expand All @@ -41,6 +42,7 @@ protected function getSampleOutput($withUrls)
- Upgrade a/package-2 (1.0.0 => 1.2.0)
- Downgrade a/package-3 (2.0.0 => 1.1.1)
- Downgrade a/no-link-2 (2.0.0 => 1.1.1)
- Upgrade php (>=7.4.6 => ^8.0)
Dev Packages
============
Expand Down
30 changes: 16 additions & 14 deletions tests/Formatter/MarkdownTableFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ protected function getSampleOutput($withUrls)
{
if ($withUrls) {
return <<<OUTPUT
| Prod Packages | Operation | Base | Target | Link |
|---------------|------------|-------|--------|-----------------------------------------------|
| a/package-1 | New | - | 1.0.0 | [Compare](https://example.com/r/1.0.0) |
| a/no-link-1 | New | - | 1.0.0 | |
| a/package-2 | Upgraded | 1.0.0 | 1.2.0 | [Compare](https://example.com/c/1.0.0..1.2.0) |
| a/package-3 | Downgraded | 2.0.0 | 1.1.1 | [Compare](https://example.com/c/2.0.0..1.1.1) |
| a/no-link-2 | Downgraded | 2.0.0 | 1.1.1 | |
| Prod Packages | Operation | Base | Target | Link |
|---------------|------------|---------|--------|-----------------------------------------------|
| a/package-1 | New | - | 1.0.0 | [Compare](https://example.com/r/1.0.0) |
| a/no-link-1 | New | - | 1.0.0 | |
| a/package-2 | Upgraded | 1.0.0 | 1.2.0 | [Compare](https://example.com/c/1.0.0..1.2.0) |
| a/package-3 | Downgraded | 2.0.0 | 1.1.1 | [Compare](https://example.com/c/2.0.0..1.1.1) |
| a/no-link-2 | Downgraded | 2.0.0 | 1.1.1 | |
| php | Upgraded | >=7.4.6 | ^8.0 | |
| Dev Packages | Operation | Base | Target | Link |
|--------------|------------|--------------------|--------|----------------------------------------------------|
Expand All @@ -31,13 +32,14 @@ protected function getSampleOutput($withUrls)
}

return <<<OUTPUT
| Prod Packages | Operation | Base | Target |
|---------------|------------|-------|--------|
| a/package-1 | New | - | 1.0.0 |
| a/no-link-1 | New | - | 1.0.0 |
| a/package-2 | Upgraded | 1.0.0 | 1.2.0 |
| a/package-3 | Downgraded | 2.0.0 | 1.1.1 |
| a/no-link-2 | Downgraded | 2.0.0 | 1.1.1 |
| Prod Packages | Operation | Base | Target |
|---------------|------------|---------|--------|
| a/package-1 | New | - | 1.0.0 |
| a/no-link-1 | New | - | 1.0.0 |
| a/package-2 | Upgraded | 1.0.0 | 1.2.0 |
| a/package-3 | Downgraded | 2.0.0 | 1.1.1 |
| a/no-link-2 | Downgraded | 2.0.0 | 1.1.1 |
| php | Upgraded | >=7.4.6 | ^8.0 |
| Dev Packages | Operation | Base | Target |
|--------------|------------|--------------------|--------|
Expand Down

0 comments on commit ae1fca2

Please sign in to comment.