13
13
use Magento \Store \Model \ScopeInterface ;
14
14
use Monolog \Formatter \FormatterInterface ;
15
15
use Monolog \Logger ;
16
+ use Magento \Framework \App \DeploymentConfig ;
16
17
17
18
/**
18
19
* Class DebugTest
@@ -44,6 +45,11 @@ class DebugTest extends \PHPUnit_Framework_TestCase
44
45
*/
45
46
private $ formatterMock ;
46
47
48
+ /**
49
+ * @var DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
50
+ */
51
+ private $ deploymentConfigMock ;
52
+
47
53
protected function setUp ()
48
54
{
49
55
$ this ->filesystemMock = $ this ->getMockBuilder (DriverInterface::class)
@@ -55,6 +61,10 @@ protected function setUp()
55
61
->getMockForAbstractClass ();
56
62
$ this ->formatterMock = $ this ->getMockBuilder (FormatterInterface::class)
57
63
->getMockForAbstractClass ();
64
+ $ this ->deploymentConfigMock = $ this ->getMockBuilder (DeploymentConfig::class)
65
+ ->disableOriginalConstructor ()
66
+ ->disableOriginalClone ()
67
+ ->getMock ();
58
68
59
69
$ this ->formatterMock ->expects ($ this ->any ())
60
70
->method ('format ' )
@@ -64,12 +74,16 @@ protected function setUp()
64
74
'filesystem ' => $ this ->filesystemMock ,
65
75
'state ' => $ this ->stateMock ,
66
76
'scopeConfig ' => $ this ->scopeConfigMock ,
77
+ 'deploymentConfig ' => $ this ->deploymentConfigMock
67
78
]);
68
79
$ this ->model ->setFormatter ($ this ->formatterMock );
69
80
}
70
81
71
82
public function testHandle ()
72
83
{
84
+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
85
+ ->method ('isAvailable ' )
86
+ ->willReturn (true );
73
87
$ this ->stateMock ->expects ($ this ->once ())
74
88
->method ('getMode ' )
75
89
->willReturn (State::MODE_DEVELOPER );
@@ -78,22 +92,28 @@ public function testHandle()
78
92
->with ('dev/debug/debug_logging ' , ScopeInterface::SCOPE_STORE , null )
79
93
->willReturn (true );
80
94
81
- $ this ->model ->handle (['formatted ' => false , 'level ' => Logger::DEBUG ]);
95
+ $ this ->assertTrue ( $ this -> model ->isHandling (['formatted ' => false , 'level ' => Logger::DEBUG ]) );
82
96
}
83
97
84
98
public function testHandleDisabledByProduction ()
85
99
{
100
+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
101
+ ->method ('isAvailable ' )
102
+ ->willReturn (true );
86
103
$ this ->stateMock ->expects ($ this ->once ())
87
104
->method ('getMode ' )
88
105
->willReturn (State::MODE_PRODUCTION );
89
106
$ this ->scopeConfigMock ->expects ($ this ->never ())
90
107
->method ('getValue ' );
91
108
92
- $ this ->model ->handle (['formatted ' => false , 'level ' => Logger::DEBUG ]);
109
+ $ this ->assertFalse ( $ this -> model ->isHandling (['formatted ' => false , 'level ' => Logger::DEBUG ]) );
93
110
}
94
111
95
112
public function testHandleDisabledByConfig ()
96
113
{
114
+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
115
+ ->method ('isAvailable ' )
116
+ ->willReturn (true );
97
117
$ this ->stateMock ->expects ($ this ->once ())
98
118
->method ('getMode ' )
99
119
->willReturn (State::MODE_DEVELOPER );
@@ -102,16 +122,32 @@ public function testHandleDisabledByConfig()
102
122
->with ('dev/debug/debug_logging ' , ScopeInterface::SCOPE_STORE , null )
103
123
->willReturn (false );
104
124
105
- $ this ->model ->handle (['formatted ' => false , 'level ' => Logger::DEBUG ]);
125
+ $ this ->assertFalse ( $ this -> model ->isHandling (['formatted ' => false , 'level ' => Logger::DEBUG ]) );
106
126
}
107
127
108
128
public function testHandleDisabledByLevel ()
109
129
{
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 );
110
146
$ this ->stateMock ->expects ($ this ->never ())
111
147
->method ('getMode ' );
112
148
$ this ->scopeConfigMock ->expects ($ this ->never ())
113
149
->method ('getValue ' );
114
150
115
- $ this ->model ->handle (['formatted ' => false , 'level ' => Logger::API ] );
151
+ $ this ->assertTrue ( $ this -> model ->isHandling (['formatted ' => false , 'level ' => Logger::DEBUG ]) );
116
152
}
117
153
}
0 commit comments