Skip to content

Commit 7dbf9cb

Browse files
author
Yevhen Miroshnychenko
authored
Merge pull request #2378 from magento-thunder/MAGETWO-89315
Fixed issues: - MAGETWO-89315: Magento application compatible without cloud Patches
2 parents 431d0d3 + ba9f25d commit 7dbf9cb

File tree

3 files changed

+104
-10
lines changed

3 files changed

+104
-10
lines changed

lib/internal/Magento/Framework/Setup/FilePermissions.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Framework\Backup\Filesystem\Iterator\Filter;
1010
use Magento\Framework\Filesystem;
1111
use Magento\Framework\Filesystem\Filter\ExcludeFilter;
12+
use Magento\Framework\App\State;
13+
use Magento\Framework\App\ObjectManager;
1214

1315
/**
1416
* Checks permissions to files and folders.
@@ -25,6 +27,11 @@ class FilePermissions
2527
*/
2628
protected $directoryList;
2729

30+
/**
31+
* @var State
32+
*/
33+
private $state;
34+
2835
/**
2936
* List of required writable directories for installation
3037
*
@@ -63,13 +70,16 @@ class FilePermissions
6370
/**
6471
* @param Filesystem $filesystem
6572
* @param DirectoryList $directoryList
73+
* @param State $state
6674
*/
6775
public function __construct(
6876
Filesystem $filesystem,
69-
DirectoryList $directoryList
77+
DirectoryList $directoryList,
78+
State $state = null
7079
) {
7180
$this->filesystem = $filesystem;
7281
$this->directoryList = $directoryList;
82+
$this->state = $state ?: ObjectManager::getInstance()->get(State::class);
7383
}
7484

7585
/**
@@ -85,8 +95,10 @@ public function getInstallationWritableDirectories()
8595
DirectoryList::VAR_DIR,
8696
DirectoryList::MEDIA,
8797
DirectoryList::STATIC_VIEW,
88-
DirectoryList::GENERATED,
8998
];
99+
if ($this->state->getMode() !== State::MODE_PRODUCTION) {
100+
$data[] = DirectoryList::GENERATED;
101+
}
90102
foreach ($data as $code) {
91103
$this->installationWritableDirectories[$code] = $this->directoryList->getPath($code);
92104
}

lib/internal/Magento/Framework/Setup/Test/Unit/FilePermissionsTest.php

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

88
use \Magento\Framework\Setup\FilePermissions;
99
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\App\State;
1011

1112
class FilePermissionsTest extends \PHPUnit\Framework\TestCase
1213
{
@@ -25,6 +26,11 @@ class FilePermissionsTest extends \PHPUnit\Framework\TestCase
2526
*/
2627
private $directoryListMock;
2728

29+
/**
30+
* @var \PHPUnit_Framework_MockObject_MockObject|State
31+
*/
32+
private $stateMock;
33+
2834
/**
2935
* @var FilePermissions
3036
*/
@@ -34,6 +40,7 @@ public function setUp()
3440
{
3541
$this->directoryWriteMock = $this->createMock(\Magento\Framework\Filesystem\Directory\Write::class);
3642
$this->filesystemMock = $this->createMock(\Magento\Framework\Filesystem::class);
43+
$this->stateMock = $this->createMock(State::class);
3744

3845
$this->filesystemMock
3946
->expects($this->any())
@@ -43,13 +50,21 @@ public function setUp()
4350

4451
$this->filePermissions = new FilePermissions(
4552
$this->filesystemMock,
46-
$this->directoryListMock
53+
$this->directoryListMock,
54+
$this->stateMock
4755
);
4856
}
4957

50-
public function testGetInstallationWritableDirectories()
58+
/**
59+
* @param string $mageMode
60+
* @dataProvider modeDataProvider
61+
*/
62+
public function testGetInstallationWritableDirectories($mageMode)
5163
{
5264
$this->setUpDirectoryListInstallation();
65+
$this->stateMock->expects($this->once())
66+
->method('getMode')
67+
->willReturn($mageMode);
5368

5469
$expected = [
5570
BP . '/app/etc',
@@ -62,6 +77,23 @@ public function testGetInstallationWritableDirectories()
6277
$this->assertEquals($expected, $this->filePermissions->getInstallationWritableDirectories());
6378
}
6479

80+
public function testGetInstallationWritableDirectoriesInProduction()
81+
{
82+
$this->setUpDirectoryListInstallationInProduction();
83+
$this->stateMock->expects($this->once())
84+
->method('getMode')
85+
->willReturn(State::MODE_PRODUCTION);
86+
87+
$expected = [
88+
BP . '/app/etc',
89+
BP . '/var',
90+
BP . '/pub/media',
91+
BP . '/pub/static'
92+
];
93+
94+
$this->assertEquals($expected, $this->filePermissions->getInstallationWritableDirectories());
95+
}
96+
6597
public function testGetApplicationNonWritableDirectories()
6698
{
6799
$this->directoryListMock
@@ -134,13 +166,18 @@ public function getApplicationCurrentNonWritableDirectoriesDataProvider()
134166
}
135167

136168
/**
169+
* @param string $mageMode
170+
* @dataProvider modeDataProvider
137171
* @covers \Magento\Framework\Setup\FilePermissions::getMissingWritableDirectoriesForInstallation
138172
* @covers \Magento\Framework\Setup\FilePermissions::getMissingWritablePathsForInstallation
139173
*/
140-
public function testGetMissingWritableDirectoriesAndPathsForInstallation()
174+
public function testGetMissingWritableDirectoriesAndPathsForInstallation($mageMode)
141175
{
142176
$this->setUpDirectoryListInstallation();
143177
$this->setUpDirectoryWriteInstallation();
178+
$this->stateMock->expects($this->once())
179+
->method('getMode')
180+
->willReturn($mageMode);
144181

145182
$expected = [
146183
BP . '/var',
@@ -160,6 +197,31 @@ public function testGetMissingWritableDirectoriesAndPathsForInstallation()
160197
);
161198
}
162199

200+
public function testGetMissingWritableDirectoriesAndPathsForInstallationInProduction()
201+
{
202+
$this->setUpDirectoryListInstallationInProduction();
203+
$this->setUpDirectoryWriteInstallation();
204+
$this->stateMock->expects($this->once())
205+
->method('getMode')
206+
->willReturn(State::MODE_PRODUCTION);
207+
208+
$expected = [
209+
BP . '/var',
210+
BP . '/pub/media',
211+
BP . '/pub/static'
212+
];
213+
214+
$this->assertEquals(
215+
$expected,
216+
array_values($this->filePermissions->getMissingWritableDirectoriesForInstallation())
217+
);
218+
219+
$this->assertEquals(
220+
$expected,
221+
array_values($this->filePermissions->getMissingWritablePathsForInstallation())
222+
);
223+
}
224+
163225
public function testGetMissingWritableDirectoriesForDbUpgrade()
164226
{
165227
$directoryMethods = ['isExist', 'isDirectory', 'isReadable', 'isWritable'];
@@ -212,6 +274,16 @@ public function getUnnecessaryWritableDirectoriesForApplicationDataProvider()
212274
}
213275

214276
public function setUpDirectoryListInstallation()
277+
{
278+
$this->setUpDirectoryListInstallationInProduction();
279+
$this->directoryListMock
280+
->expects($this->at(4))
281+
->method('getPath')
282+
->with(DirectoryList::GENERATED)
283+
->will($this->returnValue(BP . '/generated'));
284+
}
285+
286+
public function setUpDirectoryListInstallationInProduction()
215287
{
216288
$this->directoryListMock
217289
->expects($this->at(0))
@@ -233,11 +305,6 @@ public function setUpDirectoryListInstallation()
233305
->method('getPath')
234306
->with(DirectoryList::STATIC_VIEW)
235307
->will($this->returnValue(BP . '/pub/static'));
236-
$this->directoryListMock
237-
->expects($this->at(4))
238-
->method('getPath')
239-
->with(DirectoryList::GENERATED)
240-
->will($this->returnValue(BP . '/generated'));
241308
}
242309

243310
public function setUpDirectoryWriteInstallation()
@@ -294,4 +361,15 @@ public function setUpDirectoryWriteInstallation()
294361
->method('isWritable')
295362
->will($this->returnValue(false));
296363
}
364+
365+
/**
366+
* @return array
367+
*/
368+
public function modeDataProvider()
369+
{
370+
return [
371+
[State::MODE_DEFAULT],
372+
[State::MODE_DEVELOPER],
373+
];
374+
}
297375
}

setup/index.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
use Magento\Setup\Application;
7+
use Magento\Setup\Model\ObjectManagerProvider;
78

89
if (PHP_SAPI == 'cli') {
910
echo "You cannot run this from the command line." . PHP_EOL .
@@ -32,4 +33,7 @@
3233
$configuration = require __DIR__ . '/config/application.config.php';
3334
$bootstrap = new Application();
3435
$application = $bootstrap->bootstrap($configuration);
36+
$application->getServiceManager()
37+
->get(ObjectManagerProvider::class)
38+
->setObjectManager(\Magento\Framework\App\Bootstrap::create(BP, $_SERVER)->getObjectManager());
3539
$application->run();

0 commit comments

Comments
 (0)