Skip to content

Commit f3876c1

Browse files
committed
Merge branch 'ACP2E-2710' of https://github.com/magento-l3/magento2ce into 2.4-develop
2 parents 3428ebc + 59781f1 commit f3876c1

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

app/code/Magento/ImportExport/Helper/Report.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct(
6161
*/
6262
public function getExecutionTime($time)
6363
{
64-
$reportTime = $this->timeZone->date($time);
64+
$reportTime = $this->timeZone->date(new \DateTime($time));
6565
$timeDiff = $reportTime->diff($this->timeZone->date());
6666
return $timeDiff->format('%H:%I:%S');
6767
}

app/code/Magento/ImportExport/Test/Unit/Helper/ReportTest.php

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111
use Magento\Framework\App\Config\ScopeConfigInterface;
1212
use Magento\Framework\App\Helper\Context;
1313
use Magento\Framework\App\Request\Http;
14+
use Magento\Framework\App\ScopeResolverInterface;
1415
use Magento\Framework\Exception\ValidatorException;
1516
use Magento\Framework\Filesystem;
1617
use Magento\Framework\Filesystem\Directory\Read;
1718
use Magento\Framework\Filesystem\Directory\Write;
1819
use Magento\Framework\HTTP\Adapter\FileTransferFactory;
1920
use Magento\Framework\Indexer\IndexerRegistry;
21+
use Magento\Framework\Locale\ResolverInterface;
2022
use Magento\Framework\Phrase;
23+
use Magento\Framework\Stdlib\DateTime;
24+
use Magento\Framework\Stdlib\DateTime\Intl\DateFormatterFactory;
2125
use Magento\Framework\Stdlib\DateTime\Timezone;
2226
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
2327
use 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

Comments
 (0)