DoctrineAssociationsTest::addTestData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 9.232
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Doctrine\Tests\ODM\CouchDB\View;
4
5
use Doctrine\CouchDB\HTTP\SocketClient;
6
use Doctrine\CouchDB\View\Query;
7
use Doctrine\ODM\CouchDB\View\DoctrineAssociations;
8
use Doctrine\ODM\CouchDB\Mapping\ClassMetadata;
9
use Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase;
10
11
class DoctrineAssociationsTest extends CouchDBFunctionalTestCase
12
{
13
    private $dm;
14
15
    public function setUp()
16
    {
17
        $this->dm = $this->createDocumentManager();
18
    }
19
20
    /**
21
     * @return NativeQuery
22
     */
23
    protected function createDoctrineViewQuery()
24
    {
25
        return new Query(
26
            $this->dm->getHttpClient(),
27
            $this->dm->getDatabase(),
28
            'doctrine',
29
            'inverse_associations',
30
            new DoctrineAssociations()
31
        );
32
    }
33
34
    protected function addTestData()
35
    {
36
        $db = $this->dm->getHttpClient();
37
38
        // Force empty test database
39
        try {
40
            $db->request( 'DELETE', '/' . $this->getTestDatabase() . '' );
41
        } catch ( \Exception $e ) { /* Irrelevant exception */ }
42
        $db->request( 'PUT', '/' . $this->getTestDatabase() . '' );
43
44
        // Create some "interesting" documents
45
        $db->request( 'PUT', '/' . $this->getTestDatabase() . '/doc_a', json_encode( array(
46
            "_id" => "doc_a",
47
            "type" => "type_a",
48
            "doctrine_metadata" => array(
49
                "associations" => array("type_b", "type_c"),
50
            ),
51
            "type_b" => array( "doc_b" ),
52
            "type_c" => array( "doc_d" ),
53
        ) ) );
54
        $db->request( 'PUT', '/' . $this->getTestDatabase() . '/doc_b', json_encode( array(
55
            "_id" => "doc_b",
56
            "doctrine_metadata" => array(
57
                "type" => "type_b",
58
                "associations" => array("type_c")
59
            ),
60
            "type_c" => array( "doc_c", "doc_d" ),
61
        ) ) );
62
        $db->request( 'PUT', '/' . $this->getTestDatabase() . '/doc_c', json_encode( array(
63
            "_id" => "doc_c",
64
            "doctrine_metadata" => array(
65
                "type" => "type_c",
66
                "associations" => array(),
67
            ),
68
        ) ) );
69
        $db->request( 'PUT', '/' . $this->getTestDatabase() . '/doc_d', json_encode( array(
70
            "_id" => "doc_d",
71
            "doctrine_metadata" => array(
72
                "type" => "type_c",
73
                "associations" => array(),
74
            ),
75
        ) ) );
76
    }
77
78
    public function testFetchReverseRelations()
79
    {
80
        $this->addTestData();
81
82
        $view = $this->createDoctrineViewQuery();
83
        $result = $view->setStartKey( array("doc_b", "type_b") )
0 ignored issues
show
Documentation introduced by
array('doc_b', 'type_b') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
84
                       ->setEndKey( array("doc_b", "type_b", "z") )
0 ignored issues
show
Documentation introduced by
array('doc_b', 'type_b', 'z') is of type array<integer,string,{"0..."string","2":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
                       ->execute();
86
87
        $this->assertEquals(array("_id" => "doc_a"), $result[0]['value']);
88
    }
89
    
90
    public function testFetchReverseRelations1()
91
    {
92
        $this->addTestData();
93
94
        $view = $this->createDoctrineViewQuery();
95
        $result = $view->setStartKey( array("doc_d", "type_c") )
0 ignored issues
show
Documentation introduced by
array('doc_d', 'type_c') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
96
                       ->setEndKey(   array("doc_d", "type_c", "z") )
0 ignored issues
show
Documentation introduced by
array('doc_d', 'type_c', 'z') is of type array<integer,string,{"0..."string","2":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
97
                       ->execute();
98
99
        $this->assertEquals(array("_id" => "doc_a"), $result[0]['value']);
100
        $this->assertEquals(array("_id" => "doc_b"), $result[1]['value']);
101
    }
102
103 View Code Duplication
    public function testFetchReverseRelations2()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
    {
105
        $this->addTestData();
106
107
        $view = $this->createDoctrineViewQuery();
108
        $result = $view->setStartKey( array("doc_d", "type_b") )
0 ignored issues
show
Documentation introduced by
array('doc_d', 'type_b') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
109
                       ->setEndKey(   array("doc_d", "type_b", "z") )
0 ignored issues
show
Documentation introduced by
array('doc_d', 'type_b', 'z') is of type array<integer,string,{"0..."string","2":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
110
                       ->execute();
111
112
        $this->assertEquals(array(), $result->toArray() );
113
    }
114
115
116 View Code Duplication
    public function testFetchNoReverseRelations()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
    {
118
        $this->addTestData();
119
120
        $view = $this->createDoctrineViewQuery();
121
        $result = $view->setStartKey( array("doc_c", "type_a") )
0 ignored issues
show
Documentation introduced by
array('doc_c', 'type_a') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
122
                       ->setEndKey(   array("doc_c", "type_a", "z") )
0 ignored issues
show
Documentation introduced by
array('doc_c', 'type_a', 'z') is of type array<integer,string,{"0..."string","2":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
123
                       ->execute();
124
125
        $this->assertEquals(array(), $result->toArray() );
126
    }
127
}
128
129