Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GeneratedFilesTest.php
Go to the documentation of this file.
1 <?php
8 
11 
12 class GeneratedFilesTest extends \PHPUnit\Framework\TestCase
13 {
17  private $directoryList;
18 
22  private $writeInterface;
23 
27  private $model;
28 
29  protected function setUp()
30  {
31  $this->directoryList =
32  $this->createPartialMock(\Magento\Framework\App\Filesystem\DirectoryList::class, ['getPath']);
33  $writeFactory = $this->createMock(\Magento\Framework\Filesystem\Directory\WriteFactory::class);
34  $this->writeInterface = $this->getMockBuilder(\Magento\Framework\Filesystem\Directory\WriteInterface::class)
35  ->setMethods(['getPath', 'delete'])
36  ->getMockForAbstractClass();
37  $writeFactory->expects($this->once())->method('create')->willReturn($this->writeInterface);
38  $this->model = new GeneratedFiles($this->directoryList, $writeFactory);
39  }
40 
47  public function testCleanGeneratedFiles($getPathMap, $isDirectoryMap, $deleteMap)
48  {
49 
50  $this->writeInterface
51  ->expects($this->any())
52  ->method('isExist')
53  ->with()
54  ->willReturnMap([
56  ['path/to/di', false]
57  ]);
58  $this->directoryList->expects($this->any())->method('getPath')->willReturnMap($getPathMap);
59  $this->writeInterface->expects($this->any())->method('getRelativePath')->willReturnMap($getPathMap);
60  $this->writeInterface->expects($this->any())->method('isDirectory')->willReturnMap($isDirectoryMap);
61  $this->writeInterface->expects($this->exactly(1))->method('delete')->willReturnMap($deleteMap);
62  $this->model->cleanGeneratedFiles();
63  }
64 
69  {
70  $pathToGeneration = 'path/to/generation';
71  $pathToDi = 'path/to/di';
72  $pathToCache = 'path/to/di';
73  $pathToConfig = 'path/to/config';
74 
75  $getPathMap = [
76  [DirectoryList::GENERATED_CODE, $pathToGeneration],
78  [DirectoryList::CACHE, $pathToCache],
79  [DirectoryList::CONFIG, $pathToConfig],
80  ];
81 
82  $deleteMap = [[BP . '/' . $pathToGeneration, true],
83  [BP . '/' . $pathToDi, true],
85  ];
86 
87  return [
88  'runAll' => [ $getPathMap, [[BP . '/' . $pathToGeneration, true],
89  [BP . '/' . $pathToDi, true]], $deleteMap ],
90  'noDIfolder' => [ $getPathMap, [[BP . '/' . $pathToGeneration, true],
91  [BP . '/' . $pathToDi, false]], $deleteMap],
92  'noGenerationfolder' => [$getPathMap, [[BP . '/' . $pathToGeneration, false],
93  [BP . '/' . $pathToDi, true]], $deleteMap],
94  'nofolders' => [ $getPathMap, [[BP . '/' . $pathToGeneration, false],
95  [BP . '/' . $pathToDi, false]], $deleteMap],
96  ];
97  }
98 
100  {
101  $this->writeInterface
102  ->expects($this->once())
103  ->method('isExist')
105  ->willReturn(false);
106  $this->directoryList->expects($this->never())->method('getPath');
107  $this->writeInterface->expects($this->never())->method('getPath');
108  $this->writeInterface->expects($this->never())->method('delete');
109  $this->model->cleanGeneratedFiles();
110  }
111 
112  public function testRequestRegeneration()
113  {
114  $this->writeInterface->expects($this->once())->method("touch");
115  $this->model->requestRegeneration();
116  }
117 }
testCleanGeneratedFiles($getPathMap, $isDirectoryMap, $deleteMap)
const BP
Definition: autoload.php:14