Skip to content

Commit

Permalink
ENGCOM-6668: Add frontend template hints status command #26451
Browse files Browse the repository at this point in the history
  • Loading branch information
slavvka committed Feb 7, 2020
2 parents ba8fae3 + 93905ea commit 97bd34c
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Developer\Console\Command;

use Magento\Framework\App\Config\ReinitableConfigInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Command to show frontend template hints status
*/
class TemplateHintsStatusCommand extends Command
{
const COMMAND_NAME = 'dev:template-hints:status';
const TEMPLATE_HINTS_STOREFRONT_PATH = 'dev/debug/template_hints_storefront';

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @var ReinitableConfigInterface
*/
private $reinitableConfig;

/**
* Initialize dependencies.
*
* @param ScopeConfigInterface $scopeConfig
* @param ReinitableConfigInterface $reinitableConfig
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
ReinitableConfigInterface $reinitableConfig
) {
parent::__construct();
$this->scopeConfig = $scopeConfig;
$this->reinitableConfig = $reinitableConfig;
}

/**
* @inheritdoc
*/
public function configure()
{
$this->setName(self::COMMAND_NAME)
->setDescription('Show frontend template hints status.');

parent::configure();
}

/**
* @inheritdoc
* @throws \InvalidArgumentException
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$this->reinitableConfig->reinit();
$templateHintsStatus =
($this->isTemplateHintsEnabled())
? 'enabled'
: 'disabled';
$templateHintsMessage = __("Template hints are %status", ['status' => $templateHintsStatus]);
$output->writeln("<info>$templateHintsMessage</info>");

return Cli::RETURN_SUCCESS;
}

/**
* Check if template hints enabled
*
* @return bool
*/
private function isTemplateHintsEnabled(): bool
{
return $this->scopeConfig->isSetFlag(self::TEMPLATE_HINTS_STOREFRONT_PATH, 'default');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Developer\Test\Unit\Console\Command;

use Magento\Developer\Console\Command\TemplateHintsStatusCommand;
use Magento\Framework\App\Config\ReinitableConfigInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Console\Cli;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;

/**
* Class TemplateHintsStatusCommandTest
*
* Tests dev:template-hints:status command.
*/
class TemplateHintsStatusCommandTest extends TestCase
{
/**
* @var TemplateHintsStatusCommand
*/
private $command;
/**
* @var ScopeConfigInterface
*/
private $scopeConfigMock;
/**
* @var ReinitableConfigInterface
*/
private $reinitableConfigMock;

/**
* @inheritDoc
*/
protected function setUp()
{
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
$this->reinitableConfigMock = $this->getMockForAbstractClass(ReinitableConfigInterface::class);

$this->command = new TemplateHintsStatusCommand(
$this->scopeConfigMock,
$this->reinitableConfigMock
);
}

/**
* Verify ScopeConfigInterface instance
*/
public function testScopeConfigInterfaceInstance()
{
$this->assertInstanceOf(ScopeConfigInterface::class, $this->scopeConfigMock);
}

/**
* Verify ReinitableConfigInterface instance
*/
public function testReinitableConfigInterfaceInstance()
{
$this->assertInstanceOf(ReinitableConfigInterface::class, $this->reinitableConfigMock);
}

/**
* Verify TemplateHintsStatusCommand instance
*/
public function testCommandInstance()
{
$this->assertInstanceOf(TemplateHintsStatusCommand::class, $this->command);
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Developer/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<item name="dev_query_log_disable" xsi:type="object">Magento\Developer\Console\Command\QueryLogDisableCommand</item>
<item name="dev_template_hints_disable" xsi:type="object">Magento\Developer\Console\Command\TemplateHintsDisableCommand</item>
<item name="dev_template_hints_enable" xsi:type="object">Magento\Developer\Console\Command\TemplateHintsEnableCommand</item>
<item name="dev_template_hints_status" xsi:type="object">Magento\Developer\Console\Command\TemplateHintsStatusCommand</item>
<item name="dev_profiler_disable" xsi:type="object">Magento\Developer\Console\Command\ProfilerDisableCommand</item>
<item name="dev_profiler_enable" xsi:type="object">Magento\Developer\Console\Command\ProfilerEnableCommand</item>
<item name="dev_generate_patch" xsi:type="object">Magento\Developer\Console\Command\GeneratePatchCommand</item>
Expand Down

0 comments on commit 97bd34c

Please sign in to comment.