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