11
11
use Magento \Framework \App \Config \ScopeConfigInterface ;
12
12
use Magento \Framework \App \Helper \Context ;
13
13
use Magento \Framework \App \Request \Http ;
14
+ use Magento \Framework \App \ScopeResolverInterface ;
14
15
use Magento \Framework \Exception \ValidatorException ;
15
16
use Magento \Framework \Filesystem ;
16
17
use Magento \Framework \Filesystem \Directory \Read ;
17
18
use Magento \Framework \Filesystem \Directory \Write ;
18
19
use Magento \Framework \HTTP \Adapter \FileTransferFactory ;
19
20
use Magento \Framework \Indexer \IndexerRegistry ;
21
+ use Magento \Framework \Locale \ResolverInterface ;
20
22
use Magento \Framework \Phrase ;
23
+ use Magento \Framework \Stdlib \DateTime ;
24
+ use Magento \Framework \Stdlib \DateTime \Intl \DateFormatterFactory ;
21
25
use Magento \Framework \Stdlib \DateTime \Timezone ;
22
26
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
23
27
use Magento \ImportExport \Helper \Data ;
@@ -49,11 +53,6 @@ class ReportTest extends TestCase
49
53
*/
50
54
protected $ context ;
51
55
52
- /**
53
- * @var Timezone|MockObject
54
- */
55
- protected $ timezone ;
56
-
57
56
/**
58
57
* @var Filesystem|MockObject
59
58
*/
@@ -89,11 +88,6 @@ protected function setUp(): void
89
88
->disableOriginalConstructor ()
90
89
->getMock ();
91
90
$ this ->context ->expects ($ this ->any ())->method ('getRequest ' )->willReturn ($ this ->requestMock );
92
- $ this ->timezone = $ this ->getMockBuilder (Timezone::class)
93
- ->addMethods (['diff ' , 'format ' ])
94
- ->onlyMethods (['date ' , 'getConfigTimezone ' ])
95
- ->disableOriginalConstructor ()
96
- ->getMock ();
97
91
$ this ->varDirectory = $ this ->createPartialMock (
98
92
Write::class,
99
93
['getRelativePath ' , 'getAbsolutePath ' , 'readFile ' , 'isFile ' , 'stat ' ]
@@ -143,7 +137,7 @@ protected function setUp(): void
143
137
Report::class,
144
138
[
145
139
'context ' => $ this ->context ,
146
- 'timeZone ' => $ this ->timezone ,
140
+ 'timeZone ' => $ this ->getTimezone () ,
147
141
'filesystem ' =>$ this ->filesystem
148
142
]
149
143
);
@@ -162,13 +156,27 @@ public function testGetExecutionTime()
162
156
163
157
$ startDateMock = $ this ->createTestProxy (\DateTime::class, ['time ' => $ startDate ]);
164
158
$ endDateMock = $ this ->createTestProxy (\DateTime::class, ['time ' => $ endDate ]);
165
- $ this ->timezone ->method ('date ' )
159
+ $ this ->getTimezone () ->method ('date ' )
166
160
->withConsecutive ([$ startDate ], [])
167
161
->willReturnOnConsecutiveCalls ($ startDateMock , $ endDateMock );
168
162
169
163
$ this ->assertEquals ($ executionTime , $ this ->report ->getExecutionTime ($ startDate ));
170
164
}
171
165
166
+ /**
167
+ * Assert the report update execution time with default UTC timezone.
168
+ *
169
+ * @return void
170
+ */
171
+ public function testGetExecutionTimeDefaultTimezone ()
172
+ {
173
+ $ this ->assertEquals (
174
+ '00:00:03 ' ,
175
+ $ this ->report ->getExecutionTime ((new \DateTime ('now - 3seconds ' ))->format ('Y-m-d H:i:s ' )),
176
+ 'Report update execution time is not a match. '
177
+ );
178
+ }
179
+
172
180
/**
173
181
* Test getExecutionTime()
174
182
*/
@@ -306,4 +314,34 @@ public function testGetDelimiter()
306
314
$ this ->report ->getDelimiter ()
307
315
);
308
316
}
317
+
318
+ /**
319
+ * Returns Timezone, UTC by default
320
+ *
321
+ * @param string $timezone
322
+ * @return Timezone|MockObject
323
+ */
324
+ private function getTimezone (string $ timezone = 'UTC ' ): Timezone |MockObject
325
+ {
326
+ $ localeResolver = $ this ->getMockBuilder (ResolverInterface::class)->getMock ();
327
+ $ scopeResolver = $ this ->getMockBuilder (ScopeResolverInterface::class)->getMock ();
328
+ $ dateTime = $ this ->getMockBuilder (DateTime::class)->getMock ();
329
+ $ scopeConfig = $ this ->getMockBuilder (ScopeConfigInterface::class)->getMock ();
330
+ $ timezoneMock = $ this ->getMockBuilder (Timezone::class)
331
+ ->addMethods (['diff ' , 'format ' ])
332
+ ->onlyMethods (['getConfigTimezone ' ])
333
+ ->setConstructorArgs ([
334
+ 'scopeResolver ' => $ scopeResolver ,
335
+ 'localeResolver ' => $ localeResolver ,
336
+ 'dateTime ' => $ dateTime ,
337
+ 'scopeConfig ' => $ scopeConfig ,
338
+ 'scopeType ' => 'default ' ,
339
+ 'defaultTimezonePath ' => 'general/locale/timezone ' ,
340
+ 'dateFormatterFactory ' => (new DateFormatterFactory ())
341
+ ])->getMock ();
342
+
343
+ $ timezoneMock ->method ('getConfigTimezone ' )->willReturn ($ timezone );
344
+
345
+ return $ timezoneMock ;
346
+ }
309
347
}
0 commit comments