-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-52767: [Github] Not possible to disable DEBUG logging #4362
- Loading branch information
1 parent
e7d6678
commit 73c9f1a
Showing
4 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Developer\Model\Logger\Handler; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\State; | ||
use Magento\Framework\Filesystem\DriverInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
|
||
/** | ||
* Class Debug | ||
*/ | ||
class Debug extends \Magento\Framework\Logger\Handler\Debug | ||
{ | ||
/** | ||
* @var State | ||
*/ | ||
private $state; | ||
|
||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
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 write(array $record) | ||
{ | ||
$storeCode = $this->storeManager->getStore()->getCode(); | ||
|
||
if ( | ||
$this->state->getMode() === State::MODE_PRODUCTION | ||
|| !$this->scopeConfig->getValue('debug_logging', ScopeInterface::SCOPE_STORE, $storeCode) | ||
) { | ||
return null; | ||
} | ||
|
||
parent::write($record); | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
app/code/Magento/Developer/Test/Unit/Model/Logger/Handler/DebugTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Developer\Test\Unit\Model\Logger\Handler; | ||
|
||
use Magento\Developer\Model\Logger\Handler\Debug; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
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; | ||
|
||
/** | ||
* Class DebugTest | ||
*/ | ||
class DebugTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Debug | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var DriverInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $filesystemMock; | ||
|
||
/** | ||
* @var State|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $stateMock; | ||
|
||
/** | ||
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $scopeConfigMock; | ||
|
||
/** | ||
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $storeManagerMock; | ||
|
||
/** | ||
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $storeMock; | ||
|
||
protected function setUp() | ||
{ | ||
$this->filesystemMock = $this->getMockBuilder(DriverInterface::class) | ||
->getMockForAbstractClass(); | ||
$this->stateMock = $this->getMockBuilder(State::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) | ||
->getMockForAbstractClass(); | ||
$this->storeMock = $this->getMockBuilder(StoreInterface::class) | ||
->getMockForAbstractClass(); | ||
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class) | ||
->getMockForAbstractClass(); | ||
|
||
$this->storeManagerMock->expects($this->any()) | ||
->method('getStore') | ||
->willReturn($this->storeMock); | ||
|
||
$this->model = (new ObjectManager($this))->getObject(Debug::class, [ | ||
'filesystem' => $this->filesystemMock, | ||
'state' => $this->stateMock, | ||
'scopeConfig' => $this->scopeConfigMock, | ||
'storeManager' => $this->storeManagerMock | ||
]); | ||
} | ||
|
||
public function testWrite() | ||
{ | ||
$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('debug_logging', ScopeInterface::SCOPE_STORE, 'test_code') | ||
->willReturn(true); | ||
|
||
$this->model->write(['formatted' => false]); | ||
} | ||
|
||
public function testWriteWithDisabledByProduction() | ||
{ | ||
$this->storeMock->expects($this->once()) | ||
->method('getCode') | ||
->willReturn('test_code'); | ||
$this->stateMock->expects($this->once()) | ||
->method('getMode') | ||
->willReturn(State::MODE_PRODUCTION); | ||
$this->scopeConfigMock->expects($this->never()) | ||
->method('getValue'); | ||
|
||
$this->assertNull( | ||
$this->model->write(['formatted' => false]) | ||
); | ||
} | ||
|
||
public function testWriteDisabledByConfig() | ||
{ | ||
$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('debug_logging', ScopeInterface::SCOPE_STORE, 'test_code') | ||
->willReturn(false); | ||
|
||
$this->assertNull( | ||
$this->model->write(['formatted' => false]) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters