Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct base path to check if setup folder exists #20182

Merged
merged 2 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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