Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FilesystemTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\Filesystem;
9 
11 
12 class FilesystemTest extends \PHPUnit\Framework\TestCase
13 {
15  protected $_filesystem;
16 
19 
22 
25 
26  protected function setUp()
27  {
28  $this->_dirReadFactoryMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadFactory::class);
29  $this->_directoryListMock = $this->createMock(\Magento\Framework\App\Filesystem\DirectoryList::class);
30  $this->_dirWriteFactoryMock = $this->createMock(\Magento\Framework\Filesystem\Directory\WriteFactory::class);
31  $this->_filesystem = new Filesystem(
32  $this->_directoryListMock,
33  $this->_dirReadFactoryMock,
34  $this->_dirWriteFactoryMock
35  );
36  }
37 
38  public function testGetDirectoryRead()
39  {
41  $dirReadMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadInterface::class);
42  $this->_dirReadFactoryMock->expects($this->once())->method('create')->will($this->returnValue($dirReadMock));
43  $this->assertEquals($dirReadMock, $this->_filesystem->getDirectoryRead(DirectoryList::ROOT));
44  }
45 
46  public function testGetDirectoryReadByPath()
47  {
49  $dirReadMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadInterface::class);
50  $this->_dirReadFactoryMock->expects($this->once())->method('create')->will($this->returnValue($dirReadMock));
51  $this->assertEquals($dirReadMock, $this->_filesystem->getDirectoryReadByPath('path/to/some/file'));
52  }
53 
54  public function testGetDirectoryWrite()
55  {
57  $dirWriteMock = $this->createMock(\Magento\Framework\Filesystem\Directory\WriteInterface::class);
58  $this->_dirWriteFactoryMock->expects($this->once())->method('create')->will($this->returnValue($dirWriteMock));
59  $this->assertEquals($dirWriteMock, $this->_filesystem->getDirectoryWrite(DirectoryList::ROOT));
60  }
61 
62  public function testGetUri()
63  {
64  $this->_directoryListMock->expects($this->once())->method('getUrlPath')->with('code')->willReturn('result');
65  $this->assertEquals('result', $this->_filesystem->getUri('code'));
66  }
67 }