Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InvalidSkuProcessorTest.php
Go to the documentation of this file.
1 <?php
8 
12 class InvalidSkuProcessorTest extends \PHPUnit\Framework\TestCase
13 {
17  private $invalidSkuProcessor;
18 
22  private $productIdLocator;
23 
27  private $productRepository;
28 
32  protected function setUp()
33  {
34  $this->productIdLocator = $this->getMockBuilder(\Magento\Catalog\Model\ProductIdLocatorInterface::class)
35  ->disableOriginalConstructor()->getMockForAbstractClass();
36  $this->productRepository = $this->getMockBuilder(\Magento\Catalog\Api\ProductRepositoryInterface::class)
37  ->disableOriginalConstructor()->getMockForAbstractClass();
38 
39  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
40  $this->invalidSkuProcessor = $objectManager->getObject(
41  \Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor::class,
42  [
43  'productIdLocator' => $this->productIdLocator,
44  'productRepository' => $this->productRepository
45  ]
46  );
47  }
48 
56  private function prepareRetrieveInvalidSkuListMethod($productType, $productSku)
57  {
58  $idsBySku = [$productSku => [235235235 => $productType]];
59  $this->productIdLocator->expects($this->atLeastOnce())->method('retrieveProductIdsBySkus')
60  ->willReturn($idsBySku);
61  $product = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
62  ->setMethods(['getPriceType'])
63  ->disableOriginalConstructor()->getMockForAbstractClass();
64  $productPriceType = 0;
65  $product->expects($this->atLeastOnce())->method('getPriceType')->willReturn($productPriceType);
66  $this->productRepository->expects($this->atLeastOnce())->method('get')->willReturn($product);
67  }
68 
74  public function testRetrieveInvalidSkuList()
75  {
76  $productSku = 'LKJKJ2233636';
77  $productType = \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE;
78  $methodParamSku = 'SDFSDF3242355';
79  $skus = [$methodParamSku];
80  $allowedProductTypes = [$productType];
81  $allowedPriceTypeValue = true;
82  $this->prepareRetrieveInvalidSkuListMethod($productType, $productSku);
83 
84  $this->assertEquals(
85  [$methodParamSku, $productSku],
86  $this->invalidSkuProcessor->retrieveInvalidSkuList($skus, $allowedProductTypes, $allowedPriceTypeValue)
87  );
88  }
89 }
$objectManager
Definition: bootstrap.php:17
foreach($websiteCodes as $websiteCode) $skus