|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Liip\ImagineBundle\Tests\Binary\Loader; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\MongoDB\GridFSFile; |
|
6
|
|
|
use Doctrine\ODM\MongoDB\DocumentRepository; |
|
7
|
|
|
use Liip\ImagineBundle\Binary\Loader\GridFSLoader; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @covers Liip\ImagineBundle\Binary\Loader\GridFSLoader<extended> |
|
11
|
|
|
*/ |
|
12
|
|
|
class GridFSLoaderTest extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var DocumentRepository |
|
16
|
|
|
*/ |
|
17
|
|
|
private $repo; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var GridFSLoader |
|
21
|
|
|
*/ |
|
22
|
|
|
private $loader; |
|
23
|
|
|
|
|
24
|
|
|
public function setUp() |
|
25
|
|
|
{ |
|
26
|
|
|
if (!extension_loaded('mongodb')) { |
|
27
|
|
|
$this->markTestSkipped('ext/mongodb is not installed'); |
|
28
|
|
|
} |
|
29
|
|
|
if (!class_exists('Doctrine\MongoDB\GridFSFile')) { |
|
30
|
|
|
$this->markTestSkipped('doctrine mongo odm is not installed'); |
|
31
|
|
|
} |
|
32
|
|
|
$this->repo = $this->getMockBuilder('Doctrine\ODM\MongoDB\DocumentRepository')->disableOriginalConstructor()->getMock(); |
|
33
|
|
|
|
|
34
|
|
|
$dm = $this->getMockBuilder('Doctrine\ODM\MongoDB\DocumentManager')->disableOriginalConstructor()->getMock(); |
|
35
|
|
|
$dm->expects($this->any())->method('getRepository')->with('\Foo\Bar')->will($this->returnValue($this->repo)); |
|
36
|
|
|
|
|
37
|
|
|
$this->loader = new GridFSLoader($dm, '\Foo\Bar'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testFindWithValidDocument() |
|
41
|
|
|
{ |
|
42
|
|
|
$image = new GridFSFile(); |
|
43
|
|
|
$image->setBytes('01010101'); |
|
44
|
|
|
|
|
45
|
|
|
$imageDocument = $this->getMock('ImageDocument', array('getFile')); |
|
46
|
|
|
$imageDocument |
|
47
|
|
|
->expects($this->any()) |
|
48
|
|
|
->method('getFile') |
|
49
|
|
|
->with() |
|
50
|
|
|
->will($this->returnValue($image)) |
|
51
|
|
|
; |
|
52
|
|
|
|
|
53
|
|
|
$this->repo->expects($this->atLeastOnce())->method('find')->with($this->isInstanceOf('\MongoId'))->will($this->returnValue($imageDocument)); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertEquals('01010101', $this->loader->find('0123456789abcdef01234567')); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @expectedException \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testFindWithInValidDocument() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->repo->expects($this->atLeastOnce())->method('find')->with($this->isInstanceOf('\MongoId'))->will($this->returnValue(null)); |
|
64
|
|
|
|
|
65
|
|
|
$this->loader->find('0123456789abcdef01234567'); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|