8
8
namespace Magento \Deploy \Test \Unit \Process ;
9
9
10
10
use Magento \Deploy \Package \Package ;
11
+ use Magento \Deploy \Package \PackageFile ;
11
12
use Magento \Deploy \Process \Queue ;
12
13
use Magento \Deploy \Service \DeployPackage ;
14
+ use Magento \Deploy \Service \DeployStaticFile ;
13
15
use Magento \Framework \App \ResourceConnection ;
14
-
15
16
use Magento \Framework \App \State as AppState ;
17
+ use Magento \Framework \Config \ScopeInterface ;
16
18
use Magento \Framework \Locale \ResolverInterface as LocaleResolver ;
17
19
use PHPUnit \Framework \MockObject \MockObject as Mock ;
18
20
use PHPUnit \Framework \TestCase ;
19
-
20
21
use Psr \Log \LoggerInterface ;
21
22
22
23
/**
27
28
class QueueTest extends TestCase
28
29
{
29
30
/**
30
- * @var Queue
31
- */
32
- private $ queue ;
33
-
34
- /**
35
- * @var AppState|Mock
31
+ * @var AppState
36
32
*/
37
33
private $ appState ;
38
34
@@ -52,39 +48,64 @@ class QueueTest extends TestCase
52
48
private $ logger ;
53
49
54
50
/**
55
- * @var DeployPackage|Mock
51
+ * @var DeployPackage
56
52
*/
57
53
private $ deployPackageService ;
58
54
55
+ /**
56
+ * @var DeployStaticFile|Mock
57
+ */
58
+ private $ deployStaticFile ;
59
+
60
+ /**
61
+ * @var Package|Mock
62
+ */
63
+ private $ package ;
64
+
65
+ /**
66
+ * @var PackageFile|Mock
67
+ */
68
+ private $ packageFile ;
69
+
59
70
/**
60
71
* @inheritdoc
61
72
*/
62
73
protected function setUp (): void
63
74
{
64
- $ this ->appState = $ this ->createMock (AppState::class);
75
+ $ this ->resourceConnection = $ this ->createMock (ResourceConnection::class);
76
+ $ this ->package = $ this ->createMock (Package::class);
77
+ $ this ->deployStaticFile = $ this ->createMock (DeployStaticFile::class);
78
+
79
+ $ this ->packageFile = $ this ->createMock (PackageFile::class);
80
+ $ this ->packageFile
81
+ ->expects ($ this ->any ())
82
+ ->method ('getContent ' )
83
+ ->willReturn ('{} ' );
84
+
65
85
$ this ->localeResolver = $ this ->getMockForAbstractClass (
66
86
LocaleResolver::class,
67
87
['setLocale ' ],
68
88
'' ,
69
89
false
70
90
);
71
- $ this -> resourceConnection = $ this -> createMock (ResourceConnection::class);
91
+
72
92
$ this ->logger = $ this ->getMockForAbstractClass (
73
93
LoggerInterface::class,
74
94
['notice ' , 'info ' ],
75
95
'' ,
76
96
false
77
97
);
78
- $ this ->deployPackageService = $ this ->createPartialMock (DeployPackage::class, ['deploy ' ]);
79
98
80
- $ this ->queue = new Queue (
99
+ $ configScope = $ this ->createMock (ScopeInterface::class);
100
+ $ this ->appState = new AppState (
101
+ $ configScope
102
+ );
103
+
104
+ $ this ->deployPackageService = new DeployPackage (
81
105
$ this ->appState ,
82
106
$ this ->localeResolver ,
83
- $ this ->resourceConnection ,
84
- $ this ->logger ,
85
- $ this ->deployPackageService ,
86
- [],
87
- 1
107
+ $ this ->deployStaticFile ,
108
+ $ this ->logger
88
109
);
89
110
}
90
111
@@ -93,13 +114,21 @@ protected function setUp(): void
93
114
*/
94
115
public function testAdd ()
95
116
{
96
- $ package = $ this ->createMock (Package::class);
97
- $ package ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('path ' );
117
+ $ queue = new Queue (
118
+ $ this ->appState ,
119
+ $ this ->localeResolver ,
120
+ $ this ->resourceConnection ,
121
+ $ this ->logger ,
122
+ $ this ->deployPackageService ,
123
+ [],
124
+ 0
125
+ );
98
126
99
- $ this ->assertTrue ($ this ->queue ->add ($ package ));
100
- $ packages = $ this ->queue ->getPackages ();
127
+ $ this ->package ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('path ' );
128
+ $ this ->assertTrue ($ queue ->add ($ this ->package ));
129
+ $ packages = $ queue ->getPackages ();
101
130
$ this ->assertEquals (
102
- $ package ,
131
+ $ this -> package ,
103
132
isset ($ packages ['path ' ]['package ' ]) ? $ packages ['path ' ]['package ' ] : null
104
133
);
105
134
}
@@ -109,20 +138,72 @@ public function testAdd()
109
138
*/
110
139
public function testProcess ()
111
140
{
112
- $ package = $ this ->createMock (Package::class);
113
- $ package ->expects ($ this ->any ())->method ('getState ' )->willReturn (0 );
114
- $ package ->expects ($ this ->exactly (2 ))->method ('getParent ' )->willReturn (true );
115
- $ package ->expects ($ this ->any ())->method ('getArea ' )->willReturn ('area ' );
116
- $ package ->expects ($ this ->any ())->method ('getPath ' )->willReturn ('path ' );
117
- $ package ->expects ($ this ->any ())->method ('getFiles ' )->willReturn ([]);
118
- $ this ->logger ->expects ($ this ->exactly (2 ))->method ('info ' )->willReturnSelf ();
141
+ $ queue = new Queue (
142
+ $ this ->appState ,
143
+ $ this ->localeResolver ,
144
+ $ this ->resourceConnection ,
145
+ $ this ->logger ,
146
+ $ this ->deployPackageService ,
147
+ [],
148
+ 0
149
+ );
119
150
120
- $ this ->appState ->expects ($ this ->once ())->method ('emulateAreaCode ' );
151
+ $ this ->package ->expects ($ this ->any ())->method ('getState ' )->willReturn (0 );
152
+ $ this ->package ->expects ($ this ->exactly (2 ))->method ('getParent ' )->willReturn (true );
153
+ $ this ->package ->expects ($ this ->any ())->method ('getArea ' )->willReturn ('global ' );
154
+ $ this ->package ->expects ($ this ->any ())->method ('getPath ' )->willReturn ('path ' );
155
+ $ this ->package ->expects ($ this ->any ())->method ('getFiles ' )->willReturn ([]);
156
+ $ this ->package ->expects ($ this ->any ())->method ('getPreProcessors ' )->willReturn ([]);
157
+ $ this ->package ->expects ($ this ->any ())->method ('getPostProcessors ' )->willReturn ([]);
158
+ $ this ->logger ->expects ($ this ->exactly (3 ))->method ('info ' )->willReturnSelf ();
159
+ $ queue ->add ($ this ->package , []);
160
+ $ this ->resourceConnection ->expects (self ::never ())->method ('closeConnection ' );
161
+ $ this ->assertEquals (0 , $ queue ->process ());
162
+ }
121
163
122
- $ this ->queue ->add ($ package , []);
164
+ /**
165
+ * @see Queue::process()
166
+ * @dataProvider maxProcessesDataProvider
167
+ */
168
+ public function testProcessFailedPackagesToThrowAnException ($ maxProcesses )
169
+ {
170
+ $ this ->deployStaticFile
171
+ ->expects ($ this ->any ())
172
+ ->method ('writeFile ' )
173
+ ->willThrowException (new \Exception );
123
174
124
- $ this ->resourceConnection ->expects (self ::never ())->method ('closeConnection ' );
175
+ $ queue = new Queue (
176
+ $ this ->appState ,
177
+ $ this ->localeResolver ,
178
+ $ this ->resourceConnection ,
179
+ $ this ->logger ,
180
+ $ this ->deployPackageService ,
181
+ [],
182
+ $ maxProcesses
183
+ );
125
184
126
- $ this ->assertEquals (0 , $ this ->queue ->process ());
185
+ $ this ->package ->expects ($ this ->any ())->method ('getState ' )->willReturn (0 );
186
+ $ this ->package ->expects ($ this ->any ())->method ('getParent ' )->willReturn (true );
187
+ $ this ->package ->expects ($ this ->any ())->method ('getArea ' )->willReturn ('global ' );
188
+ $ this ->package ->expects ($ this ->any ())->method ('getPath ' )->willReturn ('path ' );
189
+ $ this ->package ->expects ($ this ->any ())->method ('getFiles ' )->willReturn ([$ this ->packageFile ]);
190
+ $ this ->package ->expects ($ this ->any ())->method ('getPreProcessors ' )->willReturn ([]);
191
+ $ this ->package ->expects ($ this ->any ())->method ('getPostProcessors ' )->willReturn ([]);
192
+ $ this ->logger ->expects ($ this ->any ())->method ('info ' )->willReturnSelf ();
193
+ $ queue ->add ($ this ->package , []);
194
+ $ this ->expectException (\RuntimeException::class);
195
+ $ queue ->process ();
127
196
}
197
+
198
+ /**
199
+ * @return int[]
200
+ */
201
+ public function maxProcessesDataProvider (): array
202
+ {
203
+ return [
204
+ [0 ],
205
+ [1 ]
206
+ ];
207
+ }
208
+
128
209
}
0 commit comments