This repository has been archived by the owner on Nov 11, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathLoggableGridFSTest.php
91 lines (71 loc) · 2.6 KB
/
LoggableGridFSTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Doctrine\MongoDB\Tests;
use MongoGridFS;
use MongoGridFSFile;
use Doctrine\MongoDB\GridFSFile;
use Doctrine\MongoDB\LoggableGridFS;
use Doctrine\MongoDB\Database;
use Doctrine\Common\EventManager;
class LoggableGridFSTest extends TestCase
{
const COLLECTION_NAME = 'collectionName';
const DATABASE_NAME = 'databaseName';
public function testLog()
{
$logResult = false;
$loggableGridFS = $this->getLoggableGridFS($this->getLoggerCallable($logResult));
$loggableGridFS->log(['test' => 'test']);
$expected = [
'collection' => self::COLLECTION_NAME,
'db' => self::DATABASE_NAME,
'test' => 'test'
];
$this->assertEquals($expected, $logResult);
}
public function testStoreFileLog()
{
$logResult = false;
$loggableGridFS = $this->getLoggableGridFS($this->getLoggerCallable($logResult));
$mongoGridFSFile = $this->getMockBuilder(MongoGridFSFile::class)
->disableOriginalConstructor()
->getMock();
$this->mongoCollection->expects($this->any())
->method('get')
->will($this->returnValue($mongoGridFSFile));
$document = $document = ['foo' => 'bar'];
$loggableGridFS->storeFile(__FILE__, $document, array('foo' => 'bar'));
$expectedLog = [
'storeFile' => true,
'options' => array('foo' => 'bar'),
'db' => self::DATABASE_NAME,
'count' => 1,
'collection' => self::COLLECTION_NAME,
];
$this->assertEquals($expectedLog, $logResult);
}
private function getLoggerCallable(&$called)
{
return function($msg) use (&$called) {
$called = $msg;
};
}
private function getLoggableGridFS($loggerCallable)
{
$database = $this->getMockBuilder(Database::class)
->disableOriginalConstructor()
->getMock();
$database->expects($this->any())
->method('getName')
->will($this->returnValue(self::DATABASE_NAME));
$this->mongoCollection = $this->getMockBuilder(MongoGridFS::class)
->disableOriginalConstructor()
->getMock();
$this->mongoCollection->expects($this->any())
->method('getName')
->will($this->returnValue(self::COLLECTION_NAME));
$eventManager = $this->getMockBuilder(EventManager::class)
->disableOriginalConstructor()
->getMock();
return new LoggableGridFS($database, $this->mongoCollection, $eventManager, 0, $loggerCallable);
}
}