15
15
use Magento \MagentoCloud \Filesystem \Driver \File ;
16
16
use Magento \MagentoCloud \App \Logger \Pool ;
17
17
use Magento \MagentoCloud \Package \UndefinedPackageException ;
18
+ use phpmock \phpunit \PHPMock ;
18
19
use PHPUnit \Framework \MockObject \MockObject ;
19
20
use PHPUnit \Framework \TestCase ;
20
21
use Magento \MagentoCloud \App \Logger \Processor \SanitizeProcessor ;
24
25
*/
25
26
class LoggerTest extends TestCase
26
27
{
28
+ use PHPMock;
29
+
27
30
/**
28
31
* @var File|MockObject
29
32
*/
@@ -59,6 +62,8 @@ class LoggerTest extends TestCase
59
62
*/
60
63
protected function setUp ()
61
64
{
65
+ self ::defineFunctionMock ('Magento\MagentoCloud\App ' , 'shell_exec ' );
66
+
62
67
$ this ->fileMock = $ this ->createMock (File::class);
63
68
$ this ->directoryListMock = $ this ->createMock (DirectoryList::class);
64
69
$ this ->fileListMock = $ this ->createMock (FileList::class);
@@ -71,7 +76,6 @@ protected function setUp()
71
76
* @param int $fileMockFileGetContentsExpects
72
77
* @param string $buildPhaseLogContent
73
78
* @param bool $buildLogFileExists
74
- * @param string $deployLogContent
75
79
* @param bool $deployLogFileExists
76
80
* @param int $fileMockFilePutContentsExpects
77
81
* @param int $fileMockCopyExpects
@@ -83,7 +87,6 @@ public function testExecute(
83
87
$ fileMockFileGetContentsExpects ,
84
88
$ buildPhaseLogContent ,
85
89
$ buildLogFileExists ,
86
- $ deployLogContent ,
87
90
$ deployLogFileExists ,
88
91
$ fileMockFilePutContentsExpects ,
89
92
$ fileMockCopyExpects
@@ -107,8 +110,7 @@ public function testExecute(
107
110
$ this ->fileMock ->expects ($ this ->exactly ($ fileMockFileGetContentsExpects ))
108
111
->method ('fileGetContents ' )
109
112
->willReturnMap ([
110
- [$ buildPhaseLogPath , false , null , $ buildPhaseLogContent ],
111
- [$ deployLogPath , false , null , $ deployLogContent ],
113
+ [$ buildPhaseLogPath , false , null , $ buildPhaseLogContent ]
112
114
]);
113
115
$ this ->fileMock ->expects ($ this ->exactly (2 ))
114
116
->method ('isExists ' )
@@ -126,6 +128,14 @@ public function testExecute(
126
128
$ this ->poolMock ->expects ($ this ->once ())
127
129
->method ('getHandlers ' )
128
130
->willReturn ([]);
131
+ if ($ buildLogFileExists && $ deployLogFileExists ) {
132
+ $ shellExecMock = $ this ->getFunctionMock (
133
+ 'Magento\MagentoCloud\App ' ,
134
+ 'shell_exec '
135
+ );
136
+ $ shellExecMock ->expects ($ this ->once ())
137
+ ->willReturn ($ fileMockFilePutContentsExpects ? null : 'some match ' );
138
+ }
129
139
130
140
new Logger (
131
141
$ this ->fileMock ,
@@ -147,25 +157,22 @@ public function executeDataProvider(): array
147
157
'fileMockFileGetContentsExpects ' => 1 ,
148
158
'buildPhaseLogContent ' => 'the build phase log was not applied ' ,
149
159
'buildLogFileExists ' => true ,
150
- 'deployLogContent ' => null ,
151
160
'deployLogFileExists ' => false ,
152
161
'fileMockFilePutContentsExpects ' => 0 ,
153
162
'fileMockCopyExpects ' => 1 ,
154
163
],
155
164
[
156
- 'fileMockFileGetContentsExpects ' => 2 ,
165
+ 'fileMockFileGetContentsExpects ' => 1 ,
157
166
'buildPhaseLogContent ' => 'the build phase log was applied ' ,
158
167
'buildLogFileExists ' => true ,
159
- 'deployLogContent ' => 'some log the build phase log was applied some log ' ,
160
168
'deployLogFileExists ' => true ,
161
169
'fileMockFilePutContentsExpects ' => 0 ,
162
170
'fileMockCopyExpects ' => 0 ,
163
171
],
164
172
[
165
- 'fileMockFileGetContentsExpects ' => 2 ,
173
+ 'fileMockFileGetContentsExpects ' => 1 ,
166
174
'buildPhaseLogContent ' => 'the build phase log was not applied ' ,
167
175
'buildLogFileExists ' => true ,
168
- 'deployLogContent ' => 'some log the build phase log was applied some log ' ,
169
176
'deployLogFileExists ' => true ,
170
177
'fileMockFilePutContentsExpects ' => 1 ,
171
178
'fileMockCopyExpects ' => 0 ,
@@ -174,7 +181,6 @@ public function executeDataProvider(): array
174
181
'fileMockFileGetContentsExpects ' => 0 ,
175
182
'buildPhaseLogContent ' => '' ,
176
183
'buildLogFileExists ' => false ,
177
- 'deployLogContent ' => 'some log the build phase log was applied some log ' ,
178
184
'deployLogFileExists ' => true ,
179
185
'fileMockFilePutContentsExpects ' => 0 ,
180
186
'fileMockCopyExpects ' => 0 ,
0 commit comments