Skip to content

Commit 94de8e5

Browse files
author
Yevhen Miroshnychenko
authored
MAGECLOUD-5310: Issue with Magento 2002.0 and latest patches release 1.0.1 (#690)
1 parent f66c0a0 commit 94de8e5

File tree

4 files changed

+96
-47
lines changed

4 files changed

+96
-47
lines changed

dist/front-static.php.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Entry point for static resources (JS, CSS, etc.)
4+
*
5+
* Copyright © Magento, Inc. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
9+
$_GET['resource'] = preg_replace('/^(\/static\/)(version(\d+)?\/)?|(\?.*)/', '', $_SERVER['REQUEST_URI'] ?: '');
10+
require realpath(__DIR__) . '/../app/bootstrap.php';
11+
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
12+
/** @var \Magento\Framework\App\StaticResource $app */
13+
$app = $bootstrap->createApplication(\Magento\Framework\App\StaticResource::class);
14+
$bootstrap->run($app);

src/Filesystem/FileList.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,12 @@ public function getServicesConfig(): string
9797
{
9898
return $this->directoryList->getMagentoRoot() . '/.magento/services.yaml';
9999
}
100+
101+
/**
102+
* @return string
103+
*/
104+
public function getFrontStaticDist(): string
105+
{
106+
return $this->directoryList->getRoot() . '/dist/front-static.php.dist';
107+
}
100108
}

src/Patch/Manager.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\MagentoCloud\Config\GlobalSection;
99
use Magento\MagentoCloud\Filesystem\DirectoryList;
10+
use Magento\MagentoCloud\Filesystem\FileList;
1011
use Magento\MagentoCloud\Filesystem\Driver\File;
1112
use Magento\MagentoCloud\Shell\ShellException;
1213
use Magento\MagentoCloud\Shell\ShellInterface;
@@ -42,26 +43,34 @@ class Manager
4243
*/
4344
private $globalSection;
4445

46+
/**
47+
* @var FileList
48+
*/
49+
private $fileList;
50+
4551
/**
4652
* @param LoggerInterface $logger
4753
* @param ShellInterface $shell
4854
* @param File $file
4955
* @param DirectoryList $directoryList
5056
* @param GlobalSection $globalSection
57+
* @param FileList $fileList
5158
*/
5259
public function __construct(
5360
LoggerInterface $logger,
5461
ShellInterface $shell,
5562
File $file,
5663
DirectoryList $directoryList,
57-
GlobalSection $globalSection
64+
GlobalSection $globalSection,
65+
FileList $fileList
5866
) {
5967

6068
$this->logger = $logger;
6169
$this->shell = $shell;
6270
$this->file = $file;
6371
$this->directoryList = $directoryList;
6472
$this->globalSection = $globalSection;
73+
$this->fileList = $fileList;
6574
}
6675

6776
/**
@@ -71,18 +80,11 @@ public function __construct(
7180
*/
7281
public function apply()
7382
{
74-
$magentoRoot = $this->directoryList->getMagentoRoot();
75-
76-
if (!$this->file->isExists($magentoRoot . '/pub/static.php')) {
77-
$this->logger->notice('File static.php was not found');
78-
} else {
79-
$this->file->copy(
80-
$magentoRoot . '/pub/static.php',
81-
$magentoRoot . '/pub/front-static.php'
82-
);
83-
84-
$this->logger->info('File static.php was copied');
85-
}
83+
$this->file->copy(
84+
$this->fileList->getFrontStaticDist(),
85+
$this->directoryList->getMagentoRoot() . '/pub/front-static.php'
86+
);
87+
$this->logger->info('File "front-static.php" was copied');
8688

8789
$this->logger->notice('Applying patches');
8890

src/Test/Unit/Patch/ManagerTest.php

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
use Magento\MagentoCloud\Config\GlobalSection;
1010
use Magento\MagentoCloud\Filesystem\DirectoryList;
1111
use Magento\MagentoCloud\Filesystem\Driver\File;
12+
use Magento\MagentoCloud\Filesystem\FileList;
1213
use Magento\MagentoCloud\Patch\Manager;
1314
use Magento\MagentoCloud\Shell\ProcessInterface;
15+
use Magento\MagentoCloud\Shell\ShellException;
1416
use Magento\MagentoCloud\Shell\ShellInterface;
1517
use PHPUnit\Framework\MockObject\MockObject;
1618
use PHPUnit\Framework\TestCase;
@@ -56,6 +58,11 @@ class ManagerTest extends TestCase
5658
*/
5759
private $globalSectionMock;
5860

61+
/**
62+
* @var FileList|MockObject
63+
*/
64+
private $fileListMock;
65+
5966
/**
6067
* @inheritdoc
6168
*/
@@ -67,82 +74,100 @@ protected function setUp()
6774
$this->fileMock = $this->createMock(File::class);
6875
$this->directoryListMock = $this->createMock(DirectoryList::class);
6976
$this->globalSectionMock = $this->createMock(GlobalSection::class);
77+
$this->fileListMock = $this->createMock(FileList::class);
7078

71-
$this->directoryListMock->method('getMagentoRoot')
79+
$this->directoryListMock->expects($this->once())
80+
->method('getMagentoRoot')
7281
->willReturn('magento_root');
82+
$this->fileListMock->expects($this->once())
83+
->method('getFrontStaticDist')
84+
->willReturn('dist/pub/front-static.php');
85+
$this->fileMock->expects($this->once())
86+
->method('copy')
87+
->with(
88+
'dist/pub/front-static.php',
89+
'magento_root/pub/front-static.php'
90+
);
91+
$this->loggerMock->expects($this->once())
92+
->method('info')
93+
->with('File "front-static.php" was copied');
7394

7495
$this->manager = new Manager(
7596
$this->loggerMock,
7697
$this->shellMock,
7798
$this->fileMock,
7899
$this->directoryListMock,
79-
$this->globalSectionMock
100+
$this->globalSectionMock,
101+
$this->fileListMock
80102
);
81103
}
82104

83105
public function testApply()
84106
{
85-
$this->fileMock->expects($this->once())
86-
->method('isExists')
87-
->with('magento_root/pub/static.php')
88-
->willReturn(true);
89-
$this->fileMock->expects($this->once())
90-
->method('copy')
91-
->with(
92-
'magento_root/pub/static.php',
93-
'magento_root/pub/front-static.php'
94-
);
95107
$this->globalSectionMock->expects($this->once())
96108
->method('get')
97109
->with(GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT)
98110
->willReturn(false);
99-
111+
$this->loggerMock->expects($this->exactly(2))
112+
->method('notice')
113+
->withConsecutive(
114+
['Applying patches'],
115+
['End of applying patches']
116+
);
100117
$processMock = $this->getMockForAbstractClass(ProcessInterface::class);
101118
$processMock->method('getOutput')
102119
->willReturn('Some patch applied');
103-
104120
$this->shellMock->expects($this->once())
105121
->method('execute')
106122
->with('php ./vendor/bin/ece-patches apply')
107123
->willReturn($processMock);
108-
$this->loggerMock->method('info')
109-
->withConsecutive(
110-
['File static.php was copied']
111-
);
124+
125+
$this->manager->apply();
126+
}
127+
128+
public function testApplyDeployedFromGitAndNoCopy()
129+
{
130+
$this->globalSectionMock->expects($this->once())
131+
->method('get')
132+
->with(GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT)
133+
->willReturn(true);
112134
$this->loggerMock->method('notice')
113135
->withConsecutive(
114136
['Applying patches'],
115137
['End of applying patches']
116138
);
139+
$processMock = $this->getMockForAbstractClass(ProcessInterface::class);
140+
$processMock->method('getOutput')
141+
->willReturn('Some patch applied');
142+
$this->shellMock->expects($this->once())
143+
->method('execute')
144+
->with('php ./vendor/bin/ece-patches apply --git-installation 1')
145+
->willReturn($processMock);
117146

118147
$this->manager->apply();
119148
}
120149

121-
public function testApplyDeployedFromGitAndNoCopy()
150+
public function testApplyWithException()
122151
{
123-
$this->fileMock->expects($this->once())
124-
->method('isExists')
125-
->with('magento_root/pub/static.php')
126-
->willReturn(false);
127152
$this->globalSectionMock->expects($this->once())
128153
->method('get')
129154
->with(GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT)
130-
->willReturn(true);
131-
155+
->willReturn(false);
156+
$this->loggerMock->expects($this->once())
157+
->method('notice')
158+
->with('Applying patches');
132159
$processMock = $this->getMockForAbstractClass(ProcessInterface::class);
133160
$processMock->method('getOutput')
134161
->willReturn('Some patch applied');
135-
162+
$exception = new ShellException('Some Error');
136163
$this->shellMock->expects($this->once())
137164
->method('execute')
138-
->with('php ./vendor/bin/ece-patches apply --git-installation 1')
139-
->willReturn($processMock);
140-
$this->loggerMock->method('notice')
141-
->withConsecutive(
142-
['File static.php was not found'],
143-
['Applying patches'],
144-
['End of applying patches']
145-
);
165+
->with('php ./vendor/bin/ece-patches apply')
166+
->willThrowException($exception);
167+
$this->loggerMock->expects($this->once())
168+
->method('error')
169+
->with('Some Error');
170+
$this->expectExceptionObject($exception);
146171

147172
$this->manager->apply();
148173
}

0 commit comments

Comments
 (0)