Skip to content

Commit 2d193d8

Browse files
author
Bohdan Korablov
committed
MAGETWO-60165: Inability to Run the DI Compiler before setup
1 parent 5ffafe2 commit 2d193d8

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

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

Lines changed: 17 additions & 4 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
}
5669
}

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

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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
@@ -44,6 +45,11 @@ class DebugTest extends \PHPUnit_Framework_TestCase
4445
*/
4546
private $formatterMock;
4647

48+
/**
49+
* @var DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
50+
*/
51+
private $deploymentConfigMock;
52+
4753
protected function setUp()
4854
{
4955
$this->filesystemMock = $this->getMockBuilder(DriverInterface::class)
@@ -55,6 +61,10 @@ protected function setUp()
5561
->getMockForAbstractClass();
5662
$this->formatterMock = $this->getMockBuilder(FormatterInterface::class)
5763
->getMockForAbstractClass();
64+
$this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
65+
->disableOriginalConstructor()
66+
->disableOriginalClone()
67+
->getMock();
5868

5969
$this->formatterMock->expects($this->any())
6070
->method('format')
@@ -64,12 +74,16 @@ protected function setUp()
6474
'filesystem' => $this->filesystemMock,
6575
'state' => $this->stateMock,
6676
'scopeConfig' => $this->scopeConfigMock,
77+
'deploymentConfig' => $this->deploymentConfigMock
6778
]);
6879
$this->model->setFormatter($this->formatterMock);
6980
}
7081

7182
public function testHandle()
7283
{
84+
$this->deploymentConfigMock->expects($this->once())
85+
->method('isAvailable')
86+
->willReturn(true);
7387
$this->stateMock->expects($this->once())
7488
->method('getMode')
7589
->willReturn(State::MODE_DEVELOPER);
@@ -78,22 +92,28 @@ public function testHandle()
7892
->with('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE, null)
7993
->willReturn(true);
8094

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

8498
public function testHandleDisabledByProduction()
8599
{
100+
$this->deploymentConfigMock->expects($this->once())
101+
->method('isAvailable')
102+
->willReturn(true);
86103
$this->stateMock->expects($this->once())
87104
->method('getMode')
88105
->willReturn(State::MODE_PRODUCTION);
89106
$this->scopeConfigMock->expects($this->never())
90107
->method('getValue');
91108

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

95112
public function testHandleDisabledByConfig()
96113
{
114+
$this->deploymentConfigMock->expects($this->once())
115+
->method('isAvailable')
116+
->willReturn(true);
97117
$this->stateMock->expects($this->once())
98118
->method('getMode')
99119
->willReturn(State::MODE_DEVELOPER);
@@ -102,16 +122,32 @@ public function testHandleDisabledByConfig()
102122
->with('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE, null)
103123
->willReturn(false);
104124

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

108128
public function testHandleDisabledByLevel()
109129
{
130+
$this->deploymentConfigMock->expects($this->once())
131+
->method('isAvailable')
132+
->willReturn(true);
133+
$this->stateMock->expects($this->never())
134+
->method('getMode');
135+
$this->scopeConfigMock->expects($this->never())
136+
->method('getValue');
137+
138+
$this->assertFalse($this->model->isHandling(['formatted' => false, 'level' => Logger::API]));
139+
}
140+
141+
public function testDeploymentConfigIsNotAvailable()
142+
{
143+
$this->deploymentConfigMock->expects($this->once())
144+
->method('isAvailable')
145+
->willReturn(false);
110146
$this->stateMock->expects($this->never())
111147
->method('getMode');
112148
$this->scopeConfigMock->expects($this->never())
113149
->method('getValue');
114150

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

0 commit comments

Comments
 (0)