testPostActionWithError()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
namespace Tpg\ExtjsBundle\Tests\Command\ODM;
3
4
use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
5
use Doctrine\ODM\MongoDB\LoggableCursor;
6
use Symfony\Component\Routing\Router;
7
use Test\TestBundle\Document\Order;
8
9
class GeneratedRestControllerTest extends BaseTestGeneratedRestController {
10
11 View Code Duplication
    public function testGetsAction() {
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...
12
        $this->client->request('GET', '/orders.json');
13
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
14
        $content = json_decode($this->client->getResponse()->getContent());
15
        $this->assertEquals(2, count($content));
16
    }
17
18
    public function testGetsActionWithFilterOnTotalPrice() {
19
        $filter = json_encode(array(
20
            array('property'=>'totalPrice', 'value'=>10.58)
21
        ));
22
        $this->client->request('GET', '/orders.json?filter='.$filter);
23
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
24
        $content = json_decode($this->client->getResponse()->getContent(), true);
25
        $this->assertEquals(1, count($content));
26
        $this->assertEquals('Invoice 2', $content[0]['name']);
27
    }
28
29 View Code Duplication
    public function testGetsActionWithSortDESC() {
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...
30
        $sort = json_encode(array(
31
            array('property'=>'totalPrice', 'direction'=>'DESC')
32
        ));
33
        $this->client->request('GET', '/orders.json?sort='.$sort);
34
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
35
        $content = json_decode($this->client->getResponse()->getContent(), true);
36
        $this->assertEquals('Invoice 2', $content[0]['name']);
37
        $this->assertEquals('Invoice 1', $content[1]['name']);
38
    }
39
40 View Code Duplication
    public function testGetsActionWithStart() {
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...
41
        $this->client->request('GET', '/orders.json?start=1');
42
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
43
        $content = json_decode($this->client->getResponse()->getContent(), true);
44
        $this->assertEquals(1, count($content));
45
    }
46
47 View Code Duplication
    public function testGetsActionWithLimit() {
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...
48
        $this->client->request('GET', '/orders.json?limit=1');
49
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
50
        $content = json_decode($this->client->getResponse()->getContent(), true);
51
        $this->assertEquals(1, count($content));
52
    }
53
54 View Code Duplication
    public function testGetsActionWithPage() {
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...
55
        $this->client->request('GET', '/orders.json?page=2');
56
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
57
        $content = json_decode($this->client->getResponse()->getContent(), true);
58
        $this->assertEquals(0, count($content));
59
        $this->client->request('GET', '/orders.json?page=2&limit=1');
60
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
61
        $content = json_decode($this->client->getResponse()->getContent(), true);
62
        $this->assertEquals(1, count($content));
63
    }
64
65 View Code Duplication
    public function testGetActionWithId() {
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...
66
        $repo = $this->client->getContainer()->get('doctrine_mongodb.odm.default_document_manager')->getRepository('TestTestBundle:Order');
67
        /** @var LoggableCursor $orders */
68
        $orders = $repo->findAll();
69
        $order = reset($orders);
70
        $this->client->request('GET', '/orders/'.$order->getId().'.json');
71
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
72
        $content = json_decode($this->client->getResponse()->getContent(), true);
73
        $this->assertEquals($order->getId(), $content['id']);
74
        $this->assertEquals($order->getName(), $content['name']);
75
        $this->assertEquals($order->getTotalPrice(), $content['totalPrice']);
76
    }
77
78
    public function testPostAction() {
79
        $this->client->request('POST', '/orders.json', array(), array(), array(), json_encode(array(
80
            'name'=>'Inveoice 3',
81
            'totalPrice'=>11,
82
        )));
83
        $this->assertEquals("201", $this->client->getResponse()->getStatusCode());
84
        $repo = $this->client->getContainer()->get('doctrine_mongodb.odm.default_document_manager')->getRepository('TestTestBundle:Order');
85
        $this->assertEquals(
86
            3, count($repo->findAll())
87
        );
88
        $record = json_decode($this->client->getResponse()->getContent(), true);
89
        $this->assertEquals('Inveoice 3', $record['name']);
90
        $this->assertEquals(11, $record['totalPrice']);
91
    }
92
93
    public function testPostActionWithError() {
94
        $this->client->request('POST', '/orders.json', array(), array(), array(), json_encode(array(
95
            'name'=>'BMW',
96
        )));
97
        $this->assertEquals("400", $this->client->getResponse()->getStatusCode(), $this->client->getResponse()->getContent());
98
    }
99
100 View Code Duplication
    public function testPutAction() {
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...
101
        $record = $this->records[0];
102
        $this->client->request('PUT', '/orders/'.$record->getId().'.json', array(), array(), array(), json_encode(array(
103
            'name'=>'Invoice A',
104
            'totalPrice'=>12.11,
105
        )));
106
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode(), $this->client->getResponse()->getContent());
107
        $repo = $this->client->getContainer()->get('doctrine_mongodb.odm.default_document_manager')->getRepository('TestTestBundle:Order');
108
        $this->assertEquals(
109
            2, count($repo->findAll())
110
        );
111
        $record = $repo->find($record->getId());
112
        $this->assertEquals('Invoice A', $record->getName());
113
        $this->assertEquals(12.11, $record->getTotalPrice());
114
    }
115
116 View Code Duplication
    public function testPutActionWithSomeEmpty() {
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
        $record = $this->records[0];
118
        $this->client->request('PUT', '/orders/'.$record->getId().'.json', array(), array(), array(), json_encode(array(
119
            'name'=>'Invoice B',
120
        )));
121
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
122
        $repo = $this->client->getContainer()->get('doctrine_mongodb.odm.default_document_manager')->getRepository('TestTestBundle:Order');
123
        $this->assertEquals(
124
            2, count($repo->findAll())
125
        );
126
        $record = $repo->find($record->getId());
127
        $this->assertEquals('Invoice B', $record->getName());
128
        $this->assertEquals(null, $record->getTotalPrice());
129
    }
130
131 View Code Duplication
    public function testPatchAction() {
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...
132
        $originalRecord = $this->records[0];
133
        $this->client->request('PATCH', '/orders/'.$originalRecord->getId().'.json', array(), array(), array(), json_encode(array(
134
            'name'=>'Invoice A',
135
        )));
136
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
137
        $repo = $this->client->getContainer()->get('doctrine_mongodb.odm.default_document_manager')->getRepository('TestTestBundle:Order');
138
        $record = $repo->find($originalRecord->getId());
139
        $this->assertEquals(
140
            2, count($repo->findAll())
141
        );
142
        $this->assertEquals('Invoice A', $record->getName());
143
        $this->assertEquals($originalRecord->getTotalPrice(), $record->getTotalPrice());
144
    }
145
146 View Code Duplication
    public function testDeleteAction() {
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...
147
        $record = $this->records[0];
148
        $id = $record->getId();
149
        $this->client->request('DELETE', '/orders/'.$id.'.json');
150
        $this->assertEquals("204", $this->client->getResponse()->getStatusCode());
151
        $repo = $this->client->getContainer()->get('doctrine_mongodb.odm.default_document_manager')->getRepository('TestTestBundle:Order');
152
        $this->assertNull($repo->find($id));
153
    }
154
}