Skip to content

Commit

Permalink
MAGETWO-52767: [Github] Not possible to disable DEBUG logging #4362
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftedreality committed Jun 29, 2016
1 parent 96ef03b commit 514383b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 46 deletions.
13 changes: 1 addition & 12 deletions app/code/Magento/Developer/Model/Logger/Handler/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Magento\Framework\App\State;
use Magento\Framework\Filesystem\DriverInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Class Debug
Expand All @@ -26,42 +25,32 @@ class Debug extends \Magento\Framework\Logger\Handler\Debug
*/
private $scopeConfig;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @param DriverInterface $filesystem
* @param State $state
* @param ScopeConfigInterface $scopeConfig
* @param StoreManagerInterface $storeManager
* @param string $filePath
*/
public function __construct(
DriverInterface $filesystem,
State $state,
ScopeConfigInterface $scopeConfig,
StoreManagerInterface $storeManager,
$filePath = null
) {
parent::__construct($filesystem, $filePath);

$this->state = $state;
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
}

/**
* {@inheritdoc}
*/
public function isHandling(array $record)
{
$storeCode = $this->storeManager->getStore()->getCode();

return
parent::isHandling($record)
&& $this->state->getMode() !== State::MODE_PRODUCTION
&& $this->scopeConfig->getValue('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE, $storeCode);
&& $this->scopeConfig->getValue('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
use Magento\Framework\App\State;
use Magento\Framework\Filesystem\DriverInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Monolog\Formatter\FormatterInterface;
use Monolog\Logger;

Expand Down Expand Up @@ -41,16 +39,6 @@ class DebugTest extends \PHPUnit_Framework_TestCase
*/
private $scopeConfigMock;

/**
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $storeManagerMock;

/**
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $storeMock;

/**
* @var FormatterInterface|\PHPUnit_Framework_MockObject_MockObject
*/
Expand All @@ -65,16 +53,9 @@ protected function setUp()
->getMock();
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
->getMockForAbstractClass();
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
->getMockForAbstractClass();
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
->getMockForAbstractClass();
$this->formatterMock = $this->getMockBuilder(FormatterInterface::class)
->getMockForAbstractClass();

$this->storeManagerMock->expects($this->any())
->method('getStore')
->willReturn($this->storeMock);
$this->formatterMock->expects($this->any())
->method('format')
->willReturn(null);
Expand All @@ -83,32 +64,25 @@ protected function setUp()
'filesystem' => $this->filesystemMock,
'state' => $this->stateMock,
'scopeConfig' => $this->scopeConfigMock,
'storeManager' => $this->storeManagerMock
]);
$this->model->setFormatter($this->formatterMock);
}

public function testHandle()
{
$this->storeMock->expects($this->once())
->method('getCode')
->willReturn('test_code');
$this->stateMock->expects($this->once())
->method('getMode')
->willReturn(State::MODE_DEVELOPER);
$this->scopeConfigMock->expects($this->once())
->method('getValue')
->with('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE, 'test_code')
->with('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE, null)
->willReturn(true);

$this->model->handle(['formatted' => false, 'level' => Logger::DEBUG]);
}

public function testHandleDisabledByProduction()
{
$this->storeMock->expects($this->once())
->method('getCode')
->willReturn('test_code');
$this->stateMock->expects($this->once())
->method('getMode')
->willReturn(State::MODE_PRODUCTION);
Expand All @@ -120,25 +94,19 @@ public function testHandleDisabledByProduction()

public function testHandleDisabledByConfig()
{
$this->storeMock->expects($this->once())
->method('getCode')
->willReturn('test_code');
$this->stateMock->expects($this->once())
->method('getMode')
->willReturn(State::MODE_DEVELOPER);
$this->scopeConfigMock->expects($this->once())
->method('getValue')
->with('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE, 'test_code')
->with('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE, null)
->willReturn(false);

$this->model->handle(['formatted' => false, 'level' => Logger::DEBUG]);
}

public function testHandleDisabledByLevel()
{
$this->storeMock->expects($this->once())
->method('getCode')
->willReturn('test_code');
$this->stateMock->expects($this->never())
->method('getMode');
$this->scopeConfigMock->expects($this->never())
Expand Down

0 comments on commit 514383b

Please sign in to comment.