Skip to content

Commit eede410

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-58855' into 2.1.8-develop-pr17
2 parents 437c1c2 + 899eda8 commit eede410

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

app/code/Magento/SalesRule/Model/CouponRepository.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,16 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
172172
($sortOrder->getDirection() == SortOrder::SORT_ASC) ? 'ASC' : 'DESC'
173173
);
174174
}
175+
175176
$collection->setCurPage($searchCriteria->getCurrentPage());
176177
$collection->setPageSize($searchCriteria->getPageSize());
177178

178-
$coupons = [];
179-
/** @var \Magento\SalesRule\Model\Coupon $couponModel */
180-
foreach ($collection->getItems() as $couponModel) {
181-
$coupons[] = $couponModel->getData();
182-
}
183-
179+
/** @var \Magento\SalesRule\Api\Data\CouponSearchResultInterface $searchResults */
184180
$searchResults = $this->searchResultFactory->create();
185181
$searchResults->setSearchCriteria($searchCriteria);
186-
$searchResults->setItems($coupons);
182+
$searchResults->setItems($collection->getItems());
187183
$searchResults->setTotalCount($collection->getSize());
184+
188185
return $searchResults;
189186
}
190187

app/code/Magento/SalesRule/Test/Unit/Model/CouponRepositoryTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\SalesRule\Test\Unit\Model;
77

88
use Magento\Framework\Api\SortOrder;
9+
use Magento\SalesRule\Api\Data\CouponInterface;
910

1011
class CouponRepositoryTest extends \PHPUnit_Framework_TestCase
1112
{
@@ -214,6 +215,11 @@ public function testGetList()
214215
$currentPage = 42;
215216
$pageSize = 4;
216217

218+
/** @var CouponInterface|\PHPUnit_Framework_MockObject_MockObject $couponMock */
219+
$couponMock = $this->getMockBuilder(CouponInterface::class)
220+
->disableOriginalConstructor()
221+
->getMock();
222+
217223
/**
218224
* @var \Magento\Framework\Api\SearchCriteriaInterface $searchCriteriaMock
219225
*/
@@ -248,8 +254,8 @@ public function testGetList()
248254
$collectionMock->expects($this->once())->method('setCurPage')->with($currentPage);
249255
$searchCriteriaMock->expects($this->once())->method('getPageSize')->willReturn($pageSize);
250256
$collectionMock->expects($this->once())->method('setPageSize')->with($pageSize);
251-
$collectionMock->expects($this->once())->method('getItems')->willReturn([]);
252-
$this->searchResultsMock->expects($this->once())->method('setItems')->with([]);
257+
$collectionMock->expects($this->once())->method('getItems')->willReturn([$couponMock]);
258+
$this->searchResultsMock->expects($this->once())->method('setItems')->with([$couponMock]);
253259
$this->searchResultFactory->expects($this->once())->method('create')->willReturn($this->searchResultsMock);
254260

255261
$this->assertEquals($this->searchResultsMock, $this->model->getList($searchCriteriaMock));

0 commit comments

Comments
 (0)