Skip to content

Commit 1e298b0

Browse files
committed
AC-2765::Modified Code for testcase in CollectionTest.php
1 parent 5532461 commit 1e298b0

File tree

1 file changed

+95
-15
lines changed
  • dev/tests/integration/testsuite/Magento/Review/Model/ResourceModel/Review/Summary

1 file changed

+95
-15
lines changed

dev/tests/integration/testsuite/Magento/Review/Model/ResourceModel/Review/Summary/CollectionTest.php

Lines changed: 95 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,120 @@
77

88
namespace Magento\Review\Model\ResourceModel\Review\Summary;
99

10+
use Magento\Framework\Data\Collection\Db\FetchStrategy\Query;
11+
use Magento\Framework\Data\Collection\EntityFactory;
12+
use Magento\Framework\DB\Adapter\AdapterInterface;
13+
use Magento\Framework\DB\Adapter\Pdo\Mysql;
1014
use Magento\Framework\DB\Select;
15+
use Magento\Framework\DB\Select\SelectRenderer;
16+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
17+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1118
use Magento\Review\Model\ResourceModel\Review\Summary\Collection;
1219
use PHPUnit\Framework\MockObject\MockObject;
20+
use Psr\Log\LoggerInterface;
21+
1322

1423
/**
15-
* Tests some functionality of the Product Review collection
24+
* Tests some functionality of the Review Summary collection
1625
*/
1726
class CollectionTest extends \PHPUnit\Framework\TestCase
1827
{
1928
/**
20-
* @var Collection|MockObject
29+
* @var Collection
30+
*/
31+
protected Collection $collection;
32+
33+
/**
34+
* @var Query|MockObject
2135
*/
22-
protected Collection|MockObject $_model;
36+
protected Query|MockObject $fetchStrategyMock;
37+
38+
/**
39+
* @var EntityFactory|MockObject
40+
*/
41+
protected EntityFactory|MockObject $entityFactoryMock;
42+
43+
/**
44+
* @var LoggerInterface|MockObject
45+
*/
46+
protected LoggerInterface|MockObject $loggerMock;
47+
48+
/**
49+
* @var AbstractDb|MockObject
50+
*/
51+
protected MockObject|AbstractDb $resourceMock;
52+
53+
/**
54+
* @var AdapterInterface|MockObject
55+
*/
56+
protected MockObject|Mysql|AdapterInterface $connectionMock;
57+
58+
/**
59+
* @var Select|MockObject
60+
*/
61+
protected Select|MockObject $selectMock;
2362

2463
protected function setUp(): void
2564
{
26-
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(Collection::class);
65+
$this->fetchStrategyMock = $this->createPartialMock(
66+
Query::class,
67+
['fetchAll']
68+
);
69+
$this->entityFactoryMock = $this->createPartialMock(
70+
EntityFactory::class,
71+
['create']
72+
);
73+
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
74+
$this->resourceMock = $this->getMockBuilder(AbstractDb::class)
75+
->setMethods(['getConnection', 'getMainTable', 'getTable'])
76+
->disableOriginalConstructor()
77+
->getMockForAbstractClass();
78+
$this->connectionMock = $this->createPartialMock(
79+
Mysql::class,
80+
['select', 'query']
81+
);
82+
$selectRenderer = $this->getMockBuilder(SelectRenderer::class)
83+
->disableOriginalConstructor()
84+
->getMock();
85+
$this->selectMock = $this->getMockBuilder(Select::class)
86+
->setMethods(['where'])
87+
->setConstructorArgs(['adapter' => $this->connectionMock, 'selectRenderer' => $selectRenderer])
88+
->getMock();
89+
$this->connectionMock->expects($this->once())
90+
->method('select')
91+
->willReturn($this->selectMock);
92+
$this->resourceMock->expects($this->once())
93+
->method('getConnection')
94+
->willReturn($this->connectionMock);
95+
$this->resourceMock->expects($this->once())
96+
->method('getMainTable')
97+
->willReturn('main_table_name');
98+
99+
$this->resourceMock->expects($this->once())
100+
->method('getTable')
101+
->willReturnArgument(0);
102+
$objectManager = new ObjectManager($this);
103+
$this->collection = $objectManager->getObject(
104+
Collection::class,
105+
[
106+
'entityFactory' => $this->entityFactoryMock,
107+
'logger' => $this->loggerMock,
108+
'fetchStrategy' => $this->fetchStrategyMock,
109+
'resource' => $this->resourceMock
110+
]
111+
);
27112
}
28113

29114
/**
30115
* @param array|int $storeId
116+
* @param string $expectedQuery
31117
* @dataProvider storeIdDataProvider
32118
*/
33-
public function testAddStoreFilter(array|int $storeId)
119+
public function testAddStoreFilter(array|int $storeId, string $expectedQuery)
34120
{
35-
$expectedWhere = is_numeric($storeId) ? 'store_id = ?' : 'store_id IN (?)';
36-
37-
$select = $this->createPartialMock(Select::class, ['where']);
38-
$select->expects( $this->any())
39-
->method('where')
40-
->with($this->equalTo($expectedWhere))
41-
->willReturnSelf();
121+
$this->selectMock->expects($this->once())->method('where')->with($expectedQuery, $storeId);
122+
$this->collection->addStoreFilter($storeId);
42123

43-
$this->assertEquals($this->_model, $this->_model->addStoreFilter($storeId));
44124
}
45125

46126
/**
@@ -49,8 +129,8 @@ public function testAddStoreFilter(array|int $storeId)
49129
public function storeIdDataProvider(): array
50130
{
51131
return [
52-
[1],
53-
[1, [1,2]]
132+
[1, 'store_id = ?'],
133+
[[1,2], 'store_id IN (?)']
54134
];
55135
}
56136
}

0 commit comments

Comments
 (0)