File tree Expand file tree Collapse file tree 2 files changed +12
-9
lines changed
app/code/Magento/SalesRule Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -172,19 +172,16 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
172
172
($ sortOrder ->getDirection () == SortOrder::SORT_ASC ) ? 'ASC ' : 'DESC '
173
173
);
174
174
}
175
+
175
176
$ collection ->setCurPage ($ searchCriteria ->getCurrentPage ());
176
177
$ collection ->setPageSize ($ searchCriteria ->getPageSize ());
177
178
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 */
184
180
$ searchResults = $ this ->searchResultFactory ->create ();
185
181
$ searchResults ->setSearchCriteria ($ searchCriteria );
186
- $ searchResults ->setItems ($ coupons );
182
+ $ searchResults ->setItems ($ collection -> getItems () );
187
183
$ searchResults ->setTotalCount ($ collection ->getSize ());
184
+
188
185
return $ searchResults ;
189
186
}
190
187
Original file line number Diff line number Diff line change 6
6
namespace Magento \SalesRule \Test \Unit \Model ;
7
7
8
8
use Magento \Framework \Api \SortOrder ;
9
+ use Magento \SalesRule \Api \Data \CouponInterface ;
9
10
10
11
class CouponRepositoryTest extends \PHPUnit_Framework_TestCase
11
12
{
@@ -214,6 +215,11 @@ public function testGetList()
214
215
$ currentPage = 42 ;
215
216
$ pageSize = 4 ;
216
217
218
+ /** @var CouponInterface|\PHPUnit_Framework_MockObject_MockObject $couponMock */
219
+ $ couponMock = $ this ->getMockBuilder (CouponInterface::class)
220
+ ->disableOriginalConstructor ()
221
+ ->getMock ();
222
+
217
223
/**
218
224
* @var \Magento\Framework\Api\SearchCriteriaInterface $searchCriteriaMock
219
225
*/
@@ -248,8 +254,8 @@ public function testGetList()
248
254
$ collectionMock ->expects ($ this ->once ())->method ('setCurPage ' )->with ($ currentPage );
249
255
$ searchCriteriaMock ->expects ($ this ->once ())->method ('getPageSize ' )->willReturn ($ pageSize );
250
256
$ 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 ]);
253
259
$ this ->searchResultFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->searchResultsMock );
254
260
255
261
$ this ->assertEquals ($ this ->searchResultsMock , $ this ->model ->getList ($ searchCriteriaMock ));
You can’t perform that action at this time.
0 commit comments