Skip to content

Fixed fatal error on "magento sampledata:deploy" when magento is not installed. #13571

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

Merged
merged 3 commits into from
Feb 15, 2018
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
12 changes: 6 additions & 6 deletions app/code/Magento/SampleData/Model/Dependency.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Magento\Framework\Config\Composer\Package;
use Magento\Framework\Config\Composer\PackageFactory;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\ReadInterfaceFactory;
use Magento\Framework\Filesystem\Directory\ReadFactory;

/**
* Sample Data dependency
Expand Down Expand Up @@ -40,7 +40,7 @@ class Dependency
private $componentRegistrar;

/**
* @var ReadInterfaceFactory
* @var ReadFactory
*/
private $directoryReadFactory;

Expand All @@ -51,21 +51,21 @@ class Dependency
* @param Filesystem $filesystem @deprecated 2.3.0 $directoryReadFactory is used instead
* @param PackageFactory $packageFactory
* @param ComponentRegistrarInterface $componentRegistrar
* @param Filesystem\Directory\ReadInterfaceFactory|null $directoryReadFactory
* @param Filesystem\Directory\ReadFactory|null $directoryReadFactory
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
ComposerInformation $composerInformation,
Filesystem $filesystem,
PackageFactory $packageFactory,
ComponentRegistrarInterface $componentRegistrar,
\Magento\Framework\Filesystem\Directory\ReadInterfaceFactory $directoryReadFactory = null
\Magento\Framework\Filesystem\Directory\ReadFactory $directoryReadFactory = null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would great to cover this with the tests

) {
$this->composerInformation = $composerInformation;
$this->packageFactory = $packageFactory;
$this->componentRegistrar = $componentRegistrar;
$this->directoryReadFactory = $directoryReadFactory ?:
ObjectManager::getInstance()->get(ReadInterfaceFactory::class);
ObjectManager::getInstance()->get(ReadFactory::class);
}

/**
Expand Down Expand Up @@ -123,7 +123,7 @@ private function getModuleComposerPackage($moduleDir)
*/
foreach ([$moduleDir, $moduleDir . DIRECTORY_SEPARATOR . '..'] as $dir) {
/** @var Filesystem\Directory\ReadInterface $directory */
$directory = $this->directoryReadFactory->create(['path' => $dir]);
$directory = $this->directoryReadFactory->create($dir);
if ($directory->isExist('composer.json') && $directory->isReadable('composer.json')) {
/** @var Package $package */
return $this->packageFactory->create(['json' => json_decode($directory->readFile('composer.json'))]);
Expand Down
27 changes: 18 additions & 9 deletions app/code/Magento/SampleData/Test/Unit/Model/DependencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Framework\Filesystem;
use Magento\Framework\Phrase;
use Magento\SampleData\Model\Dependency;
use Magento\Framework\Filesystem\DriverPool;

class DependencyTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -59,7 +60,7 @@ public function testPackagesFromComposerSuggest(
$moduleDirectories
);

$directoryReadFactory = $this->getMockBuilder(Filesystem\Directory\ReadInterfaceFactory::class)
$directoryReadFactory = $this->getMockBuilder(Filesystem\Directory\ReadFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
Expand Down Expand Up @@ -88,7 +89,8 @@ public static function dataPackagesFromComposerSuggest()
'composerJsonGenerator' => function (DependencyTest $test) {
return [
[
['path' => 'app/code/LocalModule'],
'app/code/LocalModule',
DriverPool::FILE,
$test->stubComposerJsonReader(
[
'name' => 'local/module',
Expand All @@ -99,11 +101,13 @@ public static function dataPackagesFromComposerSuggest()
)
],
[
['path' => 'app/code/LocalModuleWithoutComposerJson'],
'app/code/LocalModuleWithoutComposerJson',
DriverPool::FILE,
$test->stubFileNotFoundReader()
],
[
['path' => 'vendor/company/module'],
'vendor/company/module',
DriverPool::FILE,
$test->stubComposerJsonReader(
[
'name' => 'company/module',
Expand All @@ -114,7 +118,8 @@ public static function dataPackagesFromComposerSuggest()
)
],
[
['path' => 'vendor/company2/module/src/..'],
'vendor/company2/module/src/..',
DriverPool::FILE,
$test->stubComposerJsonReader(
[
'name' => 'company2/module',
Expand All @@ -125,19 +130,23 @@ public static function dataPackagesFromComposerSuggest()
)
],
[
['path' => 'vendor/company2/module/src'],
'vendor/company2/module/src',
DriverPool::FILE,
$test->stubFileNotFoundReader()
],
[
['path' => 'vendor/company/module/..'],
'vendor/company/module/..',
DriverPool::FILE,
$test->stubFileNotFoundReader()
],
[
['path' => 'app/code/LocalModuleWithoutComposerJson/..'],
'app/code/LocalModuleWithoutComposerJson/..',
DriverPool::FILE,
$test->stubFileNotFoundReader()
],
[
['path' => 'app/code/LocalModule/..'],
'app/code/LocalModule/..',
DriverPool::FILE,
$test->stubFileNotFoundReader()
],
];
Expand Down
6 changes: 0 additions & 6 deletions app/code/Magento/SampleData/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@
</argument>
</arguments>
</type>
<virtualType name="Magento\SampleData\Filesystem\Directory\Read" type="Magento\Framework\Filesystem\Directory\Read">
<arguments>
<argument name="driver" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
</arguments>
</virtualType>
<preference for="Magento\Framework\Filesystem\Directory\ReadInterface" type="Magento\SampleData\Filesystem\Directory\Read" />
</config>