17 private $metadataPool;
22 private $collectionFactory;
36 $this->metadataPool = $this->getMockBuilder(\
Magento\Framework\EntityManager\MetadataPool::class)
37 ->setMethods([
'getMetadata'])
38 ->disableOriginalConstructor()->getMock();
39 $this->collectionFactory = $this
41 ->setMethods([
'create'])
42 ->disableOriginalConstructor()->getMock();
44 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
46 \
Magento\Catalog\Model\ProductIdLocator::class,
48 'metadataPool' => $this->metadataPool,
49 'collectionFactory' => $this->collectionFactory,
59 $skus = [
'sku_1',
'sku_2'];
61 ->setMethods([
'getIterator',
'addFieldToFilter'])
62 ->disableOriginalConstructor()->getMock();
63 $product = $this->getMockBuilder(\
Magento\Catalog\Api\Data\ProductInterface::class)
64 ->setMethods([
'getSku',
'getData',
'getTypeId'])
65 ->disableOriginalConstructor()->getMockForAbstractClass();
66 $metaDataInterface = $this->getMockBuilder(\
Magento\Framework\EntityManager\EntityMetadataInterface::class)
67 ->setMethods([
'getLinkField'])
68 ->disableOriginalConstructor()->getMockForAbstractClass();
69 $this->collectionFactory->expects($this->once())->method(
'create')->willReturn(
$collection);
70 $collection->expects($this->once())->method(
'addFieldToFilter')
72 $collection->expects($this->once())->method(
'getIterator')->willReturn(
new \ArrayIterator([
$product]));
74 ->expects($this->once())
75 ->method(
'getMetadata')
76 ->with(\
Magento\Catalog\Api\Data\ProductInterface::class)
77 ->willReturn($metaDataInterface);
78 $metaDataInterface->expects($this->once())->method(
'getLinkField')->willReturn(
'entity_id');
79 $product->expects($this->once())->method(
'getSku')->willReturn(
'sku_1');
80 $product->expects($this->once())->method(
'getData')->with(
'entity_id')->willReturn(1);
81 $product->expects($this->once())->method(
'getTypeId')->willReturn(
'simple');
83 [
'sku_1' => [1 =>
'simple']],
84 $this->model->retrieveProductIdsBySkus(
$skus)
foreach($websiteCodes as $websiteCode) $skus
testRetrieveProductIdsBySkus()