1
|
|
|
<?php |
2
|
|
|
namespace HtImgModuleTest\Imagine\Loader; |
3
|
|
|
|
4
|
|
|
use Gaufrette\Exception\FileNotFound as FileNotFoundException; |
5
|
|
|
use HtImgModule\Imagine\Loader\GaufretteLoader; |
6
|
|
|
|
7
|
|
|
class GaufretteLoaderTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
public function testGetExceptionWhenImageCouldNotBeFound() |
10
|
|
|
{ |
11
|
|
|
$filesystem = $this->getMockBuilder('Gaufrette\Filesystem') |
12
|
|
|
->disableOriginalConstructor() |
13
|
|
|
->getMock(); |
14
|
|
|
$filesystem->expects($this->exactly(1)) |
15
|
|
|
->method('read') |
16
|
|
|
->with('my/special/image') |
17
|
|
|
->will($this->throwException(new FileNotFoundException('my/special/image'))); |
18
|
|
|
$loader = new GaufretteLoader($filesystem); |
19
|
|
|
|
20
|
|
|
$this->setExpectedException('HtImgModule\Exception\ImageNotFoundException'); |
|
|
|
|
21
|
|
|
$loader->load('my/special/image'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testLoadOnlyContents() |
25
|
|
|
{ |
26
|
|
|
$filesystem = $this->getMockBuilder('Gaufrette\Filesystem') |
27
|
|
|
->disableOriginalConstructor() |
28
|
|
|
->getMock(); |
29
|
|
|
$filesystem->expects($this->exactly(1)) |
30
|
|
|
->method('read') |
31
|
|
|
->will($this->returnValue('some/image/content')); |
32
|
|
|
$loader = new GaufretteLoader($filesystem); |
33
|
|
|
$this->assertEquals('some/image/content', $loader->load('asdfasdf')); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testLoadOnlyContentsWhenLogicException() |
37
|
|
|
{ |
38
|
|
|
$filesystem = $this->getMockBuilder('Gaufrette\Filesystem') |
39
|
|
|
->disableOriginalConstructor() |
40
|
|
|
->getMock(); |
41
|
|
|
$filesystem->expects($this->exactly(1)) |
42
|
|
|
->method('read') |
43
|
|
|
->will($this->returnValue('some/image/content')); |
44
|
|
|
$filesystem->expects($this->exactly(1)) |
45
|
|
|
->method('mimeType') |
46
|
|
|
->will($this->throwException(new \LogicException)); |
47
|
|
|
$loader = new GaufretteLoader($filesystem); |
48
|
|
|
$this->assertEquals('some/image/content', $loader->load('asdfasdf')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testGetBinary() |
52
|
|
|
{ |
53
|
|
|
$filesystem = $this->getMockBuilder('Gaufrette\Filesystem') |
54
|
|
|
->disableOriginalConstructor() |
55
|
|
|
->getMock(); |
56
|
|
|
$filesystem->expects($this->exactly(1)) |
57
|
|
|
->method('read') |
58
|
|
|
->will($this->returnValue('some/image/content')); |
59
|
|
|
$filesystem->expects($this->exactly(1)) |
60
|
|
|
->method('mimeType') |
61
|
|
|
->will($this->returnValue('image/jpeg')); |
62
|
|
|
$loader = new GaufretteLoader($filesystem); |
63
|
|
|
$binary = $loader->load('asdfasdf'); |
64
|
|
|
$this->assertInstanceOf('HtImgModule\Binary\Binary', $binary); |
65
|
|
|
$this->assertEquals('some/image/content', $binary->getContent()); |
66
|
|
|
$this->assertEquals('image/jpeg', $binary->getMimeType()); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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.