Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CleanupFilesTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Framework\App\State\CleanupFiles;
10 
13 
14 class CleanupFilesTest extends \PHPUnit\Framework\TestCase
15 {
19  private $filesystem;
20 
24  private $object;
25 
26  protected function setUp()
27  {
28  $this->filesystem = $this->createMock(\Magento\Framework\Filesystem::class);
29  $this->object = new CleanupFiles($this->filesystem);
30  }
31 
33  {
34  $dir1 = $this->getDirectoryCleanMock();
35  $dir2 = $this->getDirectoryCleanMock();
36  $this->filesystem->expects($this->exactly(2))
37  ->method('getDirectoryWrite')
38  ->will(
39  $this->returnValueMap(
40  [
43  ]
44  )
45  );
46  $this->object->clearCodeGeneratedClasses();
47  }
48 
50  {
51  $static = $this->getDirectoryCleanMock();
52  $var = $this->getDirectoryCleanMock(DirectoryList::TMP_MATERIALIZATION_DIR);
53  $this->filesystem->expects($this->exactly(2))->method('getDirectoryWrite')->will($this->returnValueMap([
56  ]));
57  $this->object->clearMaterializedViewFiles();
58  }
59 
66  private function getDirectoryCleanMock($subPath = null)
67  {
68  $dir = $this->getMockForAbstractClass(\Magento\Framework\Filesystem\Directory\WriteInterface::class);
69  $dir->expects($this->once())->method('search')->with('*', $subPath)->willReturn(['one', 'two']);
70  $dir->expects($this->exactly(2))->method('delete');
71  $dir->expects($this->once())->method('isExist')->will($this->returnValue(true));
72  return $dir;
73  }
74 }