Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DirTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class DirTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_model;
16 
21 
22  protected function setUp()
23  {
24  $this->moduleRegistryMock = $this->createMock(\Magento\Framework\Component\ComponentRegistrarInterface::class);
25 
26  $this->_model = new \Magento\Framework\Module\Dir($this->moduleRegistryMock);
27  }
28 
29  public function testGetDirModuleRoot()
30  {
31  $this->moduleRegistryMock->expects($this->once())
32  ->method('getPath')
33  ->with(ComponentRegistrar::MODULE, 'Test_Module')
34  ->will($this->returnValue('/Test/Module'));
35 
36  $this->assertEquals('/Test/Module', $this->_model->getDir('Test_Module'));
37  }
38 
39  public function testGetDirModuleSubDir()
40  {
41  $this->moduleRegistryMock->expects($this->once())
42  ->method('getPath')
43  ->with(ComponentRegistrar::MODULE, 'Test_Module')
44  ->will($this->returnValue('/Test/Module'));
45 
46  $this->assertEquals('/Test/Module/etc', $this->_model->getDir('Test_Module', 'etc'));
47  }
48 
49  public function testGetSetupDirModule()
50  {
51  $this->moduleRegistryMock->expects($this->once())
52  ->method('getPath')
53  ->with(ComponentRegistrar::MODULE, 'Test_Module')
54  ->willReturn('/Test/Module');
55 
56  $this->assertEquals('/Test/Module/Setup', $this->_model->getDir('Test_Module', 'Setup'));
57  }
58 
64  {
65  $this->moduleRegistryMock->expects($this->once())
66  ->method('getPath')
67  ->with(ComponentRegistrar::MODULE, 'Test_Module')
68  ->will($this->returnValue('/Test/Module'));
69 
70  $this->_model->getDir('Test_Module', 'unknown');
71  }
72 
78  {
79  $this->moduleRegistryMock->expects($this->once())
80  ->method('getPath')
81  ->with($this->identicalTo(ComponentRegistrar::MODULE), $this->identicalTo('Test Module'))
82  ->willReturn(null);
83  $this->_model->getDir('Test Module');
84  }
85 }