Skip to content

Commit

Permalink
Disable config:data:di command for production modes with open issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuench committed Mar 20, 2017
1 parent de7449b commit 498ab1e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/N98/Magento/Command/Config/Data/DiCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

class DiCommand extends AbstractMagentoCommand
{
/**
* @var \Magento\Framework\App\ProductMetadataInterface
*/
private $productMetadata;

protected function configure()
{
$this
Expand All @@ -29,6 +34,14 @@ protected function configure()
;
}

/**
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
*/
public function inject(\Magento\Framework\App\ProductMetadataInterface $productMetadata)
{
$this->productMetadata = $productMetadata;
}

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
Expand All @@ -38,10 +51,22 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->detectMagento($output, true);

if (!$this->initMagento()) {
return;
}

if ($this->runsInProductionMode($input, $output)
&& version_compare($this->productMetadata->getVersion(), '2.1.0', '<')
) {
$output->writeln(sprintf(
'This command is not available in production mode for Magento versions <2.1.0. Current version: %s',
$this->productMetadata->getVersion()
));

return;
}

/** @var ConfigLoaderInterface $configLoader */
$configLoader = $this->getObjectManager()->get(ConfigLoaderInterface::class);
$configDataPrimary = $configLoader->load('primary');
Expand Down
33 changes: 33 additions & 0 deletions tests/N98/Magento/Command/Config/Data/DiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,44 @@

namespace N98\Magento\Command\Config\Data;

use Magento\Deploy\Model\Mode;
use Magento\Framework\App\State;
use N98\Magento\Command\TestCase;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Tester\CommandTester;

class DiCommandTest extends TestCase
{
/**
* @return void
*/
protected function setUp()
{
if ($this->runsInProductionMode()) {
$this->markTestSkipped('This command is not available in production mode');
}

parent::setUp();
}

/**
* @return bool
*/
private function runsInProductionMode()
{
$objectManager = $this->getApplication()->getObjectManager();
$mode = $objectManager->create(
Mode::class,
[
'input' => new ArgvInput(),
'output' => new ConsoleOutput(),
]
);

return $mode->getMode() === State::MODE_PRODUCTION;
}

/**
* @test
* @outputBuffering off
Expand Down

0 comments on commit 498ab1e

Please sign in to comment.