Example #1
0
 /**
  * @param string $expected
  * @param string[] $taxClassKeyMockValeMap
  * @param bool $found
  * @dataProvider getTaxClassIdDataProvider
  */
 public function testGetTaxClassId($expected, $taxClassKeyMockValeMap, $found = false)
 {
     /** @var \Magento\Tax\Service\V1\Data\TaxClassKey|\PHPUnit_Framework_MockObject_MockObject $taxClassKeyMock */
     $taxClassKeyMock = $this->getMockBuilder('Magento\\Tax\\Service\\V1\\Data\\TaxClassKey')->disableOriginalConstructor()->getMock();
     $this->mockReturnValue($taxClassKeyMock, $taxClassKeyMockValeMap);
     if ($taxClassKeyMockValeMap['getType'] == TaxClassKey::TYPE_NAME) {
         $this->searchCriteriaBuilderMock->expects($this->exactly(2))->method('addFilter')->will($this->returnValue($this->searchCriteriaBuilderMock));
         /** @var \Magento\Framework\Service\V1\Data\SearchCriteria $searchCriteria */
         $searchCriteria = $this->createSearchCriteria();
         $this->searchCriteriaBuilderMock->expects($this->once())->method('create')->will($this->returnValue($searchCriteria));
         $this->searchResultBuilder->expects($this->once())->method('setSearchCriteria')->with($searchCriteria);
         /** @var \PHPUnit_Framework_MockObject_MockObject $taxClassModelMock */
         $taxClassModelMock = $this->getMockBuilder('Magento\\Tax\\Model\\ClassModel')->disableOriginalConstructor()->getMock();
         $collectionMock = $this->mockTaxClassCollection($taxClassModelMock);
         $this->taxClassCollectionFactory->expects($this->once())->method('create')->will($this->returnValue($collectionMock));
         /** @var \PHPUnit_Framework_MockObject_MockObject $taxMock */
         $taxClassMock = $this->getMockBuilder('Magento\\Tax\\Service\\V1\\Data\\TaxClass')->disableOriginalConstructor()->getMock();
         $this->converterMock->expects($this->once())->method('createTaxClassData')->with($taxClassModelMock)->will($this->returnValue($taxClassMock));
         $this->searchResultBuilder->expects($this->once())->method('setItems')->will($this->returnValue([$taxClassMock]));
         $searchResultsMock = $this->getMockBuilder('Magento\\Tax\\Service\\V1\\Data\\TaxClassSearchResults')->disableOriginalConstructor()->getMock();
         $searchResultsMock->expects($this->once())->method('getItems')->will($this->returnValue($found ? [$taxClassMock] : []));
         $taxClassMock->expects($this->any())->method('getClassId')->will($this->returnValue(self::TAX_CLASS_ID));
         $this->searchResultBuilder->expects($this->once())->method('create')->will($this->returnValue($searchResultsMock));
     }
     $this->assertEquals($expected, $this->taxClassService->getTaxClassId($taxClassKeyMock));
 }
 public function testSearch()
 {
     $collectionSize = 3;
     $currentPage = 1;
     $pageSize = 10;
     $searchCriteria = $this->createSearchCriteria();
     $this->searchResultBuilder->expects($this->once())->method('setSearchCriteria')->with($searchCriteria);
     /** @var \PHPUnit_Framework_MockObject_MockObject $collectionMock */
     $collectionMock = $this->getMockBuilder('Magento\\Tax\\Model\\Resource\\TaxClass\\Collection')->disableOriginalConstructor()->setMethods(['addFieldToFilter', 'getSize', 'setCurPage', 'setPageSize', 'getItems', 'addOrder'])->getMock();
     $this->taxClassCollectionFactory->expects($this->once())->method('create')->will($this->returnValue($collectionMock));
     $collectionMock->expects($this->exactly(2))->method('addFieldToFilter');
     $collectionMock->expects($this->any())->method('getSize')->will($this->returnValue($collectionSize));
     $collectionMock->expects($this->once())->method('setCurPage')->with($currentPage);
     $collectionMock->expects($this->once())->method('setPageSize')->with($pageSize);
     $collectionMock->expects($this->once())->method('addOrder')->with('class_name', 'ASC');
     /** @var \PHPUnit_Framework_MockObject_MockObject $taxClassModelMock */
     $taxClassModelMock = $this->getMockBuilder('Magento\\Tax\\Model\\ClassModel')->disableOriginalConstructor()->getMock();
     $collectionMock->expects($this->once())->method('getItems')->will($this->returnValue([$taxClassModelMock]));
     /** @var \PHPUnit_Framework_MockObject_MockObject $taxMock */
     $taxClassMock = $this->getMockBuilder('Magento\\Tax\\Service\\V1\\Data\\TaxClass')->disableOriginalConstructor()->getMock();
     $this->converterMock->expects($this->once())->method('createTaxClassData')->with($taxClassModelMock)->will($this->returnValue($taxClassMock));
     $this->searchResultBuilder->expects($this->once())->method('setItems')->will($this->returnValue([$taxClassMock]));
     $this->taxClassService->searchTaxClass($searchCriteria);
 }