1
|
|
|
<?php |
2
|
|
|
namespace HtImgModuleTest\Imagine\Loader; |
3
|
|
|
|
4
|
|
|
use HtImgModule\Imagine\Loader\FlysystemLoader; |
5
|
|
|
use League\Flysystem\FileNotFoundException; |
6
|
|
|
|
7
|
|
|
class FlysystemLoaderTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
public function testGetExceptionWhenImageFileCouldNotBeFound() |
10
|
|
|
{ |
11
|
|
|
$filesystem = $this->createMock('League\Flysystem\FilesystemInterface'); |
12
|
|
|
$filesystem->expects($this->exactly(1)) |
13
|
|
|
->method('read') |
14
|
|
|
->with('my/special/image') |
15
|
|
|
->will($this->throwException(new FileNotFoundException('my/special/image'))); |
16
|
|
|
$loader = new FlysystemLoader($filesystem); |
17
|
|
|
|
18
|
|
|
$this->setExpectedException('HtImgModule\Exception\ImageNotFoundException'); |
|
|
|
|
19
|
|
|
$loader->load('my/special/image'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testLoadBinary() |
23
|
|
|
{ |
24
|
|
|
$filesystem = $this->createMock('League\Flysystem\FilesystemInterface'); |
25
|
|
|
$filesystem->expects($this->exactly(1)) |
26
|
|
|
->method('read') |
27
|
|
|
->with('my/special/image') |
28
|
|
|
->will($this->returnValue('some/image/content')); |
29
|
|
|
$filesystem->expects($this->exactly(1)) |
30
|
|
|
->method('getMimeType') |
31
|
|
|
->with('my/special/image') |
32
|
|
|
->will($this->returnValue('image/png')); |
33
|
|
|
$loader = new FlysystemLoader($filesystem); |
34
|
|
|
$binary = $loader->load('my/special/image'); |
35
|
|
|
$this->assertInstanceOf('HtImgModule\Binary\Binary', $binary); |
36
|
|
|
$this->assertEquals('some/image/content', $binary->getContent()); |
37
|
|
|
$this->assertEquals('image/png', $binary->getMimeType()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testLoadOnlyContentsWhenMimeTypeCouldNotDetected() |
41
|
|
|
{ |
42
|
|
|
$filesystem = $this->createMock('League\Flysystem\FilesystemInterface'); |
43
|
|
|
$filesystem->expects($this->exactly(1)) |
44
|
|
|
->method('read') |
45
|
|
|
->with('my/special/image') |
46
|
|
|
->will($this->returnValue('some/image/content')); |
47
|
|
|
$filesystem->expects($this->exactly(1)) |
48
|
|
|
->method('getMimeType') |
49
|
|
|
->with('my/special/image') |
50
|
|
|
->will($this->returnValue(false)); |
51
|
|
|
$loader = new FlysystemLoader($filesystem); |
52
|
|
|
$this->assertEquals('some/image/content', $loader->load('my/special/image')); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.