Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BackupTest.php
Go to the documentation of this file.
1 <?php
7 
10 
14 class BackupTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $objectManager;
20 
24  protected $backupModel;
25 
29  protected $filesystemMock;
30 
34  protected $dataHelperMock;
35 
39  protected $directoryMock;
40 
41  protected function setUp()
42  {
43  $this->filesystemMock = $this->getMockBuilder(\Magento\Framework\Filesystem::class)
44  ->disableOriginalConstructor()
45  ->getMock();
46  $this->dataHelperMock = $this->getMockBuilder(\Magento\Backup\Helper\Data::class)
47  ->disableOriginalConstructor()
48  ->getMock();
49  $this->directoryMock = $this->getMockBuilder(\Magento\Framework\Filesystem\Directory\WriteInterface::class)
50  ->getMock();
51 
52  $this->filesystemMock->expects($this->atLeastOnce())
53  ->method('getDirectoryWrite')
55  ->willReturn($this->directoryMock);
56 
57  $this->objectManager = new ObjectManager($this);
58  $this->backupModel = $this->objectManager->getObject(
59  \Magento\Backup\Model\Backup::class,
60  [
61  'filesystem' => $this->filesystemMock,
62  'helper' => $this->dataHelperMock
63  ]
64  );
65  }
66 
73  public function testOutput($isFile, $result)
74  {
75  $path = '/path/to';
76  $time = 1;
77  $name = 'test';
78  $type = 'db';
79  $extension = 'sql';
80  $relativePath = '/path/to/1_db_test.sql';
81  $contents = 'test_result';
82 
83  $this->directoryMock->expects($this->atLeastOnce())
84  ->method('isFile')
85  ->with($relativePath)
86  ->willReturn($isFile);
87  $this->directoryMock->expects($this->any())
88  ->method('getRelativePath')
89  ->with($relativePath)
90  ->willReturn($relativePath);
91  $this->directoryMock->expects($this->any())
92  ->method('readFile')
93  ->with($relativePath)
94  ->willReturn($contents);
95  $this->dataHelperMock->expects($this->any())
96  ->method('getExtensionByType')
97  ->with($type)
98  ->willReturn($extension);
99 
100  $this->backupModel->setPath($path);
101  $this->backupModel->setName($name);
102  $this->backupModel->setTime($time);
103  $this->assertEquals($result, $this->backupModel->output());
104  }
105 
109  public function outputDataProvider()
110  {
111  return [
112  ['isFile' => true, 'result' => 'test_result'],
113  ['isFile' => false, 'result' => null]
114  ];
115  }
116 }
$contents
Definition: website.php:14
$type
Definition: item.phtml:13
$relativePath
Definition: get.php:35
if(!isset($_GET['name'])) $name
Definition: log.php:14