Skip to content

Commit 34bf5f2

Browse files
author
Ivan Gavryshko
committed
MAGETWO-41177: Consolidate one algorithm for populating system packages for upgrade and other tasks
- added new_version to InfoCommand
1 parent c2bc8f4 commit 34bf5f2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/InfoCommand.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class InfoCommand
2323
*/
2424
const AVAILABLE_VERSIONS = 'available_versions';
2525

26+
/**
27+
* New versions
28+
*/
29+
const NEW_VERSIONS = 'new_versions';
30+
2631

2732
/**
2833
* @var MagentoComposerApplication
@@ -100,6 +105,21 @@ private function extractVersions($packageInfo)
100105
$packageInfo[self::AVAILABLE_VERSIONS] = array_values(preg_grep("/^\*.*/", $versions, PREG_GREP_INVERT));
101106
}
102107

108+
if (count($packageInfo[self::AVAILABLE_VERSIONS]) > 0) {
109+
if ($packageInfo[self::CURRENT_VERSION]) {
110+
foreach ($packageInfo[self::AVAILABLE_VERSIONS] as $version) {
111+
if (version_compare($packageInfo[self::CURRENT_VERSION], $version, '<')) {
112+
$packageInfo[self::NEW_VERSIONS][] = $version;
113+
}
114+
}
115+
$packageInfo[self::NEW_VERSIONS][] = $packageInfo[self::CURRENT_VERSION];
116+
} else {
117+
$packageInfo[self::NEW_VERSIONS] = $packageInfo[self::AVAILABLE_VERSIONS];
118+
}
119+
} else {
120+
$packageInfo[self::NEW_VERSIONS] = [];
121+
}
122+
103123
return $packageInfo;
104124
}
105125
}

tests/Composer/InfoCommandTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public function testRunInstalled()
6161
'type' => 'library',
6262
'names' => '3rdp/a',
6363
'current_version' => '1.0.0',
64-
'available_versions' => []
64+
'available_versions' => [],
65+
'new_versions' => []
6566
],
6667
$result
6768
);
@@ -97,6 +98,10 @@ public function getCommandOutputDataProvider()
9798
'available_versions' => [
9899
'1.0.0',
99100
'1.1.0'
101+
],
102+
'new_versions' => [
103+
'1.0.0',
104+
'1.1.0'
100105
]
101106
]
102107
],
@@ -123,6 +128,10 @@ public function getCommandOutputDataProvider()
123128
'1.0.0',
124129
'1.1.0',
125130
'1.2.0'
131+
],
132+
'new_versions' => [
133+
'1.2.0',
134+
'1.1.2'
126135
]
127136
]
128137
],

0 commit comments

Comments
 (0)