Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/internal/Magento/Framework/App/DocRootLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\App;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\ReadFactory;

/**
Expand All @@ -20,18 +22,26 @@ class DocRootLocator
private $request;

/**
* @deprecated
* @var ReadFactory
*/
private $readFactory;

/**
* @var Filesystem
*/
private $filesystem;

/**
* @param RequestInterface $request
* @param ReadFactory $readFactory
* @param Filesystem|null $filesystem
*/
public function __construct(RequestInterface $request, ReadFactory $readFactory)
public function __construct(RequestInterface $request, ReadFactory $readFactory, Filesystem $filesystem = null)
{
$this->request = $request;
$this->readFactory = $readFactory;
$this->filesystem = $filesystem ?: ObjectManager::getInstance()->get(Filesystem::class);
}

/**
Expand All @@ -42,7 +52,8 @@ public function __construct(RequestInterface $request, ReadFactory $readFactory)
public function isPub()
{
$rootBasePath = $this->request->getServer('DOCUMENT_ROOT');
$readDirectory = $this->readFactory->create(DirectoryList::ROOT);
return (substr($rootBasePath, -strlen('/pub')) === '/pub') && !$readDirectory->isExist($rootBasePath . 'setup');
$readDirectory = $this->filesystem->getDirectoryRead(DirectoryList::ROOT);

return (substr($rootBasePath, -\strlen('/pub')) === '/pub') && ! $readDirectory->isExist('setup');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

use Magento\Framework\App\DocRootLocator;

/**
* Test for Magento\Framework\App\DocRootLocator class.
*/
class DocRootLocatorTest extends \PHPUnit\Framework\TestCase
{
/**
Expand All @@ -21,11 +24,15 @@ public function testIsPub($path, $isExist, $result)
{
$request = $this->createMock(\Magento\Framework\App\Request\Http::class);
$request->expects($this->once())->method('getServer')->willReturn($path);

$readFactory = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadFactory::class);

$reader = $this->createMock(\Magento\Framework\Filesystem\Directory\Read::class);
$filesystem = $this->createMock(\Magento\Framework\Filesystem::class);
$filesystem->expects($this->once())->method('getDirectoryRead')->willReturn($reader);
$reader->expects($this->any())->method('isExist')->willReturn($isExist);
$readFactory = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadFactory::class);
$readFactory->expects($this->once())->method('create')->willReturn($reader);
$model = new DocRootLocator($request, $readFactory);

$model = new DocRootLocator($request, $readFactory, $filesystem);
$this->assertSame($result, $model->isPub());
}

Expand Down