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