Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CommentParserTest.php
Go to the documentation of this file.
1 <?php
7 
13 
14 class CommentParserTest extends \PHPUnit\Framework\TestCase
15 {
19  private $filesystemMock;
20 
24  private $configFilePoolMock;
25 
29  private $readDirectoryMock;
30 
34  private $commentParser;
35 
39  protected function setUp()
40  {
41  $this->configFilePoolMock = $this->getMockBuilder(ConfigFilePool::class)
42  ->disableOriginalConstructor()
43  ->getMock();
44  $this->readDirectoryMock = $this->getMockBuilder(ReadInterface::class)
45  ->getMockForAbstractClass();
46  $this->filesystemMock = $this->getMockBuilder(Filesystem::class)
47  ->disableOriginalConstructor()
48  ->getMock();
49  $this->filesystemMock->expects($this->once())
50  ->method('getDirectoryRead')
51  ->with(DirectoryList::CONFIG)
52  ->willReturn($this->readDirectoryMock);
53 
54  $this->commentParser = new CommentParser($this->filesystemMock, $this->configFilePoolMock);
55  }
56 
57  public function testExecuteFileDoesNotExist()
58  {
59  $file = 'config.php';
60  $expectedResult = [];
61 
62  $this->readDirectoryMock->expects($this->once())
63  ->method('isExist')
64  ->with($file)
65  ->willReturn(false);
66 
67  $this->assertSame($expectedResult, $this->commentParser->execute($file));
68  }
69 
70  public function testExecute()
71  {
72  $file = 'config.php';
73  $content = <<<TEXT
74 <?php
75 return array (
76  'ns1' =>
77  array (
78  's1' =>
79  array (
80  0 => 's11',
81  1 => 's12',
82  ),
83  's2' =>
84  array (
85  0 => 's21',
86  1 => 's22',
87  ),
88  ),
93  'ns2' =>
94  array (
95  's1' =>
96  array (
97  0 => 's11',
98  ),
99  ),
100  // This comment will be ignored
101  'ns3' => 'just text',
107  'ns4' => 'just text',
112  'ns5' => 'just text',
113  # This comment will be ignored
114  'ns6' => 'just text',
115 );
116 
117 TEXT;
118 
119  $expectedResult = [
120  'ns4' => "comment for namespace 4\n second line",
121  'ns5' => '*comment for namespace *5*',
122  ];
123 
124  $this->readDirectoryMock->expects($this->once())
125  ->method('isExist')
126  ->with($file)
127  ->willReturn(true);
128  $this->readDirectoryMock->expects($this->once())
129  ->method('readFile')
130  ->with($file)
131  ->willReturn($content);
132 
133  $this->assertEquals($expectedResult, $this->commentParser->execute($file));
134  }
135 }