Skip to content

Commit 633ed60

Browse files
committed
Remove 'version' manipulation from composer.json
1 parent e0d650c commit 633ed60

File tree

4 files changed

+15
-117
lines changed

4 files changed

+15
-117
lines changed

app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -109,33 +109,6 @@ protected function configure()
109109
*/
110110
protected function execute(InputInterface $input, OutputInterface $output)
111111
{
112-
$rootJson = $this->serializer->unserialize(
113-
$this->filesystem->getDirectoryRead(
114-
DirectoryList::ROOT
115-
)->readFile("composer.json")
116-
);
117-
if (!isset($rootJson['version'])) {
118-
$magentoProductPackage = array_filter(
119-
$rootJson['require'],
120-
function ($package) {
121-
return false !== strpos($package, 'magento/product-');
122-
},
123-
ARRAY_FILTER_USE_KEY
124-
);
125-
$version = reset($magentoProductPackage);
126-
$output->writeln(
127-
'<info>' .
128-
// @codingStandardsIgnoreLine
129-
'We don\'t recommend to remove the "version" field from your composer.json; see https://getcomposer.org/doc/02-libraries.md#library-versioning for more information.' .
130-
'</info>'
131-
);
132-
$restoreVersion = new ArrayInput([
133-
'command' => 'config',
134-
'setting-key' => 'version',
135-
'setting-value' => [$version],
136-
'--quiet' => 1
137-
]);
138-
}
139112
$this->updateMemoryLimit();
140113
$this->createAuthFile();
141114
$sampleDataPackages = $this->sampleDataDependency->getSampleDataPackages();
@@ -156,12 +129,6 @@ function ($package) {
156129
/** @var Application $application */
157130
$application = $this->applicationFactory->create();
158131
$application->setAutoExit(false);
159-
if (!empty($restoreVersion)) {
160-
$result = $application->run($restoreVersion, clone $output);
161-
if ($result === 0) {
162-
$output->writeln('<info>The field "version" has been restored.</info>');
163-
}
164-
}
165132
$result = $application->run($commandInput, $output);
166133
if ($result !== 0) {
167134
$output->writeln(

app/code/Magento/SampleData/Test/Unit/Console/Command/AbstractSampleDataCommandTest.php

Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@
2626
*/
2727
abstract class AbstractSampleDataCommandTest extends TestCase
2828
{
29-
/*
30-
* Expected arguments for `composer config` to set missing field "version"
31-
*/
32-
private const STUB_EXPECTED_COMPOSER_CONFIG = [
33-
'command' => 'config',
34-
'setting-key' => 'version',
35-
'setting-value' => ['0.0.1'],
36-
'--quiet' => 1
37-
];
38-
3929
/**
4030
* @var ReadInterface|MockObject
4131
*/
@@ -118,49 +108,21 @@ protected function setupMocks(
118108
->willReturn($sampleDataPackages);
119109
$this->arrayInputFactoryMock->expects($this->never())->method('create');
120110

121-
if (!array_key_exists('version', $composerJsonContent)) {
122-
$this->applicationMock->expects($this->any())
123-
->method('run')
124-
->withConsecutive(
125-
[
126-
'input' => new ArrayInput(
127-
self::STUB_EXPECTED_COMPOSER_CONFIG
111+
$this->applicationMock->expects($this->any())
112+
->method('run')
113+
->with(
114+
new ArrayInput(
115+
array_merge(
116+
$this->expectedComposerArgumentsSampleDataCommands(
117+
$sampleDataPackages,
118+
$pathToComposerJson
128119
),
129-
'output' => $this->anything()
130-
],
131-
[
132-
'input' => new ArrayInput(
133-
array_merge(
134-
$this->expectedComposerArgumentsSampleDataCommands(
135-
$sampleDataPackages,
136-
$pathToComposerJson
137-
),
138-
$additionalComposerArgs
139-
)
140-
),
141-
'output' => $this->anything()
142-
]
143-
)->willReturnOnConsecutiveCalls(
144-
$this->returnValue(0),
145-
$this->returnValue($appRunResult)
146-
);
147-
} else {
148-
$this->applicationMock->expects($this->any())
149-
->method('run')
150-
->with(
151-
new ArrayInput(
152-
array_merge(
153-
$this->expectedComposerArgumentsSampleDataCommands(
154-
$sampleDataPackages,
155-
$pathToComposerJson
156-
),
157-
$additionalComposerArgs
158-
)
159-
),
160-
$this->anything()
161-
)
162-
->willReturn($appRunResult);
163-
}
120+
$additionalComposerArgs
121+
)
122+
),
123+
$this->anything()
124+
)
125+
->willReturn($appRunResult);
164126

165127
if (($appRunResult !== 0) && !empty($sampleDataPackages)) {
166128
$this->applicationMock->expects($this->any())

app/code/Magento/SampleData/Test/Unit/Console/Command/SampleDataDeployCommandTest.php

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ public function processDataProvider(): array
139139
'appRunResult' => 1,
140140
'composerJsonContent' => [
141141
'require' => ["magento/product-community-edition" => "0.0.1"],
142-
'version' => '0.0.1'
143142
],
144143
'expectedMsg' => 'There is no sample data for current set of modules.' . PHP_EOL,
145144
'authExist' => true,
@@ -151,33 +150,18 @@ public function processDataProvider(): array
151150
'appRunResult' => 1,
152151
'composerJsonContent' => [
153152
'require' => ["magento/product-community-edition" => "0.0.1"],
154-
'version' => '0.0.1'
155153
],
156154
'expectedMsg' => 'There is an error during sample data deployment. Composer file will be reverted.'
157155
. PHP_EOL,
158156
'authExist' => false,
159157
],
160-
'Successful sample data installation without field "version"' => [
161-
'sampleDataPackages' => [
162-
'magento/module-cms-sample-data' => '1.0.0-beta',
163-
],
164-
'appRunResult' => 0,
165-
'composerJsonContent' => [
166-
'require' => ["magento/product-community-edition" => "0.0.1"]
167-
],
168-
// @codingStandardsIgnoreLine
169-
'expectedMsg' => 'We don\'t recommend to remove the "version" field from your composer.json; see https://getcomposer.org/doc/02-libraries.md#library-versioning for more information.'
170-
. PHP_EOL . 'The field "version" has been restored.' . PHP_EOL,
171-
'authExist' => true,
172-
],
173158
'Successful sample data installation' => [
174159
'sampleDataPackages' => [
175160
'magento/module-cms-sample-data' => '1.0.0-beta',
176161
],
177162
'appRunResult' => 0,
178163
'composerJsonContent' => [
179164
'require' => ["magento/product-community-edition" => "0.0.1"],
180-
'version' => '0.0.1'
181165
],
182166
'expectedMsg' => '',
183167
'authExist' => true,
@@ -194,20 +178,7 @@ public function testExecuteWithException(): void
194178
$this->expectExceptionMessage(
195179
'Error in writing Auth file path/to/auth.json. Please check permissions for writing.'
196180
);
197-
$this->directoryReadMock->expects($this->once())
198-
->method('readFile')
199-
->with('composer.json')
200-
->willReturn('{"require": {"magento/product-community-edition": "0.0.1"}, "version": "0.0.1"}');
201-
$this->serializerMock->expects($this->any())
202-
->method('unserialize')
203-
->will($this->returnValue([
204-
'require' => ["magento/product-community-edition" => "0.0.1"],
205-
'version' => '0.0.1'
206-
]));
207-
$this->filesystemMock->expects($this->once())
208-
->method('getDirectoryRead')
209-
->with(DirectoryList::ROOT)
210-
->willReturn($this->directoryReadMock);
181+
211182
$this->directoryWriteMock->expects($this->once())
212183
->method('isExist')
213184
->with(PackagesAuth::PATH_TO_AUTH_FILE)

app/code/Magento/SampleData/Test/Unit/Console/Command/SampleDataRemoveCommandTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public function processDataProvider(): array
8989
"require" => [
9090
"magento/product-community-edition" => "0.0.1",
9191
],
92-
"version" => "0.0.1"
9392
],
9493
'expectedMsg' => 'There is an error during remove sample data.' . PHP_EOL,
9594
],
@@ -103,7 +102,6 @@ public function processDataProvider(): array
103102
"magento/product-community-edition" => "0.0.1",
104103
"magento/module-cms-sample-data" => "1.0.0-beta",
105104
],
106-
"version" => "0.0.1"
107105
],
108106
'expectedMsg' => '',
109107
],

0 commit comments

Comments
 (0)