EmbedNestedTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 57
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 30 1
A testFind() 0 20 1
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