|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Liip\ImagineBundle\Tests\Binary\Loader; |
|
4
|
|
|
|
|
5
|
|
|
use Liip\ImagineBundle\Binary\Loader\FlysystemLoader; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser; |
|
7
|
|
|
use Liip\ImagineBundle\Tests\AbstractTest; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @requires PHP 5.4 |
|
11
|
|
|
* @covers Liip\ImagineBundle\Binary\Loader\FlysystemLoader |
|
12
|
|
|
*/ |
|
13
|
|
|
class FlysystemLoaderTest extends AbstractTest |
|
14
|
|
|
{ |
|
15
|
|
|
private $flyFilesystem; |
|
16
|
|
|
|
|
17
|
|
|
public function setUp() |
|
18
|
|
|
{ |
|
19
|
|
|
parent::setUp(); |
|
20
|
|
|
|
|
21
|
|
|
if (!class_exists('\League\Flysystem\Filesystem')) { |
|
22
|
|
|
$this->markTestSkipped( |
|
23
|
|
|
'The league/flysystem PHP library is not available.' |
|
24
|
|
|
); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
$adapter = new \League\Flysystem\Adapter\Local($this->fixturesDir); |
|
28
|
|
|
$this->flyFilesystem = new \League\Flysystem\Filesystem($adapter); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testShouldImplementLoaderInterface() |
|
32
|
|
|
{ |
|
33
|
|
|
$rc = new \ReflectionClass('Liip\ImagineBundle\Binary\Loader\FlysystemLoader'); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Binary\Loader\LoaderInterface')); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testCouldBeConstructedWithExpectedArguments() |
|
39
|
|
|
{ |
|
40
|
|
|
return new FlysystemLoader( |
|
41
|
|
|
ExtensionGuesser::getInstance(), |
|
42
|
|
|
$this->flyFilesystem |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @depends testCouldBeConstructedWithExpectedArguments |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testReturnImageContentOnFind($loader) |
|
50
|
|
|
{ |
|
51
|
|
|
$expectedContent = file_get_contents($this->fixturesDir.'/assets/cats.jpeg'); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertSame( |
|
54
|
|
|
$expectedContent, |
|
55
|
|
|
$loader->find('assets/cats.jpeg')->getContent() |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @depends testCouldBeConstructedWithExpectedArguments |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testThrowsIfInvalidPathGivenOnFind($loader) |
|
63
|
|
|
{ |
|
64
|
|
|
$path = 'invalid.jpeg'; |
|
65
|
|
|
|
|
66
|
|
|
$this->setExpectedException( |
|
67
|
|
|
'Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException', |
|
68
|
|
|
sprintf('Source image "%s" not found.', $path) |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
$loader->find($path); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|