forked from doctrine/mongodb-odm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentManagerTest.php
149 lines (124 loc) · 4.37 KB
/
DocumentManagerTest.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace Doctrine\ODM\MongoDB\Tests;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
/**
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
*/
class DocumentManagerTest extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{
public function testCustomRepository()
{
$dm = $this->getDocumentManager();
$this->assertInstanceOf('Documents\CustomRepository\Repository', $dm->getRepository('Documents\CustomRepository\Document'));
}
public function testGetConnection()
{
$this->assertInstanceOf('\Doctrine\MongoDB\Connection', $this->dm->getConnection());
}
public function testGetMetadataFactory()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory', $this->dm->getMetadataFactory());
}
public function testGetConfiguration()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\Configuration', $this->dm->getConfiguration());
}
public function testGetUnitOfWork()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\UnitOfWork', $this->dm->getUnitOfWork());
}
public function testGetProxyFactory()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\Proxy\ProxyFactory', $this->dm->getProxyFactory());
}
public function testGetEventManager()
{
$this->assertInstanceOf('\Doctrine\Common\EventManager', $this->dm->getEventManager());
}
public function testGetSchemaManager()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\SchemaManager', $this->dm->getSchemaManager());
}
public function testCreateQueryBuilder()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\Query\Builder', $this->dm->createQueryBuilder());
}
public function testGetFilterCollection()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\Query\FilterCollection', $this->dm->getFilterCollection());
}
public function testGetPartialReference()
{
$user = $this->dm->getPartialReference('Documents\CmsUser', 42);
$this->assertTrue($this->dm->contains($user));
$this->assertEquals(42, $user->id);
$this->assertNull($user->getName());
}
static public function dataMethodsAffectedByNoObjectArguments()
{
return array(
array('persist'),
array('remove'),
array('merge'),
array('refresh'),
array('detach')
);
}
/**
* @dataProvider dataMethodsAffectedByNoObjectArguments
* @expectedException \InvalidArgumentException
* @param string $methodName
*/
public function testThrowsExceptionOnNonObjectValues($methodName) {
$this->dm->$methodName(null);
}
static public function dataAffectedByErrorIfClosedException()
{
return array(
array('flush'),
array('persist'),
array('remove'),
array('merge'),
array('refresh'),
);
}
/**
* @dataProvider dataAffectedByErrorIfClosedException
* @param string $methodName
*/
public function testAffectedByErrorIfClosedException($methodName)
{
$this->setExpectedException('Doctrine\ODM\MongoDB\MongoDBException', 'closed');
$this->dm->close();
if ($methodName === 'flush') {
$this->dm->$methodName();
} else {
$this->dm->$methodName(new \stdClass());
}
}
protected function getDocumentManager()
{
$config = new Configuration();
$config->setProxyDir(__DIR__ . '/../../../../Proxies');
$config->setProxyNamespace('Proxies');
$config->setHydratorDir(__DIR__ . '/../../../../Hydrators');
$config->setHydratorNamespace('Hydrators');
$config->setDefaultDB('doctrine_odm_tests');
/*
$config->setLoggerCallable(function(array $log) {
print_r($log);
});
$config->setMetadataCacheImpl(new ApcCache());
*/
$reader = new AnnotationReader();
$config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
return DocumentManager::create($this->getConnection(), $config);
}
protected function getConnection()
{
return $this->getMock('Doctrine\MongoDB\Connection');
}
}