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