Skip to content

Commit c9dc0fb

Browse files
committed
Merge remote-tracking branch 'falcon/MAGETWO-60165' into MAGETWO-60931
2 parents ed67d17 + 378eb5f commit c9dc0fb

File tree

2 files changed

+59
-9
lines changed

2 files changed

+59
-9
lines changed

app/code/Magento/Developer/Model/Logger/Handler/Debug.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\App\State;
1010
use Magento\Framework\Filesystem\DriverInterface;
1111
use Magento\Store\Model\ScopeInterface;
12+
use Magento\Framework\App\DeploymentConfig;
1213

1314
/**
1415
* Class Debug
@@ -25,32 +26,44 @@ class Debug extends \Magento\Framework\Logger\Handler\Debug
2526
*/
2627
private $scopeConfig;
2728

29+
/**
30+
* @var DeploymentConfig
31+
*/
32+
private $deploymentConfig;
33+
2834
/**
2935
* @param DriverInterface $filesystem
3036
* @param State $state
3137
* @param ScopeConfigInterface $scopeConfig
38+
* @param DeploymentConfig $deploymentConfig
3239
* @param string $filePath
3340
*/
3441
public function __construct(
3542
DriverInterface $filesystem,
3643
State $state,
3744
ScopeConfigInterface $scopeConfig,
45+
DeploymentConfig $deploymentConfig,
3846
$filePath = null
3947
) {
4048
parent::__construct($filesystem, $filePath);
4149

4250
$this->state = $state;
4351
$this->scopeConfig = $scopeConfig;
52+
$this->deploymentConfig = $deploymentConfig;
4453
}
4554

4655
/**
4756
* {@inheritdoc}
4857
*/
4958
public function isHandling(array $record)
5059
{
51-
return
52-
parent::isHandling($record)
53-
&& $this->state->getMode() !== State::MODE_PRODUCTION
54-
&& $this->scopeConfig->getValue('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE);
60+
if ($this->deploymentConfig->isAvailable()) {
61+
return
62+
parent::isHandling($record)
63+
&& $this->state->getMode() !== State::MODE_PRODUCTION
64+
&& $this->scopeConfig->getValue('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE);
65+
}
66+
67+
return parent::isHandling($record);
5568
}
56-
}
69+
}

app/code/Magento/Developer/Test/Unit/Model/Logger/Handler/DebugTest.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
use Magento\Store\Model\ScopeInterface;
1414
use Monolog\Formatter\FormatterInterface;
1515
use Monolog\Logger;
16+
use Magento\Framework\App\DeploymentConfig;
1617

1718
/**
1819
* Class DebugTest
20+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1921
*/
2022
class DebugTest extends \PHPUnit_Framework_TestCase
2123
{
@@ -44,6 +46,11 @@ class DebugTest extends \PHPUnit_Framework_TestCase
4446
*/
4547
private $formatterMock;
4648

49+
/**
50+
* @var DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
private $deploymentConfigMock;
53+
4754
protected function setUp()
4855
{
4956
$this->filesystemMock = $this->getMockBuilder(DriverInterface::class)
@@ -55,6 +62,10 @@ protected function setUp()
5562
->getMockForAbstractClass();
5663
$this->formatterMock = $this->getMockBuilder(FormatterInterface::class)
5764
->getMockForAbstractClass();
65+
$this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
66+
->disableOriginalConstructor()
67+
->disableOriginalClone()
68+
->getMock();
5869

5970
$this->formatterMock->expects($this->any())
6071
->method('format')
@@ -64,12 +75,16 @@ protected function setUp()
6475
'filesystem' => $this->filesystemMock,
6576
'state' => $this->stateMock,
6677
'scopeConfig' => $this->scopeConfigMock,
78+
'deploymentConfig' => $this->deploymentConfigMock
6779
]);
6880
$this->model->setFormatter($this->formatterMock);
6981
}
7082

7183
public function testHandle()
7284
{
85+
$this->deploymentConfigMock->expects($this->once())
86+
->method('isAvailable')
87+
->willReturn(true);
7388
$this->stateMock->expects($this->once())
7489
->method('getMode')
7590
->willReturn(State::MODE_DEVELOPER);
@@ -78,22 +93,28 @@ public function testHandle()
7893
->with('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE, null)
7994
->willReturn(true);
8095

81-
$this->model->handle(['formatted' => false, 'level' => Logger::DEBUG]);
96+
$this->assertTrue($this->model->isHandling(['formatted' => false, 'level' => Logger::DEBUG]));
8297
}
8398

8499
public function testHandleDisabledByProduction()
85100
{
101+
$this->deploymentConfigMock->expects($this->once())
102+
->method('isAvailable')
103+
->willReturn(true);
86104
$this->stateMock->expects($this->once())
87105
->method('getMode')
88106
->willReturn(State::MODE_PRODUCTION);
89107
$this->scopeConfigMock->expects($this->never())
90108
->method('getValue');
91109

92-
$this->model->handle(['formatted' => false, 'level' => Logger::DEBUG]);
110+
$this->assertFalse($this->model->isHandling(['formatted' => false, 'level' => Logger::DEBUG]));
93111
}
94112

95113
public function testHandleDisabledByConfig()
96114
{
115+
$this->deploymentConfigMock->expects($this->once())
116+
->method('isAvailable')
117+
->willReturn(true);
97118
$this->stateMock->expects($this->once())
98119
->method('getMode')
99120
->willReturn(State::MODE_DEVELOPER);
@@ -102,16 +123,32 @@ public function testHandleDisabledByConfig()
102123
->with('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE, null)
103124
->willReturn(false);
104125

105-
$this->model->handle(['formatted' => false, 'level' => Logger::DEBUG]);
126+
$this->assertFalse($this->model->isHandling(['formatted' => false, 'level' => Logger::DEBUG]));
106127
}
107128

108129
public function testHandleDisabledByLevel()
109130
{
131+
$this->deploymentConfigMock->expects($this->once())
132+
->method('isAvailable')
133+
->willReturn(true);
134+
$this->stateMock->expects($this->never())
135+
->method('getMode');
136+
$this->scopeConfigMock->expects($this->never())
137+
->method('getValue');
138+
139+
$this->assertFalse($this->model->isHandling(['formatted' => false, 'level' => Logger::API]));
140+
}
141+
142+
public function testDeploymentConfigIsNotAvailable()
143+
{
144+
$this->deploymentConfigMock->expects($this->once())
145+
->method('isAvailable')
146+
->willReturn(false);
110147
$this->stateMock->expects($this->never())
111148
->method('getMode');
112149
$this->scopeConfigMock->expects($this->never())
113150
->method('getValue');
114151

115-
$this->model->handle(['formatted' => false, 'level' => Logger::API]);
152+
$this->assertTrue($this->model->isHandling(['formatted' => false, 'level' => Logger::DEBUG]));
116153
}
117154
}

0 commit comments

Comments
 (0)