Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributeSetFinderTest.php
Go to the documentation of this file.
1 <?php
8 
12 use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
16 
17 class AttributeSetFinderTest extends \PHPUnit\Framework\TestCase
18 {
22  protected $productCollection;
23 
28 
33 
34  protected function setUp()
35  {
36  $this->productCollection = $this->getMockBuilder(Collection::class)
37  ->disableOriginalConstructor()
38  ->getMock();
39  $this->productCollectionFactory = $this->getMockBuilder(CollectionFactory::class)
40  ->setMethods(['create'])
41  ->disableOriginalConstructor()
42  ->getMock();
43  $this->productCollectionFactory->expects($this->once())->method('create')->willReturn($this->productCollection);
44 
45  $this->attributeSetFinder = (new ObjectManager($this))->getObject(
46  AttributeSetFinder::class,
47  [
48  'productCollectionFactory' => $this->productCollectionFactory,
49  ]
50  );
51  }
52 
54  {
55  $productIds = [1, 2, 3];
56  $attributeSetIds = [3, 4, 6];
57 
58  $select = $this->getMockBuilder(Select::class)
59  ->disableOriginalConstructor()
60  ->getMock();
61  $select->expects($this->once())->method('reset')->with(Select::COLUMNS)->willReturnSelf();
62  $select->expects($this->once())->method('columns')->with(ProductInterface::ATTRIBUTE_SET_ID)->willReturnSelf();
63  $select->expects($this->once())->method('where')->with('entity_id IN (?)', $productIds)->willReturnSelf();
64  $select->expects($this->once())->method('group')->with(ProductInterface::ATTRIBUTE_SET_ID)->willReturnSelf();
65 
66  $connection = $this->createMock(AdapterInterface::class);
67  $connection->expects($this->once())->method('fetchCol')->with($select)->willReturn($attributeSetIds);
68 
69  $this->productCollection->expects($this->once())->method('getSelect')->willReturn($select);
70  $this->productCollection->expects($this->once())->method('getConnection')->willReturn($connection);
71 
72  $this->assertEquals($attributeSetIds, $this->attributeSetFinder->findAttributeSetIdsByProductIds($productIds));
73  }
74 }
const COLUMNS
Definition: Select.php:48
$connection
Definition: bulk.php:13