Skip to content

Commit c0e67a3

Browse files
committed
ACP2E-3189: additional unit test
1 parent 5d658c0 commit c0e67a3

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Report/BestsellersTest.php

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Magento\Sales\Model\ResourceModel\Report\Bestsellers;
2222
use Magento\Store\Api\Data\StoreInterface;
2323
use Magento\Store\Model\StoreManagerInterface;
24+
use PHPUnit\Framework\Attributes\DataProvider;
25+
use PHPUnit\Framework\MockObject\Exception;
2426
use PHPUnit\Framework\MockObject\MockObject;
2527
use PHPUnit\Framework\TestCase;
2628
use Psr\Log\LoggerInterface;
@@ -95,6 +97,24 @@ class BestsellersTest extends TestCase
9597
*/
9698
protected string $connectionName = 'connection_name';
9799

100+
/**
101+
* Data provider for testAggregateWithMultipleOrderDatesAndNoDates
102+
*
103+
* @return array
104+
*/
105+
public static function datesDataProvider(): array
106+
{
107+
$randomDates = [];
108+
for ($i = 0; $i < 10000; $i++) {
109+
$randomDates[] = date('Y-m-d', rand(0, time()));
110+
}
111+
return [
112+
'from-to interval' => [new \DateTime('yesterday'), new \DateTime(), $randomDates],
113+
'from interval' => [new \DateTime('yesterday'), null, $randomDates],
114+
'from interval no dates' => [new \DateTime('yesterday'), null, []]
115+
];
116+
}
117+
98118
/**
99119
* @inheritDoc
100120
*/
@@ -307,16 +327,18 @@ public function testAggregatePerStoreCalculationNoInterval(): void
307327
}
308328

309329
/**
330+
* @param \DateTime|null $from
331+
* @param \DateTime|null $to
332+
* @param array $randomDates
310333
* @return void
311-
* @throws \Exception
334+
* @throws Exception
312335
*/
313-
public function testAggregateWithMultipleOrderDates(): void
314-
{
315-
$from = new \DateTime('yesterday');
316-
$to = null;
317-
for ($i = 0; $i < 10000; $i++) {
318-
$randomDates[] = date('Y-m-d', rand(0, time()));
319-
}
336+
#[DataProvider('datesDataProvider')]
337+
public function testAggregateWithMultipleOrderDatesAndNoDates(
338+
?\DateTime $from,
339+
?\DateTime $to,
340+
array $randomDates
341+
): void {
320342
$periodExpr = 'DATE(DATE_ADD(`source_table`.`created_at`, INTERVAL -25200 SECOND))';
321343
$select = $this->getMockBuilder(Select::class)
322344
->disableOriginalConstructor()
@@ -336,7 +358,11 @@ public function testAggregateWithMultipleOrderDates(): void
336358
$connection->expects($this->any())->method('select')->willReturn($select);
337359
$query = $this->createMock(\Zend_Db_Statement_Interface::class);
338360
$query->expects($this->once())->method('fetchAll')->willReturn($randomDates);
339-
$connection->expects($this->exactly(4))->method('query')->willReturn($query);
361+
$calls = 3;
362+
if ($from && $to) {
363+
$calls = 4;
364+
}
365+
$connection->expects($this->exactly($calls))->method('query')->willReturn($query);
340366
$resource = $this->createMock(ResourceConnection::class);
341367
$resource->expects($this->any())
342368
->method('getConnection')

0 commit comments

Comments
 (0)