Skip to content

Commit 0de28fa

Browse files
committed
Merge remote-tracking branch 'origin/develop' into imported-magento-atwix-pyrrans-ece-tools-810
2 parents 51b0991 + 0014ca4 commit 0de28fa

File tree

6 files changed

+103
-14
lines changed

6 files changed

+103
-14
lines changed

src/Command/Dev/UpdateComposer.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
108108
{
109109
$gitOptions = $this->globalSection->get(GlobalSection::VAR_DEPLOY_FROM_GIT_OPTIONS);
110110

111-
$scripts = $this->composerGenerator->getInstallFromGitScripts($gitOptions['repositories']);
112-
foreach (array_slice($scripts, 1) as $script) {
111+
$InstallFromGitScripts = $this->composerGenerator->getInstallFromGitScripts($gitOptions['repositories']);
112+
foreach (array_slice($InstallFromGitScripts, 1) as $script) {
113113
$this->shell->execute($script);
114114
}
115115

116-
$composer = $this->composerGenerator->generate($gitOptions['repositories']);
116+
// Preparing framework modules for installation
117+
$frameworkPreparationScript = $this->composerGenerator->getFrameworkPreparationScript(
118+
array_keys($gitOptions['repositories'])
119+
);
120+
foreach ($frameworkPreparationScript as $script) {
121+
$this->shell->execute($script);
122+
}
123+
124+
$composer = $this->composerGenerator->generate(
125+
$gitOptions['repositories'],
126+
array_merge($InstallFromGitScripts, $frameworkPreparationScript)
127+
);
117128

118129
if (!empty($gitOptions['clear_magento_module_requirements'])) {
119130
$clearRequirementsScript = $this->clearModuleRequirements->generate();

src/Command/Dev/UpdateComposer/ComposerGenerator.php

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ public function __construct(
6969
* Generates composer.json data for installation from git.
7070
*
7171
* @param array $repoOptions
72+
* @param array $installFromGitScripts
7273
* @return array
7374
* @throws FileSystemException
7475
* @codeCoverageIgnore
7576
*/
76-
public function generate(array $repoOptions): array
77+
public function generate(array $repoOptions, array $installFromGitScripts): array
7778
{
78-
$composer = $this->getBaseComposer($repoOptions);
79+
$composer = $this->getBaseComposer($installFromGitScripts);
7980

8081
$rootComposerJsonPath = $this->directoryList->getMagentoRoot() . '/composer.json';
8182
if ($this->file->isExists($rootComposerJsonPath)) {
@@ -162,15 +163,39 @@ public function getInstallFromGitScripts(array $repoOptions): array
162163
return $installFromGitScripts;
163164
}
164165

166+
/**
167+
* @param array $repoNames
168+
* @return array
169+
* @throws FileSystemException
170+
*/
171+
public function getFrameworkPreparationScript(array $repoNames): array
172+
{
173+
$script = [];
174+
175+
foreach ($repoNames as $repoName) {
176+
$path = $repoName . '/lib/internal/Magento/Framework';
177+
$absolutePath = $this->directoryList->getMagentoRoot() . '/' .$path;
178+
179+
if ($this->file->isExists($absolutePath)) {
180+
foreach ($this->findPackages($absolutePath) as $package) {
181+
if ($package) {
182+
$script[] = 'mv ' . $path . '/' . $package . ' ' . $path . '-' . $package;
183+
}
184+
}
185+
}
186+
}
187+
188+
return $script;
189+
}
190+
165191
/**
166192
* Returns base skeleton for composer.json.
167193
*
168-
* @param array $repoOptions
194+
* @param array $installFromGitScripts
169195
* @return array
170196
*/
171-
private function getBaseComposer(array $repoOptions): array
197+
private function getBaseComposer(array $installFromGitScripts): array
172198
{
173-
$installFromGitScripts = $this->getInstallFromGitScripts($repoOptions);
174199
$composer = [
175200
'name' => 'magento/cloud-dev',
176201
'description' => 'eCommerce Platform for Growth',
@@ -188,6 +213,11 @@ private function getBaseComposer(array $repoOptions): array
188213
],
189214
'config' => [
190215
'use-include-path' => true,
216+
'allow-plugins' => [
217+
'dealerdirect/phpcodesniffer-composer-installer' => true,
218+
'laminas/laminas-dependency-plugin' => true,
219+
'magento/*' => true
220+
]
191221
],
192222
'autoload' => [
193223
'psr-4' => [
@@ -200,6 +230,11 @@ private function getBaseComposer(array $repoOptions): array
200230
'extra' => [
201231
'magento-force' => 'override',
202232
'magento-deploystrategy' => 'copy',
233+
'magento-deploy-ignore' => [
234+
'*' => [
235+
'/.gitignore'
236+
]
237+
]
203238
],
204239
'scripts' => [
205240
'install-from-git' => $installFromGitScripts,

src/Test/Unit/Command/Dev/UpdateComposer/ComposerGeneratorTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ class ComposerGeneratorTest extends TestCase
4949
],
5050
];
5151

52+
/**
53+
* @var array
54+
*/
55+
private $installFromGitScript = [
56+
'php -r"@mkdir(__DIR__ . \'/app/etc\', 0777, true);"',
57+
'rm -rf repo1 repo2 repo3 repo4 repo5',
58+
'git clone -b 1.0.0 --single-branch --depth 1 path_to_repo1 repo1',
59+
'git clone -b 2.0.0 --single-branch --depth 1 path_to_repo2 repo2',
60+
'git clone path_to_repo3 "repo3" && git --git-dir="repo3/.git" --work-tree="repo3" checkout ref3',
61+
'git clone path_to_repo4 "repo4" && git --git-dir="repo4/.git" --work-tree="repo4" checkout ref4',
62+
'git clone path_to_repo5 "repo5" && git --git-dir="repo5/.git" --work-tree="repo5" checkout ref5',
63+
'mv repo1/lib/internal/Magento/Framework/Lib1 repo1/lib/internal/Magento/Framework-Lib1',
64+
];
65+
5266
/**
5367
* @var DirectoryList|MockObject
5468
*/
@@ -86,16 +100,23 @@ protected function setUp(): void
86100
);
87101
}
88102

89-
public function testGetInstallFromGitScripts()
103+
public function testScripts(): void
90104
{
91105
$expected = include(__DIR__ . '/_files/expected_composer.php');
92-
$actual = $this->composerGenerator->getInstallFromGitScripts($this->repoOptions);
93-
$this->assertEquals($expected['scripts']['install-from-git'], $actual);
106+
$installFromGitScripts = $this->composerGenerator->getInstallFromGitScripts($this->repoOptions);
107+
$frameworkPreparationScript = $this->composerGenerator->getFrameworkPreparationScript(
108+
array_keys($this->repoOptions)
109+
);
110+
111+
$this->assertEquals(
112+
$expected['scripts']['install-from-git'],
113+
array_merge($installFromGitScripts, $frameworkPreparationScript)
114+
);
94115
}
95116

96117
public function testGenerate(): void
97118
{
98-
$composer = $this->composerGenerator->generate($this->repoOptions);
119+
$composer = $this->composerGenerator->generate($this->repoOptions, $this->installFromGitScript);
99120

100121
$expected = include(__DIR__ . '/_files/expected_composer.php');
101122
foreach ($expected as $key => $value) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "magento/lib1",
3+
"type": "magento2-library"
4+
}

src/Test/Unit/Command/Dev/UpdateComposer/_files/expected_composer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,21 @@
4040
'symlink' => false,
4141
],
4242
],
43+
'magento/lib1' => [
44+
'type' => 'path',
45+
'url' => 'repo1/lib/internal/Magento/Framework/Lib1',
46+
'options' => [
47+
'symlink' => false,
48+
],
49+
],
4350
],
4451
'require' => [
4552
'package' => '*',
4653
'vendor/library1' => '*@dev',
4754
'vendor/theme1' => '*@dev',
4855
'vendor/module-module1' => '*@dev',
4956
'vendor/module-module5' => '*@dev',
57+
'magento/lib1' => '*@dev',
5058
],
5159
'scripts' =>[
5260
'install-from-git' => [
@@ -57,6 +65,7 @@
5765
'git clone path_to_repo3 "repo3" && git --git-dir="repo3/.git" --work-tree="repo3" checkout ref3',
5866
'git clone path_to_repo4 "repo4" && git --git-dir="repo4/.git" --work-tree="repo4" checkout ref4',
5967
'git clone path_to_repo5 "repo5" && git --git-dir="repo5/.git" --work-tree="repo5" checkout ref5',
68+
'mv repo1/lib/internal/Magento/Framework/Lib1 repo1/lib/internal/Magento/Framework-Lib1',
6069
],
6170
'pre-install-cmd' => [
6271
'@install-from-git',
@@ -65,7 +74,7 @@
6574
'@install-from-git',
6675
],
6776
'prepare-packages' => [
68-
'rsync -azhm --stats --exclude=\'lib/internal/Vendor/Library1\' --exclude=\'dev/tests\' --exclude=\'.git\' --exclude=\'composer.json\' --exclude=\'composer.lock\' ./repo1/ ./',
77+
'rsync -azhm --stats --exclude=\'lib/internal/Magento/Framework/Lib1\' --exclude=\'lib/internal/Vendor/Library1\' --exclude=\'dev/tests\' --exclude=\'.git\' --exclude=\'composer.json\' --exclude=\'composer.lock\' ./repo1/ ./',
6978
'rsync -azhm --stats --exclude=\'app/code/Vendor/Module1\' --exclude=\'dev/tests\' --exclude=\'.git\' --exclude=\'composer.json\' --exclude=\'composer.lock\' ./repo2/ ./',
7079
'rsync -azhm --stats --exclude=\'app/design/Vendor/Theme1\' --exclude=\'dev/tests\' --exclude=\'.git\' --exclude=\'composer.json\' --exclude=\'composer.lock\' ./repo3/ ./',
7180
'rsync -azhm --stats --exclude=\'dev/tests\' --exclude=\'.git\' --exclude=\'composer.json\' --exclude=\'composer.lock\' ./repo4/ ./',

src/Test/Unit/Command/Dev/UpdateComposerTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ public function testExecute(): void
105105
'script2',
106106
'script3',
107107
]);
108+
$this->composerGeneratorMock->expects($this->once())
109+
->method('getFrameworkPreparationScript')
110+
->with(array_keys($gitOptions['repositories']))
111+
->willReturn([
112+
'script4',
113+
'script5',
114+
]);
108115
$this->composerGeneratorMock->expects($this->once())
109116
->method('generate')
110117
->with($gitOptions['repositories'])
@@ -121,11 +128,13 @@ public function testExecute(): void
121128
],
122129
],
123130
]);
124-
$this->shellMock->expects($this->exactly(3))
131+
$this->shellMock->expects($this->exactly(5))
125132
->method('execute')
126133
->withConsecutive(
127134
['script2'],
128135
['script3'],
136+
['script4'],
137+
['script5'],
129138
['composer update --ansi --no-interaction']
130139
);
131140
$this->fileListMock->expects($this->once())

0 commit comments

Comments
 (0)