6
6
namespace Magento \Developer \Model \Logger \Handler ;
7
7
8
8
use Magento \Config \Console \Command \ConfigSetCommand ;
9
+ use Magento \Framework \App \Config ;
9
10
use Magento \Framework \App \Config \ScopeConfigInterface ;
10
11
use Magento \Framework \App \Filesystem \DirectoryList ;
11
12
use Magento \Framework \Filesystem ;
16
17
use Symfony \Component \Console \Input \InputInterface ;
17
18
use Symfony \Component \Console \Output \OutputInterface ;
18
19
20
+ /**
21
+ * Preconditions
22
+ * - Developer mode enabled
23
+ * - Log file isn't exists
24
+ * - 'Log to file' setting are enabled
25
+ *
26
+ * Test steps
27
+ * - Enable production mode without compilation
28
+ * - Try to log message into log file
29
+ * - Assert that log file isn't exists
30
+ * - Assert that 'Log to file' setting are disabled
31
+ *
32
+ * - Enable 'Log to file' setting
33
+ * - Try to log message into debug file
34
+ * - Assert that log file is exists
35
+ * - Assert that log file contain logged message
36
+ */
19
37
class DebugTest extends \PHPUnit_Framework_TestCase
20
38
{
21
39
/**
@@ -48,6 +66,11 @@ class DebugTest extends \PHPUnit_Framework_TestCase
48
66
*/
49
67
private $ etcDirectory ;
50
68
69
+ /**
70
+ * @var Config
71
+ */
72
+ private $ appConfig ;
73
+
51
74
public function setUp ()
52
75
{
53
76
/** @var Filesystem $filesystem */
@@ -68,9 +91,11 @@ public function setUp()
68
91
]
69
92
);
70
93
$ this ->configSetCommand = Bootstrap::getObjectManager ()->create (ConfigSetCommand::class);
94
+ $ this ->appConfig = Bootstrap::getObjectManager ()->create (Config::class);
71
95
72
96
// Preconditions
73
97
$ this ->mode ->enableDeveloperMode ();
98
+ $ this ->enableDebugging ();
74
99
if (file_exists ($ this ->getDebuggerLogPath ())) {
75
100
unlink ($ this ->getDebuggerLogPath ());
76
101
}
@@ -82,15 +107,8 @@ public function tearDown()
82
107
$ this ->etcDirectory ->renameFile ('env.base.php ' , 'env.php ' );
83
108
}
84
109
85
- public function testDebugInProductionMode ()
110
+ private function enableDebugging ()
86
111
{
87
- $ message = 'test message ' ;
88
-
89
- $ this ->mode ->enableProductionModeMinimal ();
90
-
91
- $ this ->logger ->debug ($ message );
92
- $ this ->assertFileNotExists ($ this ->getDebuggerLogPath ());
93
-
94
112
$ this ->inputMock = $ this ->getMockBuilder (InputInterface::class)
95
113
->getMockForAbstractClass ();
96
114
$ this ->outputMock = $ this ->getMockBuilder (OutputInterface::class)
@@ -115,6 +133,18 @@ public function testDebugInProductionMode()
115
133
->method ('writeln ' )
116
134
->with ('<info>Value was saved and locked.</info> ' );
117
135
$ this ->assertFalse ((bool )$ this ->configSetCommand ->run ($ this ->inputMock , $ this ->outputMock ));
136
+ }
137
+
138
+ public function testDebugInProductionMode ()
139
+ {
140
+ $ message = 'test message ' ;
141
+
142
+ $ this ->mode ->enableProductionModeMinimal ();
143
+ $ this ->logger ->debug ($ message );
144
+ $ this ->assertFileNotExists ($ this ->getDebuggerLogPath ());
145
+ $ this ->assertFalse ((bool )$ this ->appConfig ->getValue ('dev/debug/debug_logging ' ));
146
+
147
+ $ this ->enableDebugging ();
118
148
$ this ->logger ->debug ($ message );
119
149
120
150
$ this ->assertFileExists ($ this ->getDebuggerLogPath ());
0 commit comments