Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FileExistsTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\View\Asset\MergeStrategy\FileExists;
9 
11 
12 class FileExistsTest extends \PHPUnit\Framework\TestCase
13 {
17  private $mergerMock;
18 
22  private $dirMock;
23 
27  private $resultAsset;
28 
32  private $fileExists;
33 
34  protected function setUp()
35  {
36  $this->mergerMock = $this->getMockForAbstractClass(\Magento\Framework\View\Asset\MergeStrategyInterface::class);
37  $this->dirMock = $this->getMockForAbstractClass(\Magento\Framework\Filesystem\Directory\ReadInterface::class);
38  $filesystem = $this->createMock(\Magento\Framework\Filesystem::class);
39  $filesystem->expects($this->once())
40  ->method('getDirectoryRead')
42  ->will($this->returnValue($this->dirMock));
43  $this->fileExists = new FileExists($this->mergerMock, $filesystem);
44  $this->resultAsset = $this->createMock(\Magento\Framework\View\Asset\File::class);
45  $this->resultAsset->expects($this->once())->method('getPath')->will($this->returnValue('foo/file'));
46  }
47 
48  public function testMergeExists()
49  {
50  $this->dirMock->expects($this->once())->method('isExist')->with('foo/file')->will($this->returnValue(true));
51  $this->mergerMock->expects($this->never())->method('merge');
52  $this->fileExists->merge([], $this->resultAsset);
53  }
54 
55  public function testMergeNotExists()
56  {
57  $this->dirMock->expects($this->once())->method('isExist')->with('foo/file')->will($this->returnValue(false));
58  $this->mergerMock->expects($this->once())->method('merge')->with([], $this->resultAsset);
59  $this->fileExists->merge([], $this->resultAsset);
60  }
61 }
$filesystem