1
1
<?php
2
2
/**
3
- * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
3
+ * Copyright © 2015 Magento. All rights reserved.
4
+ * See COPYING.txt for license details.
4
5
*/
5
6
namespace Magento \Backup \Model ;
6
7
8
+ use Magento \TestFramework \Helper \ObjectManager ;
9
+ use Magento \Framework \App \Filesystem \DirectoryList ;
7
10
11
+ /**
12
+ * @covers \Magento\Backup\Model\Backup
13
+ */
8
14
class BackupTest extends \PHPUnit_Framework_TestCase
9
15
{
16
+ /**
17
+ * @var \Magento\TestFramework\Helper\ObjectManager
18
+ */
19
+ protected $ objectManager ;
20
+
21
+ /**
22
+ * @var \Magento\Backup\Model\Backup
23
+ */
24
+ protected $ backupModel ;
25
+
26
+ /**
27
+ * @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject
28
+ */
29
+ protected $ filesystemMock ;
30
+
31
+ /**
32
+ * @var \Magento\Backup\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
33
+ */
34
+ protected $ dataHelperMock ;
35
+
36
+ /**
37
+ * @var \Magento\Framework\Filesystem\Directory\WriteInterface|\PHPUnit_Framework_MockObject_MockObject
38
+ */
39
+ protected $ directoryMock ;
40
+
41
+ public function setUp ()
42
+ {
43
+ $ this ->filesystemMock = $ this ->getMockBuilder ('Magento\Framework\Filesystem ' )
44
+ ->disableOriginalConstructor ()
45
+ ->getMock ();
46
+ $ this ->dataHelperMock = $ this ->getMockBuilder ('Magento\Backup\Helper\Data ' )
47
+ ->disableOriginalConstructor ()
48
+ ->getMock ();
49
+ $ this ->directoryMock = $ this ->getMockBuilder ('Magento\Framework\Filesystem\Directory\WriteInterface ' )
50
+ ->getMock ();
51
+
52
+ $ this ->filesystemMock ->expects ($ this ->atLeastOnce ())
53
+ ->method ('getDirectoryWrite ' )
54
+ ->with (DirectoryList::VAR_DIR )
55
+ ->willReturn ($ this ->directoryMock );
56
+
57
+ $ this ->objectManager = new ObjectManager ($ this );
58
+ $ this ->backupModel = $ this ->objectManager ->getObject (
59
+ 'Magento\Backup\Model\Backup ' ,
60
+ [
61
+ 'filesystem ' => $ this ->filesystemMock ,
62
+ 'helper ' => $ this ->dataHelperMock
63
+ ]
64
+ );
65
+ }
10
66
11
- public function testOutput ()
67
+ /**
68
+ * @covers \Magento\Backup\Model\Backup::output
69
+ * @param bool $isFile
70
+ * @param string $result
71
+ * @dataProvider outputDataProvider
72
+ */
73
+ public function testOutput ($ isFile , $ result )
12
74
{
13
75
$ path = '/path/to ' ;
14
76
$ time = 1 ;
15
77
$ name = 'test ' ;
16
78
$ type = 'db ' ;
17
79
$ extension = 'sql ' ;
18
- $ filename = $ time . '_ ' . $ type . '_ ' . $ name . '. ' . $ extension ;
19
- $ relativePath = $ path . '/ ' . $ filename ;
20
- $ contents = 'test_content ' ;
21
-
22
- $ directory = $ this ->getMock ('Magento\Framework\Filesystem\Directory\ReadInterface ' , [], [], '' , false );
23
- $ directory ->expects ($ this ->exactly (2 ))->method ('getRelativePath ' )
24
- ->with ($ relativePath )->will ($ this ->returnValue ($ relativePath ));
25
- $ directory ->expects ($ this ->once ())->method ('isFile ' )->with ($ relativePath )->will ($ this ->returnValue (true ));
26
- $ directory ->expects ($ this ->once ())->method ('readFile ' )->with ($ relativePath )
27
- ->will ($ this ->returnValue ($ contents ));
28
-
29
- $ filesystem = $ this ->getMock ('Magento\Framework\Filesystem ' , [], [], '' , false );
30
- $ filesystem ->expects ($ this ->exactly (2 ))->method ('getDirectoryWrite ' )
31
- ->with (\Magento \Framework \App \Filesystem \DirectoryList::VAR_DIR )
32
- ->will ($ this ->returnValue ($ directory ));
33
-
34
- $ helper = $ this ->getMock ('\Magento\Backup\Helper\Data ' , [], [], '' , false );
35
- $ helper ->expects ($ this ->exactly (2 ))->method ('getExtensionByType ' )->with ($ type )
36
- ->will ($ this ->returnValue ($ extension ));
37
-
38
- /** @var Backup $backup */
39
- $ backup = (new \Magento \TestFramework \Helper \ObjectManager ($ this ))->getObject (
40
- 'Magento\Backup\Model\Backup ' ,
41
- [
42
- 'filesystem ' => $ filesystem ,
43
- 'helper ' => $ helper
44
- ]
45
- );
46
- $ backup ->setPath ($ path );
47
- $ backup ->setName ($ name );
48
- $ backup ->setTime ($ time );
49
- $ this ->assertEquals ($ contents , $ backup ->output ());
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
+
106
+ /**
107
+ * @return array
108
+ */
109
+ public function outputDataProvider ()
110
+ {
111
+ return [
112
+ ['isFile ' => true , 'result ' => 'test_result ' ],
113
+ ['isFile ' => false , 'result ' => null ]
114
+ ];
50
115
}
51
- }
116
+ }
0 commit comments