7 declare(strict_types=1);
35 private $productUrlMock;
40 private $outputHelperMock;
45 private $objectManagerHelper;
50 private $productValueMap = [
59 $this->helperMock = $this->getMockBuilder(Compare::class)
60 ->disableOriginalConstructor()
62 $this->productUrlMock = $this->getMockBuilder(Url::class)
63 ->disableOriginalConstructor()
65 $this->outputHelperMock = $this->getMockBuilder(Output::class)
66 ->disableOriginalConstructor()
69 $this->objectManagerHelper =
new ObjectManagerHelper($this);
71 $this->model = $this->objectManagerHelper->getObject(
72 CompareProducts::class,
74 'helper' => $this->helperMock,
75 'productUrl' => $this->productUrlMock,
76 'outputHelper' => $this->outputHelperMock
87 private function getItemCollectionMock(array
$items) : \PHPUnit_Framework_MockObject_MockObject
89 $itemCollectionMock = $this->getMockBuilder(Collection::class)
90 ->disableOriginalConstructor()
93 $itemCollectionMock->expects($this->any())
94 ->method(
'getIterator')
95 ->willReturn(
new \ArrayIterator(
$items));
97 return $itemCollectionMock;
106 private function prepareProductsWithCorrespondingMocks(array $dataSet) : array
115 foreach ($dataSet as
$data) {
119 $outputMap[] = [
$item,
$data[
'name'],
'name',
'productName#' .
$data[
'id']];
120 $helperMap[] = [
$item,
'http://remove.url/' .
$data[
'id']];
121 $urlMap[] = [
$item, [],
'http://product.url/' .
$data[
'id']];
124 $this->productUrlMock->expects($this->exactly(
$count))
126 ->will($this->returnValueMap($urlMap));
128 $this->outputHelperMock->expects($this->exactly(
$count))
129 ->method(
'productAttribute')
130 ->will($this->returnValueMap($outputMap));
132 $this->helperMock->expects($this->exactly(
$count))
133 ->method(
'getPostDataRemove')
134 ->will($this->returnValueMap($helperMap));
145 private function getProductMock(array
$data) : \PHPUnit_Framework_MockObject_MockObject
147 $product = $this->getMockBuilder(Product::class)
148 ->disableOriginalConstructor()
153 ->method($this->productValueMap[
$index])
163 [
'id' => 1,
'name' =>
'product#1'],
164 [
'id' => 2,
'name' =>
'product#2'],
165 [
'id' => 3,
'name' =>
'product#3']
170 $this->helperMock->expects($this->once())
171 ->method(
'getItemCount')
174 $items = $this->prepareProductsWithCorrespondingMocks($dataSet);
176 $itemCollectionMock = $this->getItemCollectionMock(
$items);
178 $this->helperMock->expects($this->once())
179 ->method(
'getItemCollection')
180 ->willReturn($itemCollectionMock);
182 $this->helperMock->expects($this->once())
183 ->method(
'getListUrl')
184 ->willReturn(
'http://list.url');
189 'countCaption' =>
__(
'%1 items',
$count),
190 'listUrl' =>
'http://list.url',
194 'product_url' =>
'http://product.url/1',
195 'name' =>
'productName#1',
196 'remove_url' =>
'http://remove.url/1' 200 'product_url' =>
'http://product.url/2',
201 'name' =>
'productName#2',
202 'remove_url' =>
'http://remove.url/2' 206 'product_url' =>
'http://product.url/3',
207 'name' =>
'productName#3',
208 'remove_url' =>
'http://remove.url/3' 212 $this->model->getSectionData()
220 $this->helperMock->expects($this->once())
221 ->method(
'getItemCount')
224 $this->helperMock->expects($this->never())
225 ->method(
'getItemCollection');
227 $this->helperMock->expects($this->once())
228 ->method(
'getListUrl')
229 ->willReturn(
'http://list.url');
234 'countCaption' =>
__(
'%1 items',
$count),
235 'listUrl' =>
'http://list.url',
238 $this->model->getSectionData()
246 $this->helperMock->expects($this->once())
247 ->method(
'getItemCount')
250 $items = $this->prepareProductsWithCorrespondingMocks(
254 'name' =>
'SingleProduct' 259 $itemCollectionMock = $this->getItemCollectionMock(
$items);
261 $this->helperMock->expects($this->once())
262 ->method(
'getItemCollection')
263 ->willReturn($itemCollectionMock);
265 $this->helperMock->expects($this->once())
266 ->method(
'getListUrl')
267 ->willReturn(
'http://list.url');
272 'countCaption' =>
__(
'1 item'),
273 'listUrl' =>
'http://list.url',
277 'product_url' =>
'http://product.url/12345',
278 'name' =>
'productName#12345',
279 'remove_url' =>
'http://remove.url/12345' 283 $this->model->getSectionData()
testGetSectionDataNoItems()
testGetSectionDataSingleItem()