Skip to content

Commit

Permalink
Use correct base path to check if setup folder exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen van Leusden committed Jan 10, 2019
1 parent 0502433 commit 8966f5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
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 @@ -21,11 +21,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

0 comments on commit 8966f5f

Please sign in to comment.