Skip to content

Commit aa6368e

Browse files
authored
ENGCOM-4711: Use correct base path to check if setup folder exists #20182
2 parents 0d2b026 + e521181 commit aa6368e

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

lib/internal/Magento/Framework/App/DocRootLocator.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Framework\App;
89

910
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\Filesystem;
1012
use Magento\Framework\Filesystem\Directory\ReadFactory;
1113

1214
/**
@@ -20,18 +22,26 @@ class DocRootLocator
2022
private $request;
2123

2224
/**
25+
* @deprecated
2326
* @var ReadFactory
2427
*/
2528
private $readFactory;
2629

30+
/**
31+
* @var Filesystem
32+
*/
33+
private $filesystem;
34+
2735
/**
2836
* @param RequestInterface $request
2937
* @param ReadFactory $readFactory
38+
* @param Filesystem|null $filesystem
3039
*/
31-
public function __construct(RequestInterface $request, ReadFactory $readFactory)
40+
public function __construct(RequestInterface $request, ReadFactory $readFactory, Filesystem $filesystem = null)
3241
{
3342
$this->request = $request;
3443
$this->readFactory = $readFactory;
44+
$this->filesystem = $filesystem ?: ObjectManager::getInstance()->get(Filesystem::class);
3545
}
3646

3747
/**
@@ -42,7 +52,8 @@ public function __construct(RequestInterface $request, ReadFactory $readFactory)
4252
public function isPub()
4353
{
4454
$rootBasePath = $this->request->getServer('DOCUMENT_ROOT');
45-
$readDirectory = $this->readFactory->create(DirectoryList::ROOT);
46-
return (substr($rootBasePath, -strlen('/pub')) === '/pub') && !$readDirectory->isExist($rootBasePath . 'setup');
55+
$readDirectory = $this->filesystem->getDirectoryRead(DirectoryList::ROOT);
56+
57+
return (substr($rootBasePath, -\strlen('/pub')) === '/pub') && ! $readDirectory->isExist('setup');
4758
}
4859
}

lib/internal/Magento/Framework/App/Test/Unit/DocRootLocatorTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
use Magento\Framework\App\DocRootLocator;
1010

11+
/**
12+
* Test for Magento\Framework\App\DocRootLocator class.
13+
*/
1114
class DocRootLocatorTest extends \PHPUnit\Framework\TestCase
1215
{
1316
/**
@@ -21,11 +24,15 @@ public function testIsPub($path, $isExist, $result)
2124
{
2225
$request = $this->createMock(\Magento\Framework\App\Request\Http::class);
2326
$request->expects($this->once())->method('getServer')->willReturn($path);
27+
28+
$readFactory = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadFactory::class);
29+
2430
$reader = $this->createMock(\Magento\Framework\Filesystem\Directory\Read::class);
31+
$filesystem = $this->createMock(\Magento\Framework\Filesystem::class);
32+
$filesystem->expects($this->once())->method('getDirectoryRead')->willReturn($reader);
2533
$reader->expects($this->any())->method('isExist')->willReturn($isExist);
26-
$readFactory = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadFactory::class);
27-
$readFactory->expects($this->once())->method('create')->willReturn($reader);
28-
$model = new DocRootLocator($request, $readFactory);
34+
35+
$model = new DocRootLocator($request, $readFactory, $filesystem);
2936
$this->assertSame($result, $model->isPub());
3037
}
3138

0 commit comments

Comments
 (0)