Skip to content

Commit e954a58

Browse files
authored
MAGECLOUD-4982: De-composed magento-cloud-patches fail to apply locally (magento#663)
* MAGECLOUD-4982: De-composed magento-cloud-patches fail to apply locally
1 parent 6ba3f1f commit e954a58

File tree

4 files changed

+66
-27
lines changed

4 files changed

+66
-27
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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,16 @@ public function getServicesConfig(): string
119119
*
120120
* @return string
121121
*/
122-
public function getServiceEolsConfig() : string
122+
public function getServiceEolsConfig(): string
123123
{
124124
return $this->directoryList->getRoot() . '/config/eol.yaml';
125125
}
126+
127+
/**
128+
* @return string
129+
*/
130+
public function getFrontStaticDist(): string
131+
{
132+
return $this->directoryList->getRoot() . '/dist/front-static.php.dist';
133+
}
126134
}

src/Step/Build/CopyPubStatic.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\MagentoCloud\Filesystem\DirectoryList;
1111
use Magento\MagentoCloud\Filesystem\Driver\File;
12+
use Magento\MagentoCloud\Filesystem\FileList;
1213
use Magento\MagentoCloud\Step\StepInterface;
1314
use Psr\Log\LoggerInterface;
1415

@@ -32,19 +33,27 @@ class CopyPubStatic implements StepInterface
3233
*/
3334
private $directoryList;
3435

36+
/**
37+
* @var FileList
38+
*/
39+
private $fileList;
40+
3541
/**
3642
* @param LoggerInterface $logger
3743
* @param File $file
3844
* @param DirectoryList $directoryList
45+
* @param FileList $fileList
3946
*/
4047
public function __construct(
4148
LoggerInterface $logger,
4249
File $file,
43-
DirectoryList $directoryList
50+
DirectoryList $directoryList,
51+
FileList $fileList
4452
) {
4553
$this->logger = $logger;
4654
$this->file = $file;
4755
$this->directoryList = $directoryList;
56+
$this->fileList = $fileList;
4857
}
4958

5059
/**
@@ -54,16 +63,10 @@ public function execute(): void
5463
{
5564
$magentoRoot = $this->directoryList->getMagentoRoot();
5665

57-
if (!$this->file->isExists($magentoRoot . '/pub/static.php')) {
58-
$this->logger->notice('File "static.php" was not found');
59-
60-
return;
61-
}
62-
6366
$this->file->copy(
64-
$magentoRoot . '/pub/static.php',
67+
$this->fileList->getFrontStaticDist(),
6568
$magentoRoot . '/pub/front-static.php'
6669
);
67-
$this->logger->info('File "static.php" was copied');
70+
$this->logger->info('File "front-static.php" was copied');
6871
}
6972
}

src/Test/Unit/Step/Build/CopyPubStaticTest.php

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\MagentoCloud\Step\Build\CopyPubStatic;
1111
use Magento\MagentoCloud\Filesystem\DirectoryList;
1212
use Magento\MagentoCloud\Filesystem\Driver\File;
13+
use Magento\MagentoCloud\Filesystem\FileList;
1314
use Magento\MagentoCloud\Step\StepException;
1415
use PHPUnit\Framework\MockObject\MockObject;
1516
use PHPUnit\Framework\TestCase;
@@ -40,6 +41,11 @@ class CopyPubStaticTest extends TestCase
4041
*/
4142
private $directoryListMock;
4243

44+
/**
45+
* @var FileList|MockObject
46+
*/
47+
private $fileListMock;
48+
4349
/**
4450
* @inheritDoc
4551
*/
@@ -48,14 +54,16 @@ protected function setUp(): void
4854
$this->fileMock = $this->createMock(File::class);
4955
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
5056
$this->directoryListMock = $this->createMock(DirectoryList::class);
57+
$this->fileListMock = $this->createMock(FileList::class);
5158

5259
$this->directoryListMock->method('getMagentoRoot')
5360
->willReturn('magento_root');
5461

5562
$this->step = new CopyPubStatic(
5663
$this->loggerMock,
5764
$this->fileMock,
58-
$this->directoryListMock
65+
$this->directoryListMock,
66+
$this->fileListMock
5967
);
6068
}
6169

@@ -64,20 +72,21 @@ protected function setUp(): void
6472
*/
6573
public function testExecute(): void
6674
{
67-
$this->fileMock->expects($this->once())
68-
->method('isExists')
69-
->with('magento_root/pub/static.php')
70-
->willReturn(true);
75+
$frontStaticDistPath = 'path/dist/front-static.php.dist';
76+
$this->directoryListMock->expects($this->once())
77+
->method('getMagentoRoot')
78+
->willReturn('magento_root');
79+
$this->fileListMock->expects($this->once())
80+
->method('getFrontStaticDist')
81+
->willReturn($frontStaticDistPath);
7182
$this->fileMock->expects($this->once())
7283
->method('copy')
7384
->with(
74-
'magento_root/pub/static.php',
85+
$frontStaticDistPath,
7586
'magento_root/pub/front-static.php'
7687
);
7788
$this->loggerMock->method('info')
78-
->withConsecutive(
79-
['File "static.php" was copied']
80-
);
89+
->with('File "front-static.php" was copied');
8190

8291
$this->step->execute();
8392
}
@@ -87,16 +96,21 @@ public function testExecute(): void
8796
*/
8897
public function testExecuteNotFound(): void
8998
{
99+
$frontStaticDistPath = 'path/dist/front-static.php.dist';
100+
$this->directoryListMock->expects($this->once())
101+
->method('getMagentoRoot')
102+
->willReturn('magento_root');
103+
$this->fileListMock->expects($this->once())
104+
->method('getFrontStaticDist')
105+
->willReturn($frontStaticDistPath);
90106
$this->fileMock->expects($this->once())
91-
->method('isExists')
92-
->with('magento_root/pub/static.php')
93-
->willReturn(false);
94-
$this->fileMock->expects($this->never())
95-
->method('copy');
96-
$this->loggerMock->method('notice')
97-
->withConsecutive(
98-
['File "static.php" was not found']
107+
->method('copy')
108+
->with(
109+
$frontStaticDistPath,
110+
'magento_root/pub/front-static.php'
99111
);
112+
$this->loggerMock->method('info')
113+
->with('File "front-static.php" was copied');
100114

101115
$this->step->execute();
102116
}

0 commit comments

Comments
 (0)