Skip to content

Commit afe6a4f

Browse files
author
Ivan Gavryshko
committed
MAGETWO-40176: Show redundant version when checking component dependency in Magento component manager
- added tests - fixed bug - CR changes
1 parent e074ce3 commit afe6a4f

6 files changed

+240
-10
lines changed

src/InfoCommand.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
*/
1212
class InfoCommand
1313
{
14-
1514
/**
1615
* @var MagentoComposerApplication
1716
*/
@@ -32,10 +31,9 @@ public function __construct(MagentoComposerApplication $magentoComposerApplicati
3231
*
3332
* @param string $package
3433
* @param bool $installed
35-
* @param null $version
3634
* @return array|bool
3735
*/
38-
public function run($package, $installed = false, $version = null)
36+
public function run($package, $installed = false)
3937
{
4038
$commandParameters = [
4139
'command' => 'info',
@@ -60,7 +58,6 @@ public function run($package, $installed = false, $version = null)
6058
if (count($chunk) === 2) {
6159
$result[trim($chunk[0])] = trim($chunk[1]);
6260
}
63-
6461
}
6562

6663
$result = $this->extractVersions($result);
@@ -83,7 +80,12 @@ private function extractVersions($packageInfo)
8380
$packageInfo['available_versions'] = [];
8481
} else {
8582
$currentVersion = array_values(preg_grep("/^\*.*/", $versions));
86-
$packageInfo['current_version'] = str_replace('* ', '', $currentVersion[0]);
83+
if ($currentVersion) {
84+
$packageInfo['current_version'] = str_replace('* ', '', $currentVersion[0]);
85+
} else {
86+
$packageInfo['current_version'] = '';
87+
}
88+
8789
$packageInfo['available_versions'] = array_values(preg_grep("/^\*.*/", $versions, PREG_GREP_INVERT));
8890
}
8991

src/RequireUpdateDryRunCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
namespace Magento\Composer;
88

9-
9+
/**
10+
* Class RequireUpdateDryRunCommand calls composer require and update --dry-run commands
11+
*/
1012
class RequireUpdateDryRunCommand
1113
{
1214
/**
@@ -76,7 +78,6 @@ public function run($packages, $workingDir = null)
7678
*/
7779
protected function generateAdditionalErrorMessage($message, $inputPackages)
7880
{
79-
8081
$matches = [];
8182
$errorMessage = '';
8283
$packages = [];

tests/Composer/ConsoleArrayInputFactoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
use Magento\Composer\ConsoleArrayInputFactory;
88

9-
class ConsoleArrayInputFactoryTest extends PHPUnit_Framework_TestCase {
9+
class ConsoleArrayInputFactoryTest extends PHPUnit_Framework_TestCase
10+
{
1011

1112
/**
1213
* @var ConsoleArrayInputFactory

tests/Composer/InfoCommandTest.php

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Composer\MagentoComposerApplication;
8+
use Magento\Composer\InfoCommand;
9+
10+
class InfoCommandTest extends PHPUnit_Framework_TestCase
11+
{
12+
13+
private $installedOutput = 'name : 3rdp/a
14+
descrip. : Plugin project A
15+
keywords :
16+
versions : * 1.0.0
17+
type : library
18+
names : 3rdp/a
19+
20+
requires
21+
php >=5.4.11
22+
3rdp/c 1.1.0';
23+
24+
/**
25+
* @var MagentoComposerApplication|\PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
protected $application;
28+
29+
/**
30+
* @var InfoCommand
31+
*/
32+
protected $infoCommand;
33+
34+
protected function setUp()
35+
{
36+
$this->application = $this->getMock('Magento\Composer\MagentoComposerApplication', [], [], '', false, false);
37+
38+
$this->infoCommand = new InfoCommand($this->application);
39+
}
40+
41+
/**
42+
* @dataProvider getCommandOutputDataProvider
43+
*/
44+
public function testRun($input, $output)
45+
{
46+
$this->application->expects($this->once())->method('runComposerCommand')->willReturn($input);
47+
$result = $this->infoCommand->run('3rdp/a');
48+
$this->assertEquals($output, $result);
49+
}
50+
51+
public function testRunInstalled()
52+
{
53+
$this->application->expects($this->once())->method('runComposerCommand')->willReturn($this->installedOutput);
54+
$result = $this->infoCommand->run('3rdp/a', true);
55+
$this->assertEquals(
56+
[
57+
'name' => '3rdp/a',
58+
'descrip.' => 'Plugin project A',
59+
'versions' => '* 1.0.0',
60+
'keywords' => '',
61+
'type' => 'library',
62+
'names' => '3rdp/a',
63+
'current_version' => '1.0.0',
64+
'available_versions' => []
65+
],
66+
$result
67+
);
68+
}
69+
70+
/**
71+
* Data provider that returns different input and output for composer info command.
72+
*
73+
* @return array
74+
*/
75+
public function getCommandOutputDataProvider()
76+
{
77+
return [
78+
'Package not installed' => [
79+
'name : 3rdp/a
80+
descrip. : Plugin project A
81+
keywords :
82+
versions : 1.0.0, 1.1.0
83+
type : library
84+
names : 3rdp/a
85+
86+
requires
87+
php >=5.4.11
88+
3rdp/c 1.1.0',
89+
[
90+
'name' => '3rdp/a',
91+
'descrip.' => 'Plugin project A',
92+
'versions' => '1.0.0, 1.1.0',
93+
'keywords' => '',
94+
'type' => 'library',
95+
'names' => '3rdp/a',
96+
'current_version' => '',
97+
'available_versions' => [
98+
'1.0.0',
99+
'1.1.0'
100+
]
101+
]
102+
],
103+
'Package installed' => [
104+
'name : 3rdp/a
105+
descrip. : Plugin project A
106+
keywords :
107+
versions : 1.0.0, 1.1.0, * 1.1.2, 1.2.0
108+
type : library
109+
names : 3rdp/a
110+
111+
requires
112+
php >=5.4.11
113+
3rdp/c 1.1.0',
114+
[
115+
'name' => '3rdp/a',
116+
'descrip.' => 'Plugin project A',
117+
'versions' => '1.0.0, 1.1.0, * 1.1.2, 1.2.0',
118+
'keywords' => '',
119+
'type' => 'library',
120+
'names' => '3rdp/a',
121+
'current_version' => '1.1.2',
122+
'available_versions' => [
123+
'1.0.0',
124+
'1.1.0',
125+
'1.2.0'
126+
]
127+
]
128+
],
129+
];
130+
}
131+
}

tests/Composer/MagentoComposerApplicationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Magento\Composer\ConsoleArrayInputFactory;
1010
use Symfony\Component\Console\Output\BufferedOutput;
1111

12-
class MagentoComposerApplicationTest extends PHPUnit_Framework_TestCase {
13-
12+
class MagentoComposerApplicationTest extends PHPUnit_Framework_TestCase
13+
{
1414
/**
1515
* @var MagentoComposerApplication
1616
*/
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Composer\MagentoComposerApplication;
8+
use Magento\Composer\InfoCommand;
9+
use Magento\Composer\RequireUpdateDryRunCommand;
10+
11+
class RequireUpdateDryRunCommandTest extends PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var MagentoComposerApplication|\PHPUnit_Framework_MockObject_MockObject
15+
*/
16+
protected $application;
17+
18+
/**
19+
* @var InfoCommand|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $infoCommand;
22+
23+
/**
24+
* @var RequireUpdateDryRunCommand
25+
*/
26+
protected $requireUpdateDryRunCommand;
27+
28+
/**
29+
* @var string
30+
*/
31+
private $errorMessage = 'Loading composer repositories with package information
32+
Updating dependencies (including require-dev)
33+
Your requirements could not be resolved to an installable set of packages.
34+
35+
Problem 1
36+
- 3rdp/e 1.0.0 requires 3rdp/d 1.0.0 -> no matching package found.
37+
- 3rdp/e 1.0.0 requires 3rdp/d 1.0.0 -> no matching package found.
38+
- 3rdp/e 1.0.0 requires 3rdp/d 1.0.0 -> no matching package found.
39+
- Installation request for 3rdp/e 1.0.0 -> satisfiable by 3rdp/e[1.0.0].
40+
41+
Potential causes:
42+
- A typo in the package name
43+
- The package is not available in a stable-enough version according to your minimum-stability setting
44+
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
45+
46+
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.';
47+
48+
/**
49+
* @var string
50+
*/
51+
private $packageInfo = [
52+
'name' => '3rdp/d',
53+
'descrip.' => 'Plugin project A',
54+
'versions' => '* 1.0.0, 1.1.0, 1.2.0',
55+
'keywords' => '',
56+
'type' => 'library',
57+
'names' => '3rdp/d',
58+
'current_version' => '1.0.0',
59+
'available_versions' => [
60+
'1.1.0',
61+
'1.2.0'
62+
]
63+
];
64+
65+
protected function setUp()
66+
{
67+
$this->application = $this->getMock('Magento\Composer\MagentoComposerApplication', [], [], '', false, false);
68+
$this->infoCommand = $this->getMock('Magento\Composer\InfoCommand', [], [], '', false, false);
69+
70+
$this->requireUpdateDryRunCommand = new RequireUpdateDryRunCommand(
71+
$this->application,
72+
$this->infoCommand
73+
);
74+
}
75+
76+
public function testRun()
77+
{
78+
$this->application->expects($this->exactly(2))->method('runComposerCommand');
79+
$this->requireUpdateDryRunCommand->run([], '');
80+
}
81+
82+
/**
83+
* @expectedException \RuntimeException
84+
* @expectedExceptionMessage
85+
*/
86+
public function testRunException()
87+
{
88+
$this->application->expects($this->at(1))
89+
->method('runComposerCommand')
90+
->willThrowException(new \RuntimeException($this->errorMessage));
91+
$this->infoCommand->expects($this->once())->method('run')->willReturn($this->packageInfo);
92+
$this->requireUpdateDryRunCommand->run(['3rdp/e 1.2.0'], '');
93+
}
94+
95+
}

0 commit comments

Comments
 (0)