Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ModificationChainTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Setup\Module\Di\Compiler\Config\ModificationChain;
10 
11 class ModificationChainTest extends \PHPUnit\Framework\TestCase
12 {
13  public function testConstructor()
14  {
15  $modificationsList = [];
16  $modificationsList[] = $this->getMockBuilder(
17  \Magento\Setup\Module\Di\Compiler\Config\ModificationInterface::class
18  )->getMock();
19  $modificationsList[] = $this->getMockBuilder(
20  \Magento\Setup\Module\Di\Compiler\Config\ModificationInterface::class
21  )->getMock();
22 
23  new ModificationChain($modificationsList);
24  }
25 
26  public function testConstructorException()
27  {
28  $this->expectException('InvalidArgumentException');
29  $this->expectExceptionMessage('Wrong modifier provided');
30  $modificationsList = [];
31  $modificationsList[] = $this->getMockBuilder(
32  \Magento\Setup\Module\Di\Compiler\Config\ModificationInterface::class
33  )->getMock();
34  $modificationsList[] = $this->getMockBuilder(
35  \Magento\Setup\Module\Di\Compiler\Config\ModificationInterface::class
36  )->getMock();
37  $modificationsList[] = 'banana';
38 
39  new ModificationChain($modificationsList);
40  }
41 
42  public function testModify()
43  {
44  $inputArray = [
45  'data' => [1, 2, 3]
46  ];
47 
48  $expectedArray1 = [
49  'data' => [1, 2, 3, 1]
50  ];
51 
52  $expectedArray2 = [
53  'data' => [1, 2, 3, 1, 1]
54  ];
55 
56  $modifier1 = $this->getMockBuilder(\Magento\Setup\Module\Di\Compiler\Config\ModificationInterface::class)
57  ->getMock();
58  $modifier2 = $this->getMockBuilder(\Magento\Setup\Module\Di\Compiler\Config\ModificationInterface::class)
59  ->getMock();
60 
61  $modificationsList = [$modifier1, $modifier2];
62 
63  $modifier1->expects($this->once())
64  ->method('modify')
65  ->with($inputArray)
66  ->willReturn($expectedArray1);
67 
68  $modifier2->expects($this->once())
69  ->method('modify')
70  ->with($expectedArray1)
71  ->willReturn($expectedArray2);
72 
73  $chain = new ModificationChain($modificationsList);
74 
75  $this->assertEquals($expectedArray2, $chain->modify($inputArray));
76  }
77 }