Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MixinManagerTest.php
Go to the documentation of this file.
1 <?php
7 
8 class MixinManagerTest extends \PHPUnit\Framework\TestCase
9 {
13  private $mixinManager;
14 
18  private $mixinFactoryMock;
19 
20  public function setUp()
21  {
22  $this->mixinFactoryMock = $this->createMock(\Magento\Setup\Model\Description\Mixin\MixinFactory::class);
23  $this->mixinManager = new \Magento\Setup\Model\Description\MixinManager($this->mixinFactoryMock);
24  }
25 
26  public function testApply()
27  {
28  $description = '>o<';
29  $mixinList = ['x', 'y', 'z'];
30 
31  $xMixinMock = $this->getMockForAbstractClass(
32  \Magento\Setup\Model\Description\Mixin\DescriptionMixinInterface::class
33  );
34  $xMixinMock->expects($this->once())
35  ->method('apply')
36  ->with($description)
37  ->willReturn($description . 'x');
38 
39  $yMixinMock = $this->getMockForAbstractClass(
40  \Magento\Setup\Model\Description\Mixin\DescriptionMixinInterface::class
41  );
42  $yMixinMock->expects($this->once())
43  ->method('apply')
44  ->with($description . 'x')
45  ->willReturn($description . 'xy');
46 
47  $zMixinMock = $this->getMockForAbstractClass(
48  \Magento\Setup\Model\Description\Mixin\DescriptionMixinInterface::class
49  );
50  $zMixinMock->expects($this->once())
51  ->method('apply')
52  ->with($description . 'xy')
53  ->willReturn($description . 'xyz');
54 
55  $this->mixinFactoryMock
56  ->expects($this->exactly(count($mixinList)))
57  ->method('create')
58  ->withConsecutive(
59  [$mixinList[0]],
60  [$mixinList[1]],
61  [$mixinList[2]]
62  )
63  ->will(
64  $this->onConsecutiveCalls(
65  $xMixinMock,
66  $yMixinMock,
67  $zMixinMock
68  )
69  );
70 
71  $this->assertEquals(
72  $description . 'xyz',
73  $this->mixinManager->apply($description, $mixinList)
74  );
75  }
76 }