88namespace Magento \Deploy \Test \Unit \Process ;
99
1010use Magento \Deploy \Package \Package ;
11- use Magento \Deploy \Package \PackageFile ;
1211use Magento \Deploy \Process \Queue ;
1312use Magento \Deploy \Service \DeployPackage ;
14- use Magento \Deploy \Service \DeployStaticFile ;
1513use Magento \Framework \App \ResourceConnection ;
14+
1615use Magento \Framework \App \State as AppState ;
17- use Magento \Framework \Config \ScopeInterface ;
1816use Magento \Framework \Locale \ResolverInterface as LocaleResolver ;
1917use PHPUnit \Framework \MockObject \MockObject as Mock ;
2018use PHPUnit \Framework \TestCase ;
19+
2120use Psr \Log \LoggerInterface ;
2221
2322/**
2827class QueueTest extends TestCase
2928{
3029 /**
31- * @var AppState
30+ * @var Queue
31+ */
32+ private $ queue ;
33+
34+ /**
35+ * @var AppState|Mock
3236 */
3337 private $ appState ;
3438
@@ -48,64 +52,39 @@ class QueueTest extends TestCase
4852 private $ logger ;
4953
5054 /**
51- * @var DeployPackage
55+ * @var DeployPackage|Mock
5256 */
5357 private $ deployPackageService ;
5458
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-
7059 /**
7160 * @inheritdoc
7261 */
7362 protected function setUp (): void
7463 {
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);
8565 $ this ->localeResolver = $ this ->getMockForAbstractClass (
8666 LocaleResolver::class,
8767 ['setLocale ' ],
8868 '' ,
8969 false
9070 );
91-
71+ $ this -> resourceConnection = $ this -> createMock (ResourceConnection::class);
9272 $ this ->logger = $ this ->getMockForAbstractClass (
9373 LoggerInterface::class,
9474 ['notice ' , 'info ' ],
9575 '' ,
9676 false
9777 );
78+ $ this ->deployPackageService = $ this ->createPartialMock (DeployPackage::class, ['deploy ' ]);
9879
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 (
10581 $ this ->appState ,
10682 $ this ->localeResolver ,
107- $ this ->deployStaticFile ,
108- $ this ->logger
83+ $ this ->resourceConnection ,
84+ $ this ->logger ,
85+ $ this ->deployPackageService ,
86+ [],
87+ 1
10988 );
11089 }
11190
@@ -114,21 +93,13 @@ protected function setUp(): void
11493 */
11594 public function testAdd ()
11695 {
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 ' );
12698
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 ();
130101 $ this ->assertEquals (
131- $ this -> package ,
102+ $ package ,
132103 isset ($ packages ['path ' ]['package ' ]) ? $ packages ['path ' ]['package ' ] : null
133104 );
134105 }
@@ -138,72 +109,20 @@ public function testAdd()
138109 */
139110 public function testProcess ()
140111 {
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 ();
150119
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 ' );
163121
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 , []);
174123
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 ' );
184125
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 ());
196127 }
197-
198- /**
199- * @return int[]
200- */
201- public function maxProcessesDataProvider (): array
202- {
203- return [
204- [0 ],
205- [1 ]
206- ];
207- }
208-
209128}
0 commit comments