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

Add frontend template hints status command #26451

Merged
merged 17 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from 10 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

WaPoNe marked this conversation as resolved.
Show resolved Hide resolved
namespace Magento\Developer\Console\Command;

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

/**
* 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
*/
protected function configure()
{
$this->setName(self::COMMAND_NAME)
->setDescription('Show frontend template hints status.');

parent::configure();
}

/**
* @inheritdoc
* @throws \InvalidArgumentException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->reinitableConfig->reinit();
$templateHintsStatus =
$this->scopeConfig->isSetFlag(self::TEMPLATE_HINTS_STOREFRONT_PATH, 'default')
Copy link
Contributor

Choose a reason for hiding this comment

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

Wasn't that line extracted to private method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right @lbajsarowicz but I was able to test that private method that gave me strange errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lbajsarowicz I brought it back and changed unit tests to verify single interfaces.

? 'enabled'
: 'disabled';
$templateHintsMessage = __("Template hints are %status", ['status' => $templateHintsStatus]);
$output->writeln("<info>" . $templateHintsMessage . "</info>");
WaPoNe marked this conversation as resolved.
Show resolved Hide resolved

return Cli::RETURN_SUCCESS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

WaPoNe marked this conversation as resolved.
Show resolved Hide resolved
namespace Magento\Developer\Test\Unit\Console\Command;

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

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

/**
* @var ScopeConfigInterface
*/
private $scopeConfigMock;
/**
WaPoNe marked this conversation as resolved.
Show resolved Hide resolved
* @var ReinitableConfigInterface
*/
private $reinitableConfigMock;

WaPoNe marked this conversation as resolved.
Show resolved Hide resolved
protected function setUp()
{
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
$this->reinitableConfigMock = $this->getMockForAbstractClass(ReinitableConfigInterface::class);

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

}

WaPoNe marked this conversation as resolved.
Show resolved Hide resolved
public function testExecute()
{
$tester = new CommandTester($this->command);
$tester->execute([]);

$this->assertContains(
'disabled',
$tester->getDisplay()
);

$this->assertEquals(
0,
$tester->getStatusCode()
);
}
}
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