Skip to content

Commit 5af38a1

Browse files
author
Kopylova,Olga(okopylova)
committed
Merge pull request #3 from magento-ogre/MAGETWO-41177-one-algorithm
Added NEW_VERSIONS to the result of info command
2 parents cf0e8f8 + 716e782 commit 5af38a1

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magento/composer",
33
"description": "Magento composer library helps to instantiate Composer application and run composer commands.",
44
"type": "library",
5-
"version": "1.0.0",
5+
"version": "1.0.1",
66
"license": [
77
"OSL-3.0",
88
"AFL-3.0"

src/InfoCommand.php

Lines changed: 19 additions & 1 deletion
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
@@ -85,10 +90,11 @@ public function run($package, $installed = false)
8590
private function extractVersions($packageInfo)
8691
{
8792
$versions = explode(', ', $packageInfo[self::VERSIONS]);
93+
$packageInfo[self::NEW_VERSIONS] = [];
94+
$packageInfo[self::AVAILABLE_VERSIONS] = [];
8895

8996
if (count($versions) === 1) {
9097
$packageInfo[self::CURRENT_VERSION] = str_replace('* ', '', $packageInfo[self::VERSIONS]);
91-
$packageInfo[self::AVAILABLE_VERSIONS] = [];
9298
} else {
9399
$currentVersion = array_values(preg_grep("/^\*.*/", $versions));
94100
if ($currentVersion) {
@@ -100,6 +106,18 @@ private function extractVersions($packageInfo)
100106
$packageInfo[self::AVAILABLE_VERSIONS] = array_values(preg_grep("/^\*.*/", $versions, PREG_GREP_INVERT));
101107
}
102108

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

tests/Composer/InfoCommandTest.php

Lines changed: 9 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,9 @@ public function getCommandOutputDataProvider()
123128
'1.0.0',
124129
'1.1.0',
125130
'1.2.0'
131+
],
132+
'new_versions' => [
133+
'1.2.0'
126134
]
127135
]
128136
],

0 commit comments

Comments
 (0)