forked from doctrine/mongodb-odm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DbNameTest.php
81 lines (59 loc) · 2.45 KB
/
DbNameTest.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
<?php
require_once 'TestInit.php';
use Documents\Account,
Documents\User,
Documents\SpecialUser;
class DbNameTest extends BaseTest
{
public function testPrefixDbName()
{
$this->dm->getConfiguration()->setPrefixDBName('test_');
$meta = $this->getMetaData();
$expectedDbName = 'test_doctrine_odm_tests';
$this->assertEquals($meta['account']->getDB(), $expectedDbName);
$this->assertEquals($meta['user']->getDB(), $expectedDbName);
$this->assertEquals($meta['specialUser']->getDB(), $expectedDbName);
}
public function testSuffixDbName()
{
$this->dm->getConfiguration()->setSuffixDBName('_test');
$meta = $this->getMetaData();
$expectedDbName = 'doctrine_odm_tests_test';
$this->assertEquals($meta['account']->getDB(), $expectedDbName);
$this->assertEquals($meta['user']->getDB(), $expectedDbName);
$this->assertEquals($meta['specialUser']->getDB(), $expectedDbName);
}
public function testPrefixAndSuffixDbName()
{
$this->dm->getConfiguration()->setPrefixDBName('test_');
$this->dm->getConfiguration()->setSuffixDBName('_test');
$meta = $this->getMetaData();
$expectedDbName = 'test_doctrine_odm_tests_test';
$this->assertEquals($meta['account']->getDB(), $expectedDbName);
$this->assertEquals($meta['user']->getDB(), $expectedDbName);
$this->assertEquals($meta['specialUser']->getDB(), $expectedDbName);
}
public function testPersist()
{
$this->dm->getConfiguration()->setPrefixDBName('test_');
$account = new Account();
$account->setName('test');
$this->dm->persist($account);
$this->dm->flush();
$this->assertTrue(!is_null($account->getId()));
$mongo = $this->dm->getMongo()->getMongo();
$testAccount = $mongo->test_doctrine_odm_tests
->accounts
->findOne(array('_id' => new \MongoId($account->getId())));
$this->assertTrue(is_array($testAccount));
$this->assertEquals($account->getId(), (string)$testAccount['_id']);
}
protected function getMetaData()
{
return array(
'account' => $this->dm->getClassMetadata('Documents\Account'),
'user' => $this->dm->getClassMetadata('Documents\User'),
'specialUser' => $this->dm->getClassMetadata('Documents\SpecialUser')
);
}
}