5
5
*/
6
6
namespace Magento \Catalog \Test \Unit \Model \Product \Option \Type ;
7
7
8
+ use Magento \Catalog \Model \Product \Configuration \Item \Option \OptionInterface ;
9
+ use Magento \Framework \App \Filesystem \DirectoryList ;
10
+ use Magento \Framework \Filesystem ;
11
+ use Magento \Framework \Filesystem \Directory \ReadInterface ;
12
+ use Magento \Framework \Filesystem \DriverPool ;
13
+
8
14
class FileTest extends \PHPUnit_Framework_TestCase
9
15
{
10
16
/**
@@ -13,7 +19,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
13
19
protected $ objectManager ;
14
20
15
21
/**
16
- * @var \Magento\Framework\Filesystem\Directory\ ReadInterface|\PHPUnit_Framework_MockObject_MockObject
22
+ * @var ReadInterface|\PHPUnit_Framework_MockObject_MockObject
17
23
*/
18
24
protected $ rootDirectory ;
19
25
@@ -22,17 +28,29 @@ class FileTest extends \PHPUnit_Framework_TestCase
22
28
*/
23
29
protected $ coreFileStorageDatabase ;
24
30
31
+ /**
32
+ * @var Filesystem|\PHPUnit_Framework_MockObject_MockObject
33
+ */
34
+ private $ filesystemMock ;
35
+
25
36
protected function setUp ()
26
37
{
27
38
$ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
28
39
29
- $ this ->rootDirectory = $ this ->getMockBuilder (' Magento\Framework\ Filesystem\Directory\ReadInterface ' )
40
+ $ this ->filesystemMock = $ this ->getMockBuilder (Filesystem::class )
30
41
->disableOriginalConstructor ()
31
- ->setMethods (['isFile ' , 'isReadable ' , 'getAbsolutePath ' ])
32
- ->getMockForAbstractClass ();
42
+ ->getMock ();
43
+
44
+ $ this ->rootDirectory = $ this ->getMockBuilder (ReadInterface::class)
45
+ ->getMock ();
46
+
47
+ $ this ->filesystemMock ->expects ($ this ->once ())
48
+ ->method ('getDirectoryRead ' )
49
+ ->with (DirectoryList::MEDIA , DriverPool::FILE )
50
+ ->willReturn ($ this ->rootDirectory );
33
51
34
52
$ this ->coreFileStorageDatabase = $ this ->getMock (
35
- ' Magento\MediaStorage\Helper\File\Storage\Database ' ,
53
+ \ Magento \MediaStorage \Helper \File \Storage \Database::class ,
36
54
['copyFile ' ],
37
55
[],
38
56
'' ,
@@ -46,28 +64,29 @@ protected function setUp()
46
64
protected function getFileObject ()
47
65
{
48
66
return $ this ->objectManager ->getObject (
49
- ' Magento\Catalog\Model\Product\Option\Type\File ' ,
67
+ \ Magento \Catalog \Model \Product \Option \Type \File::class ,
50
68
[
51
- 'saleableItem ' => $ this ->rootDirectory ,
52
- 'priceCurrency ' => $ this ->coreFileStorageDatabase
69
+ 'filesystem ' => $ this ->filesystemMock ,
70
+ 'coreFileStorageDatabase ' => $ this ->coreFileStorageDatabase
53
71
]
54
72
);
55
73
}
56
74
57
75
public function testCopyQuoteToOrder ()
58
76
{
59
- $ optionMock = $ this ->getMockBuilder (
60
- 'Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface '
61
- )->disableOriginalConstructor ()->setMethods (['getValue ' ])->getMockForAbstractClass ();
77
+ $ optionMock = $ this ->getMockBuilder (OptionInterface::class)
78
+ ->disableOriginalConstructor ()
79
+ ->setMethods (['getValue ' ])
80
+ ->getMockForAbstractClass ();
62
81
63
82
$ quotePath = '/quote/path/path/uploaded.file ' ;
64
83
$ orderPath = '/order/path/path/uploaded.file ' ;
65
84
66
85
$ optionMock ->expects ($ this ->any ())
67
86
->method ('getValue ' )
68
- ->will ($ this ->returnValue (['quote_path ' => $ quotePath , 'order_path ' => $ orderPath ]));
87
+ ->will ($ this ->returnValue (serialize ( ['quote_path ' => $ quotePath , 'order_path ' => $ orderPath ]) ));
69
88
70
- $ this ->rootDirectory ->expects ($ this ->any ())
89
+ $ this ->rootDirectory ->expects ($ this ->once ())
71
90
->method ('isFile ' )
72
91
->with ($ this ->equalTo ($ quotePath ))
73
92
->will ($ this ->returnValue (true ));
@@ -89,7 +108,7 @@ public function testCopyQuoteToOrder()
89
108
$ fileObject ->setData ('configuration_item_option ' , $ optionMock );
90
109
91
110
$ this ->assertInstanceOf (
92
- ' Magento\Catalog\Model\Product\Option\Type\File ' ,
111
+ \ Magento \Catalog \Model \Product \Option \Type \File::class ,
93
112
$ fileObject ->copyQuoteToOrder ()
94
113
);
95
114
}
0 commit comments