1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ODM\CouchDB\Functional; |
4
|
|
|
|
5
|
|
|
use Doctrine\Tests\Models\Embedded\Embedded; |
6
|
|
|
use Doctrine\Tests\Models\Embedded\Embedder; |
7
|
|
|
use Doctrine\Tests\Models\Embedded\Nested; |
8
|
|
|
|
9
|
|
|
class EmbedNestedTest extends \Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase |
10
|
|
|
{ |
11
|
|
|
private $dm; |
12
|
|
|
|
13
|
|
|
public function setUp() |
14
|
|
|
{ |
15
|
|
|
$this->type = 'Doctrine\Tests\Models\Embedded\Embedder'; |
|
|
|
|
16
|
|
|
$this->embeddedType = 'Doctrine\Tests\Models\Embedded\Embedded'; |
|
|
|
|
17
|
|
|
$this->nestedType = 'Doctrine\Tests\Models\Embedded\Nested'; |
|
|
|
|
18
|
|
|
$this->dm = $this->createDocumentManager(); |
19
|
|
|
|
20
|
|
|
$httpClient = $this->dm->getHttpClient(); |
21
|
|
|
$data = json_encode( |
22
|
|
|
array( |
23
|
|
|
'_id' => "1", |
24
|
|
|
'embedded' => array( |
25
|
|
|
'name' => 'embedded one', |
26
|
|
|
'embeds' => array( |
27
|
|
|
array( |
28
|
|
|
'nestedName' => 'nested one', |
29
|
|
|
'type' => $this->nestedType |
30
|
|
|
), |
31
|
|
|
array( |
32
|
|
|
'nestedName' => 'nested two', |
33
|
|
|
'type' => $this->nestedType |
34
|
|
|
) |
35
|
|
|
), |
36
|
|
|
'type' => $this->embeddedType |
37
|
|
|
), |
38
|
|
|
'type' => $this->type |
39
|
|
|
)); |
40
|
|
|
$resp = $httpClient->request('PUT', '/' . $this->dm->getDatabase() . '/1', $data); |
41
|
|
|
$this->assertEquals(201, $resp->status); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testFind() |
45
|
|
|
{ |
46
|
|
|
$embedder = $this->dm->find($this->type, 1); |
47
|
|
|
$this->assertNotNull($embedder); |
48
|
|
|
$this->assertInstanceOf($this->type, $embedder); |
49
|
|
|
$embedded = $embedder->embedded; |
50
|
|
|
$this->assertNotNull($embedded); |
51
|
|
|
$this->assertInstanceOf($this->embeddedType, $embedded); |
52
|
|
|
|
53
|
|
|
$nesteds = $embedded->embeds; |
54
|
|
|
$this->assertCount(2, $nesteds); |
55
|
|
|
|
56
|
|
|
$nested = $nesteds[0]; |
57
|
|
|
$this->assertInstanceOf($this->nestedType, $nested); |
58
|
|
|
$this->assertEquals('nested one', $nested->nestedName); |
59
|
|
|
$nested = $nesteds[1]; |
60
|
|
|
$this->assertInstanceOf($this->nestedType, $nested); |
61
|
|
|
$this->assertEquals('nested two', $nested->nestedName); |
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: