Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductIdentitiesExtenderTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
18 class ProductIdentitiesExtenderTest extends \PHPUnit\Framework\TestCase
19 {
23  private $configurableTypeMock;
24 
28  private $productRepositoryMock;
29 
33  private $plugin;
34 
35  protected function setUp()
36  {
37  $this->configurableTypeMock = $this->getMockBuilder(Configurable::class)
38  ->disableOriginalConstructor()
39  ->getMock();
40  $this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)
41  ->getMock();
42 
43  $this->plugin = new ProductIdentitiesExtender($this->configurableTypeMock, $this->productRepositoryMock);
44  }
45 
46  public function testAfterGetIdentities()
47  {
48  $productId = 1;
49  $productIdentity = 'cache_tag_1';
50  $productMock = $this->getMockBuilder(Product::class)
51  ->disableOriginalConstructor()
52  ->getMock();
53  $parentProductId = 2;
54  $parentProductIdentity = 'cache_tag_2';
55  $parentProductMock = $this->getMockBuilder(Product::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58 
59  $productMock->expects($this->once())
60  ->method('getId')
61  ->willReturn($productId);
62  $this->configurableTypeMock->expects($this->once())
63  ->method('getParentIdsByChild')
64  ->with($productId)
65  ->willReturn([$parentProductId]);
66  $this->productRepositoryMock->expects($this->once())
67  ->method('getById')
68  ->with($parentProductId)
69  ->willReturn($parentProductMock);
70  $parentProductMock->expects($this->once())
71  ->method('getIdentities')
72  ->willReturn([$parentProductIdentity]);
73 
74  $productIdentities = $this->plugin->afterGetIdentities($productMock, [$productIdentity]);
75  $this->assertEquals([$productIdentity, $parentProductIdentity], $productIdentities);
76  }
77 }