|
9 | 9 |
|
10 | 10 | use Magento\Framework\Api\SortOrder;
|
11 | 11 | use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
|
| 12 | +use Magento\Quote\Api\Data\CartInterface; |
12 | 13 | use Magento\Quote\Model\QuoteRepository\LoadHandler;
|
| 14 | +use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory; |
13 | 15 |
|
14 | 16 | /**
|
15 | 17 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
@@ -66,10 +68,16 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase
|
66 | 68 | */
|
67 | 69 | private $collectionProcessor;
|
68 | 70 |
|
| 71 | + /** @var \PHPUnit_Framework_MockObject_MockObject */ |
| 72 | + private $objectManagerMock; |
| 73 | + |
69 | 74 | protected function setUp()
|
70 | 75 | {
|
71 | 76 | $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
|
72 | 77 |
|
| 78 | + $this->objectManagerMock = $this->getMock(\Magento\Framework\ObjectManagerInterface::class); |
| 79 | + \Magento\Framework\App\ObjectManager::setInstance($this->objectManagerMock); |
| 80 | + |
73 | 81 | $this->quoteFactoryMock = $this->getMock(\Magento\Quote\Model\QuoteFactory::class, ['create'], [], '', false);
|
74 | 82 | $this->storeManagerMock = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class);
|
75 | 83 | $this->quoteMock = $this->getMock(
|
@@ -411,55 +419,48 @@ public function testDelete()
|
411 | 419 | $this->model->delete($this->quoteMock);
|
412 | 420 | }
|
413 | 421 |
|
414 |
| - /** |
415 |
| - * @param int $direction |
416 |
| - * @param string $expectedDirection |
417 |
| - */ |
418 |
| - public function testGetListSuccess() |
| 422 | + public function testGetList() |
419 | 423 | {
|
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); |
424 | 424 | $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); |
425 | 439 |
|
| 440 | + $searchResult = $this->getMock(\Magento\Quote\Api\Data\CartSearchResultsInterface::class, [], [], '', false); |
| 441 | + $searchCriteriaMock = $this->getMock(\Magento\Framework\Api\SearchCriteria::class, [], [], '', false); |
426 | 442 | $this->searchResultsDataFactory
|
427 | 443 | ->expects($this->once())
|
428 | 444 | ->method('create')
|
429 |
| - ->will($this->returnValue($searchResult)); |
| 445 | + ->willReturn($searchResult); |
430 | 446 |
|
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); |
438 | 447 | $this->collectionProcessor->expects($this->once())
|
439 | 448 | ->method('process')
|
440 | 449 | ->with($searchCriteriaMock, $this->quoteCollectionMock);
|
| 450 | + |
441 | 451 | $this->extensionAttributesJoinProcessorMock->expects($this->once())
|
442 | 452 | ->method('process')
|
443 | 453 | ->with(
|
444 | 454 | $this->isInstanceOf(\Magento\Quote\Model\ResourceModel\Quote\Collection::class)
|
445 | 455 | );
|
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]); |
463 | 464 | $this->assertEquals($searchResult, $this->model->getList($searchCriteriaMock));
|
464 | 465 | }
|
465 | 466 |
|
|
0 commit comments