Skip to content

Commit fe8501c

Browse files
author
Sergii Kovalenko
committed
MAGETWO-56080: SearchCriteria Unified Processing for Quote and Tax modules
1 parent 3b8dfde commit fe8501c

File tree

4 files changed

+41
-40
lines changed

4 files changed

+41
-40
lines changed

app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
use Magento\Framework\Api\SortOrder;
1111
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
12+
use Magento\Quote\Api\Data\CartInterface;
1213
use Magento\Quote\Model\QuoteRepository\LoadHandler;
14+
use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory;
1315

1416
/**
1517
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -66,10 +68,16 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase
6668
*/
6769
private $collectionProcessor;
6870

71+
/** @var \PHPUnit_Framework_MockObject_MockObject */
72+
private $objectManagerMock;
73+
6974
protected function setUp()
7075
{
7176
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
7277

78+
$this->objectManagerMock = $this->getMock(\Magento\Framework\ObjectManagerInterface::class);
79+
\Magento\Framework\App\ObjectManager::setInstance($this->objectManagerMock);
80+
7381
$this->quoteFactoryMock = $this->getMock(\Magento\Quote\Model\QuoteFactory::class, ['create'], [], '', false);
7482
$this->storeManagerMock = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class);
7583
$this->quoteMock = $this->getMock(
@@ -411,55 +419,48 @@ public function testDelete()
411419
$this->model->delete($this->quoteMock);
412420
}
413421

414-
/**
415-
* @param int $direction
416-
* @param string $expectedDirection
417-
*/
418-
public function testGetListSuccess()
422+
public function testGetList()
419423
{
420-
$this->markTestSkipped('MAGETWO-48531');
421-
$searchResult = $this->getMock(\Magento\Quote\Api\Data\CartSearchResultsInterface::class, [], [], '', false);
422-
$searchCriteriaMock = $this->getMock(\Magento\Framework\Api\SearchCriteria::class, [], [], '', false);
423-
$cartMock = $this->getMock(\Magento\Payment\Model\Cart::class, [], [], '', false);
424424
$pageSize = 10;
425+
$collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
426+
->setMethods(['create'])
427+
->disableOriginalConstructor()
428+
->getMock();
429+
$collectionFactoryMock->expects($this->once())
430+
->method('create')
431+
->willReturn($this->quoteCollectionMock);
432+
$cartMock = $this->getMock(CartInterface::class, [], [], '', false);
433+
$this->loadHandlerMock->expects($this->once())
434+
->method('load')
435+
->with($cartMock);
436+
$this->objectManagerMock->expects($this->atLeastOnce())
437+
->method('get')
438+
->willReturnOnConsecutiveCalls($collectionFactoryMock);
425439

440+
$searchResult = $this->getMock(\Magento\Quote\Api\Data\CartSearchResultsInterface::class, [], [], '', false);
441+
$searchCriteriaMock = $this->getMock(\Magento\Framework\Api\SearchCriteria::class, [], [], '', false);
426442
$this->searchResultsDataFactory
427443
->expects($this->once())
428444
->method('create')
429-
->will($this->returnValue($searchResult));
445+
->willReturn($searchResult);
430446

431-
$searchResult
432-
->expects($this->once())
433-
->method('setSearchCriteria');
434-
435-
//back in getList()
436-
$this->quoteCollectionMock->expects($this->once())->method('getSize')->willReturn($pageSize);
437-
$searchResult->expects($this->once())->method('setTotalCount')->with($pageSize);
438447
$this->collectionProcessor->expects($this->once())
439448
->method('process')
440449
->with($searchCriteriaMock, $this->quoteCollectionMock);
450+
441451
$this->extensionAttributesJoinProcessorMock->expects($this->once())
442452
->method('process')
443453
->with(
444454
$this->isInstanceOf(\Magento\Quote\Model\ResourceModel\Quote\Collection::class)
445455
);
446-
447-
$this->quoteCollectionMock->expects($this->once())->method('getItems')->willReturn([$cartMock]);
448-
$searchResult->expects($this->once())->method('setItems')->with([$cartMock]);
449-
450-
$this->model = $this->getMock(
451-
\Magento\Quote\Model\QuoteRepository::class,
452-
['getQuoteCollection'],
453-
[
454-
'quoteFactory' => $this->quoteFactoryMock,
455-
'storeManager' => $this->storeManagerMock,
456-
'quoteCollection' => $this->quoteCollectionMock,
457-
'searchResultsDataFactory' => $this->searchResultsDataFactory,
458-
'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock,
459-
'collectionProcessor' => $this->collectionProcessor,
460-
]
461-
);
462-
$this->model->expects($this->once())->method('getQuoteCollection')->willReturn($this->quoteCollectionMock);
456+
$this->quoteCollectionMock->expects($this->atLeastOnce())->method('getItems')->willReturn([$cartMock]);
457+
$searchResult->expects($this->once())->method('setTotalCount')->with($pageSize);
458+
$this->quoteCollectionMock->expects($this->once())
459+
->method('getSize')
460+
->willReturn($pageSize);
461+
$searchResult->expects($this->once())
462+
->method('setItems')
463+
->with([$cartMock]);
463464
$this->assertEquals($searchResult, $this->model->getList($searchCriteriaMock));
464465
}
465466

app/code/Magento/Tax/Model/Calculation/RateRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ private function getCollectionProcessor()
310310
{
311311
if (!$this->collectionProcessor) {
312312
$this->collectionProcessor = \Magento\Framework\App\ObjectManager::getInstance()->get(
313-
'\Magento\Tax\Model\Api\TaxRate\SearchCrtieria\CollectionProcessor'
313+
'Magento\Tax\Model\Api\SearchCriteria\TaxRateCollectionProcessor'
314314
);
315315
}
316316
return $this->collectionProcessor;

app/code/Magento/Tax/Model/TaxRuleRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private function getCollectionProcessor()
227227
{
228228
if (!$this->collectionProcessor) {
229229
$this->collectionProcessor = \Magento\Framework\App\ObjectManager::getInstance()->get(
230-
'\Magento\Tax\Model\Api\TaxRule\SearchCrtieria\CollectionProcessor'
230+
'Magento\Tax\Model\Api\SearchCriteria\TaxRuleCollectionProcessor'
231231
);
232232
}
233233
return $this->collectionProcessor;

app/code/Magento/Tax/etc/di.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@
8787
</type>
8888
<type name="Magento\Tax\Model\TaxRuleRepository">
8989
<arguments>
90-
<argument name="collectionProcessor" xsi:type="object">Magento\Tax\Model\Api\SearchCrtieria\TaxRuleCollectionProcessor</argument>
90+
<argument name="collectionProcessor" xsi:type="object">Magento\Tax\Model\Api\SearchCriteria\TaxRuleCollectionProcessor</argument>
9191
</arguments>
9292
</type>
9393
<type name="Magento\Tax\Model\Calculation\RateRepository">
9494
<arguments>
95-
<argument name="collectionProcessor" xsi:type="object">Magento\Tax\Model\Api\SearchCrtieria\TaxRateCollectionProcessor</argument>
95+
<argument name="collectionProcessor" xsi:type="object">Magento\Tax\Model\Api\SearchCriteria\TaxRateCollectionProcessor</argument>
9696
</arguments>
9797
</type>
98-
<virtualType name="Magento\Tax\Model\Api\SearchCrtieria\TaxRateCollectionProcessor" type="Magento\Framework\Api\SearchCriteria\CollectionProcessor">
98+
<virtualType name="Magento\Tax\Model\Api\SearchCriteria\TaxRateCollectionProcessor" type="Magento\Framework\Api\SearchCriteria\CollectionProcessor">
9999
<arguments>
100100
<argument name="processors" xsi:type="array">
101101
<item name="filters" xsi:type="object">Magento\Tax\Model\Api\SearchCriteria\CollectionProcessor\TaxRateFilterProcessor</item>
@@ -158,7 +158,7 @@
158158
</argument>
159159
</arguments>
160160
</virtualType>
161-
<virtualType name="Magento\Tax\Model\Api\SearchCrtieria\TaxRuleCollectionProcessor" type="Magento\Framework\Api\SearchCriteria\CollectionProcessor">
161+
<virtualType name="Magento\Tax\Model\Api\SearchCriteria\TaxRuleCollectionProcessor" type="Magento\Framework\Api\SearchCriteria\CollectionProcessor">
162162
<arguments>
163163
<argument name="processors" xsi:type="array">
164164
<item name="joins" xsi:type="object">Magento\Tax\Model\Api\SearchCriteria\CollectionProcessor\TaxRuleJoinProcessor</item>

0 commit comments

Comments
 (0)