Skip to content

Commit c86ae42

Browse files
committed
Merge branch 'MC-39827' into 2.4-bugfixes-121520
2 parents 94d99d7 + c269862 commit c86ae42

File tree

3 files changed

+53
-10
lines changed
  • app/code/Magento/SalesRule
  • dev/tests/integration/testsuite/Magento/SalesRule/Model/ResourceModel/Report

3 files changed

+53
-10
lines changed

app/code/Magento/SalesRule/Model/ResourceModel/Report/Rule.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ public function aggregate($from = null, $to = null)
9090
*/
9191
public function getUniqRulesNamesList()
9292
{
93-
$connection = $this->getConnection();
94-
$tableName = $this->getTable('salesrule_coupon_aggregated');
93+
$resourceModel = $this->_createdatFactory->create();
94+
$connection = $resourceModel->getConnection();
95+
$tableName = $resourceModel->getMainTable();
9596
$select = $connection->select()->from(
9697
$tableName,
9798
new \Zend_Db_Expr('DISTINCT rule_name')

app/code/Magento/SalesRule/Test/Unit/Model/ResourceModel/Report/RuleTest.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
namespace Magento\SalesRule\Test\Unit\Model\ResourceModel\Report;
99

10-
use Magento\Framework\App\ResourceConnection;
1110
use Magento\Framework\DB\Adapter\Pdo\Mysql;
1211
use Magento\Framework\DB\Select;
1312
use Magento\Framework\DB\Select\SelectRenderer;
1413
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1514
use Magento\Reports\Model\FlagFactory;
1615
use Magento\SalesRule\Model\ResourceModel\Report\Rule;
16+
use Magento\SalesRule\Model\ResourceModel\Report\Rule\Createdat;
1717
use Magento\SalesRule\Model\ResourceModel\Report\Rule\CreatedatFactory;
1818
use Magento\SalesRule\Model\ResourceModel\Report\Rule\UpdatedatFactory;
1919
use PHPUnit\Framework\TestCase;
@@ -84,14 +84,20 @@ function ($value) {
8484
[$this, 'fetchAllCallback']
8585
);
8686

87-
$resourceMock = $this->createMock(ResourceConnection::class);
88-
$resourceMock->expects($this->any())->method('getConnection')->willReturn($connectionMock);
89-
$resourceMock->expects($this->once())->method('getTableName')->willReturn(self::TABLE_NAME);
90-
9187
$flagFactory = $this->createMock(FlagFactory::class);
92-
$createdatFactoryMock = $this->createPartialMock(
88+
89+
$createdatResourceModel = $this->createConfiguredMock(
90+
Createdat::class,
91+
[
92+
'getConnection' => $connectionMock,
93+
'getMainTable' => self::TABLE_NAME,
94+
]
95+
);
96+
$createdatFactoryMock = $this->createConfiguredMock(
9397
CreatedatFactory::class,
94-
['create']
98+
[
99+
'create' => $createdatResourceModel
100+
]
95101
);
96102
$updatedatFactoryMock = $this->createPartialMock(
97103
UpdatedatFactory::class,
@@ -102,7 +108,6 @@ function ($value) {
102108
$model = $objectHelper->getObject(
103109
Rule::class,
104110
[
105-
'resource' => $resourceMock,
106111
'reportsFlagFactory' => $flagFactory,
107112
'createdatFactory' => $createdatFactoryMock,
108113
'updatedatFactory' => $updatedatFactoryMock
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Model\ResourceModel\Report;
9+
10+
use Magento\Sales\Model\Order;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Test for salesrule report model
16+
*/
17+
class RuleTest extends TestCase
18+
{
19+
/**
20+
* @magentoDataFixture Magento/SalesRule/_files/order_with_coupon.php
21+
*/
22+
public function testGetUniqRulesNamesList()
23+
{
24+
$ruleName = uniqid('cart_price_rule_');
25+
$orderIncrementId = '100000001';
26+
$objectManager = Bootstrap::getObjectManager();
27+
/** @var Order $order */
28+
$order = $objectManager->create(Order::class);
29+
$order->loadByIncrementId($orderIncrementId)
30+
->setCouponRuleName($ruleName)
31+
->save();
32+
/** @var Rule $reportResource */
33+
$reportResource = $objectManager->create(Rule::class);
34+
$reportResource->aggregate();
35+
$this->assertContains($ruleName, $reportResource->getUniqRulesNamesList());
36+
}
37+
}

0 commit comments

Comments
 (0)