1111use Magento \Framework \App \Config \ScopeConfigInterface ;
1212use Magento \Framework \App \Helper \Context ;
1313use Magento \Framework \App \Request \Http ;
14+ use Magento \Framework \App \ScopeResolverInterface ;
1415use Magento \Framework \Exception \ValidatorException ;
1516use Magento \Framework \Filesystem ;
1617use Magento \Framework \Filesystem \Directory \Read ;
1718use Magento \Framework \Filesystem \Directory \Write ;
1819use Magento \Framework \HTTP \Adapter \FileTransferFactory ;
1920use Magento \Framework \Indexer \IndexerRegistry ;
21+ use Magento \Framework \Locale \ResolverInterface ;
2022use Magento \Framework \Phrase ;
23+ use Magento \Framework \Stdlib \DateTime ;
24+ use Magento \Framework \Stdlib \DateTime \Intl \DateFormatterFactory ;
2125use Magento \Framework \Stdlib \DateTime \Timezone ;
2226use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
2327use Magento \ImportExport \Helper \Data ;
@@ -49,11 +53,6 @@ class ReportTest extends TestCase
4953 */
5054 protected $ context ;
5155
52- /**
53- * @var Timezone|MockObject
54- */
55- protected $ timezone ;
56-
5756 /**
5857 * @var Filesystem|MockObject
5958 */
@@ -89,11 +88,6 @@ protected function setUp(): void
8988 ->disableOriginalConstructor ()
9089 ->getMock ();
9190 $ 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 ();
9791 $ this ->varDirectory = $ this ->createPartialMock (
9892 Write::class,
9993 ['getRelativePath ' , 'getAbsolutePath ' , 'readFile ' , 'isFile ' , 'stat ' ]
@@ -143,7 +137,7 @@ protected function setUp(): void
143137 Report::class,
144138 [
145139 'context ' => $ this ->context ,
146- 'timeZone ' => $ this ->timezone ,
140+ 'timeZone ' => $ this ->getTimezone () ,
147141 'filesystem ' =>$ this ->filesystem
148142 ]
149143 );
@@ -162,13 +156,27 @@ public function testGetExecutionTime()
162156
163157 $ startDateMock = $ this ->createTestProxy (\DateTime::class, ['time ' => $ startDate ]);
164158 $ endDateMock = $ this ->createTestProxy (\DateTime::class, ['time ' => $ endDate ]);
165- $ this ->timezone ->method ('date ' )
159+ $ this ->getTimezone () ->method ('date ' )
166160 ->withConsecutive ([$ startDate ], [])
167161 ->willReturnOnConsecutiveCalls ($ startDateMock , $ endDateMock );
168162
169163 $ this ->assertEquals ($ executionTime , $ this ->report ->getExecutionTime ($ startDate ));
170164 }
171165
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+
172180 /**
173181 * Test getExecutionTime()
174182 */
@@ -306,4 +314,34 @@ public function testGetDelimiter()
306314 $ this ->report ->getDelimiter ()
307315 );
308316 }
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+ }
309347}
0 commit comments