Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FsTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 require_once __DIR__ . '/_files/ioMock.php';
11 
12 class FsTest extends \PHPUnit\Framework\TestCase
13 {
17  private $objectManager;
18 
22  private $snapshotMock;
23 
27  private $fsHelperMock;
28 
32  private $fs;
33 
37  private $backupPath;
38 
42  private $rootDir;
43 
47  private $ignorePaths;
48 
49  protected function setUp()
50  {
51  $this->backupPath = '/some/test/path';
52  $this->rootDir = '/';
53  $this->ignorePaths = [];
54 
55  $this->objectManager = new ObjectManager($this);
56  $this->snapshotMock = $this->getMockBuilder(\Magento\Framework\Backup\Filesystem::class)
57  ->setMethods(['getBackupPath', 'getRootDir', 'getIgnorePaths'])
58  ->getMock();
59  $this->snapshotMock->expects($this->any())
60  ->method('getBackupPath')
61  ->willReturn($this->backupPath);
62  $this->snapshotMock->expects($this->any())
63  ->method('getRootDir')
64  ->willReturn($this->rootDir);
65  $this->snapshotMock->expects($this->any())
66  ->method('getIgnorePaths')
67  ->willReturn($this->ignorePaths);
68  $this->fsHelperMock = $this->getMockBuilder(\Magento\Framework\Backup\Filesystem\Helper::class)
69  ->setMethods(['getInfo', 'rm'])
70  ->getMock();
71  $this->fs = $this->objectManager->getObject(
72  \Magento\Framework\Backup\Filesystem\Rollback\Fs::class,
73  [
74  'snapshotObject' => $this->snapshotMock,
75  'fsHelper' => $this->fsHelperMock,
76  ]
77  );
78  }
79 
84  public function testRunNotEnoughPermissions()
85  {
86  $fsInfo = [
87  'writable' => false,
88  'writableMeta' => ['test1', 'test2'],
89  ];
90 
91  $this->fsHelperMock->expects($this->once())
92  ->method('getInfo')
93  ->willReturn($fsInfo);
94  $this->fs->run();
95  }
96 
97  public function testRun()
98  {
99  $fsInfo = ['writable' => true];
100 
101  $this->fsHelperMock->expects($this->once())
102  ->method('getInfo')
103  ->willReturn($fsInfo);
104  $this->fsHelperMock->expects($this->once())
105  ->method('rm')
106  ->with($this->rootDir, $this->ignorePaths);
107 
108  $this->fs->run();
109  }
110 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60