EmbedNestedTest::testFind()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 1
nc 1
nop 0
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';
0 ignored issues
show
Bug introduced by
The property type does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
16
        $this->embeddedType = 'Doctrine\Tests\Models\Embedded\Embedded';
0 ignored issues
show
Bug introduced by
The property embeddedType does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
17
        $this->nestedType = 'Doctrine\Tests\Models\Embedded\Nested';
0 ignored issues
show
Bug introduced by
The property nestedType does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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