5
5
*/
6
6
namespace Magento \Framework \Image \Adapter ;
7
7
8
+ use Magento \Framework \Filesystem \FilesystemException ;
9
+ use Magento \TestFramework \Helper \ObjectManager ;
10
+
8
11
class ImageMagickTest extends \PHPUnit_Framework_TestCase
9
12
{
10
13
/**
14
+ * @var \PHPUnit_Framework_MockObject_MockObject |\Magento\Framework\Filesystem
15
+ */
16
+ protected $ filesystemMock ;
17
+
18
+ /**
19
+ * @var \PHPUnit_Framework_MockObject_MockObject |\Psr\Log\LoggerInterface
20
+ */
21
+ protected $ loggerMock ;
22
+
23
+ /**
24
+ * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Filesystem\Directory\WriteInterface
25
+ */
26
+ protected $ writeMock ;
27
+ /**
28
+ * @var \Magento\Framework\Image\Adapter\ImageMagick
29
+ */
30
+ protected $ imageMagic ;
31
+
32
+ public function setup ()
33
+ {
34
+ $ objectManager = new ObjectManager ($ this );
35
+ $ this ->loggerMock = $ this ->getMockBuilder ( 'Psr\Log\LoggerInterface ' )->getMock ();
36
+ $ this ->writeMock = $ this ->getMockBuilder ('Magento\Framework\Filesystem\Directory\WriteInterface ' )->getMock ();
37
+ $ this ->filesystemMock = $ this ->getMock (
38
+ 'Magento\Framework\Filesystem ' ,
39
+ ['getDirectoryWrite ' ],
40
+ [],
41
+ '' ,
42
+ false
43
+ );
44
+ $ this ->filesystemMock
45
+ ->expects ($ this ->once ())
46
+ ->method ('getDirectoryWrite ' )
47
+ ->will ($ this ->returnValue ( $ this ->writeMock ));
48
+
49
+ $ this ->imageMagic = $ objectManager
50
+ ->getObject (
51
+ 'Magento\Framework\Image\Adapter\ImageMagick ' ,
52
+ ['filesystem ' => $ this ->filesystemMock ,
53
+ 'logger ' => $ this ->loggerMock ]
54
+ );
55
+ }
56
+ /**
57
+ * @param string $imagePath
58
+ * @param string $expectedMessage
11
59
* @dataProvider watermarkDataProvider
12
60
*/
13
61
public function testWatermark ($ imagePath , $ expectedMessage )
14
62
{
15
- $ filesystem =
16
- $ this ->getMockBuilder ('Magento\Framework\Filesystem ' )->disableOriginalConstructor ()->getMock ();
17
63
$ this ->setExpectedException ('LogicException ' , $ expectedMessage );
18
- $ object = new \Magento \Framework \Image \Adapter \ImageMagick ($ filesystem );
19
- $ object ->watermark ($ imagePath );
64
+ $ this ->imageMagic ->watermark ($ imagePath );
20
65
}
21
66
22
67
/**
@@ -33,4 +78,16 @@ public function watermarkDataProvider()
33
78
]
34
79
];
35
80
}
81
+
82
+ /**
83
+ * @expectedException \Exception
84
+ * @expectedExceptionMessage Unable to write file into directory product/cache. Access forbidden.
85
+ */
86
+ public function testSaveWithException ()
87
+ {
88
+ $ exception = new FilesystemException ();
89
+ $ this ->writeMock ->method ('create ' )->will ($ this ->throwException ($ exception ));
90
+ $ this ->loggerMock ->expects ($ this ->once ())->method ('critical ' )->with ($ exception );
91
+ $ this ->imageMagic ->save ('product/cache ' , 'sample.jpg ' );
92
+ }
36
93
}
0 commit comments