forked from doctrine/mongodb-odm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHydratorTest.php
98 lines (81 loc) · 2.51 KB
/
HydratorTest.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
<?php
namespace Doctrine\ODM\MongoDB\Tests;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
class HydratorTest extends BaseTest
{
public function testHydrator()
{
$class = $this->dm->getClassMetadata(__NAMESPACE__.'\HydrationClosureUser');
$user = new HydrationClosureUser();
$this->dm->getHydratorFactory()->hydrate($user, array(
'_id' => 1,
'name' => 'jon',
'referenceOne' => array('$id' => '1'),
'referenceMany' => array(
array(
'$id' => '1'
),
array(
'$id' => '2'
)
),
'embedOne' => array('name' => 'jon'),
'embedMany' => array(
array('name' => 'jon')
)
));
$this->assertEquals(1, $user->id);
$this->assertEquals('jon', $user->name);
$this->assertInstanceOf(__NAMESPACE__.'\HydrationClosureReferenceOne', $user->referenceOne);
$this->assertInstanceOf('Doctrine\ODM\MongoDB\PersistentCollection', $user->referenceMany);
$this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $user->referenceMany[0]);
$this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $user->referenceMany[1]);
$this->assertInstanceOf('Doctrine\ODM\MongoDB\PersistentCollection', $user->embedMany);
$this->assertEquals('jon', $user->embedOne->name);
$this->assertEquals('jon', $user->embedMany[0]->name);
}
}
/** @ODM\Document */
class HydrationClosureUser
{
/** @ODM\Id */
public $id;
/** @ODM\String */
public $name;
/** @ODM\ReferenceOne(targetDocument="HydrationClosureReferenceOne") */
public $referenceOne;
/** @ODM\ReferenceMany(targetDocument="HydrationClosureReferenceMany") */
public $referenceMany = array();
/** @ODM\EmbedOne(targetDocument="HydrationClosureEmbedOne") */
public $embedOne;
/** @ODM\EmbedMany(targetDocument="HydrationClosureEmbedMany") */
public $embedMany = array();
}
/** @ODM\Document */
class HydrationClosureReferenceOne
{
/** @ODM\Id */
public $id;
/** @ODM\String */
public $name;
}
/** @ODM\Document */
class HydrationClosureReferenceMany
{
/** @ODM\Id */
public $id;
/** @ODM\String */
public $name;
}
/** @ODM\EmbeddedDocument */
class HydrationClosureEmbedMany
{
/** @ODM\String */
public $name;
}
/** @ODM\EmbeddedDocument */
class HydrationClosureEmbedOne
{
/** @ODM\String */
public $name;
}