Skip to content

Commit dbe3b37

Browse files
ENGCOM-4711: Use correct base path to check if setup folder exists #20182
- Merge Pull Request #20182 from JeroenVanLeusden/magento2:patch-4 - Merged commits: 1. 8966f5f
2 parents 5a8ef03 + 8966f5f commit dbe3b37

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ public function testIsPub($path, $isExist, $result)
2121
{
2222
$request = $this->createMock(\Magento\Framework\App\Request\Http::class);
2323
$request->expects($this->once())->method('getServer')->willReturn($path);
24+
25+
$readFactory = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadFactory::class);
26+
2427
$reader = $this->createMock(\Magento\Framework\Filesystem\Directory\Read::class);
28+
$filesystem = $this->createMock(\Magento\Framework\Filesystem::class);
29+
$filesystem->expects($this->once())->method('getDirectoryRead')->willReturn($reader);
2530
$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);
31+
32+
$model = new DocRootLocator($request, $readFactory, $filesystem);
2933
$this->assertSame($result, $model->isPub());
3034
}
3135

0 commit comments

Comments
 (0)