Skip to content

Commit 6154e18

Browse files
author
Ievgen Sentiabov
committed
MAGETWO-44113: Creating Ratings in the Frontend (not available after Magento installation)
- Changed constructor mocks - Refactored code related to code review
1 parent 4ef40c9 commit 6154e18

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,32 @@ class ReviewTest extends \PHPUnit_Framework_TestCase
3131
/**
3232
* @var \Magento\Review\Model\ResourceModel\Review\Collection|\PHPUnit_Framework_MockObject_MockObject
3333
*/
34-
private $collectionMock;
34+
private $collection;
3535

3636
/**
3737
* @var \Magento\Review\Model\ResourceModel\Review\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
3838
*/
39-
private $collectionFactoryMock;
39+
private $collectionFactory;
4040

4141
/**
4242
* @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject
4343
*/
44-
private $registryMock;
44+
private $registry;
4545

4646
/**
4747
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
4848
*/
49-
private $productMock;
49+
private $product;
5050

5151
/**
52-
* @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject
52+
* @var \Magento\Store\Model\StoreManager|\PHPUnit_Framework_MockObject_MockObject
5353
*/
54-
private $contextMock;
54+
private $storeManager;
5555

5656
/**
57-
* @va rMagento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
57+
* @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
5858
*/
59-
private $storeMock;
59+
private $store;
6060

6161
protected function setUp()
6262
{
@@ -66,9 +66,9 @@ protected function setUp()
6666

6767
$helper = new ObjectManager($this);
6868
$this->block = $helper->getObject(ReviewBlock::class, [
69-
'context' => $this->contextMock,
70-
'registry' => $this->registryMock,
71-
'collectionFactory' => $this->collectionFactoryMock,
69+
'storeManager' => $this->storeManager,
70+
'registry' => $this->registry,
71+
'collectionFactory' => $this->collectionFactory,
7272
]);
7373
}
7474

@@ -85,32 +85,32 @@ public function testGetIdentities()
8585
*/
8686
private function initCollectionMocks()
8787
{
88-
$this->collectionMock = $this->getMockBuilder(Collection::class)
88+
$this->collection = $this->getMockBuilder(Collection::class)
8989
->disableOriginalConstructor()
9090
->setMethods(['addStoreFilter', 'addStatusFilter', 'addEntityFilter', 'getSize', '__wakeup'])
9191
->getMock();
9292

93-
$this->collectionMock->expects(static::any())
93+
$this->collection->expects(static::any())
9494
->method('addStoreFilter')
9595
->willReturnSelf();
9696

97-
$this->collectionMock->expects(static::any())
97+
$this->collection->expects(static::any())
9898
->method('addStatusFilter')
9999
->with(Review::STATUS_APPROVED)
100100
->willReturnSelf();
101101

102-
$this->collectionMock->expects(static::any())
102+
$this->collection->expects(static::any())
103103
->method('addEntityFilter')
104104
->willReturnSelf();
105105

106-
$this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
106+
$this->collectionFactory = $this->getMockBuilder(CollectionFactory::class)
107107
->disableOriginalConstructor()
108108
->setMethods(['create', '__wakeup'])
109109
->getMock();
110110

111-
$this->collectionFactoryMock->expects(static::once())
111+
$this->collectionFactory->expects(static::once())
112112
->method('create')
113-
->willReturn($this->collectionMock);
113+
->willReturn($this->collection);
114114
}
115115

116116
/**
@@ -119,23 +119,23 @@ private function initCollectionMocks()
119119
private function initRegistryMock()
120120
{
121121
$this->initProductMock();
122-
$this->registryMock = $this->getMockBuilder(Registry::class)
122+
$this->registry = $this->getMockBuilder(Registry::class)
123123
->disableOriginalConstructor()
124124
->setMethods(['registry'])
125125
->getMock();
126126

127-
$this->registryMock->expects(static::once())
127+
$this->registry->expects(static::once())
128128
->method('registry')
129129
->with('product')
130-
->willReturn($this->productMock);
130+
->willReturn($this->product);
131131
}
132132

133133
/**
134134
* Create mock object for catalog product
135135
*/
136136
private function initProductMock()
137137
{
138-
$this->productMock = $this->getMockBuilder(Product::class)
138+
$this->product = $this->getMockBuilder(Product::class)
139139
->disableOriginalConstructor()
140140
->setMethods(['getId'])
141141
->getMock();
@@ -146,27 +146,18 @@ private function initProductMock()
146146
*/
147147
private function initContextMock()
148148
{
149-
$this->storeMock = $this->getMockBuilder(Store::class)
149+
$this->store = $this->getMockBuilder(Store::class)
150150
->disableOriginalConstructor()
151151
->setMethods(['getId', '__wakeup'])
152152
->getMock();
153153

154-
$storeManager = $this->getMockBuilder(StoreManager::class)
154+
$this->storeManager = $this->getMockBuilder(StoreManager::class)
155155
->disableOriginalConstructor()
156156
->setMethods(['getStore', '__wakeup'])
157157
->getMock();
158158

159-
$storeManager->expects(static::once())
159+
$this->storeManager->expects(static::any())
160160
->method('getStore')
161-
->willReturn($this->storeMock);
162-
163-
$this->contextMock = $this->getMockBuilder(Context::class)
164-
->disableOriginalConstructor()
165-
->setMethods(['getStoreManager'])
166-
->getMock();
167-
168-
$this->contextMock->expects(static::once())
169-
->method('getStoreManager')
170-
->willReturn($storeManager);
161+
->willReturn($this->store);
171162
}
172163
}

0 commit comments

Comments
 (0)