testPutActionWithSomeEmpty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 14
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 14
loc 14
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
namespace Tpg\ExtjsBundle\Tests\Command\ORM;
3
4
use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
5
use Symfony\Component\Routing\Router;
6
use Test\TestBundle\Entity\Car;
7
8
class GeneratedRestControllerTest extends BaseTestGeneratedRestController {
9
10 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...
11
        $this->client->request('GET', '/cars.json');
12
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
13
        $content = json_decode($this->client->getResponse()->getContent());
14
        $this->assertEquals(3, count($content));
15
    }
16
17
    public function testGetsActionWithFilterOnName() {
18
        $filter = json_encode(array(
19
            array('property'=>'name','value'=>'Ford')
20
        ));
21
        $this->client->request('GET', '/cars.json?filter='.$filter);
22
        $content = json_decode($this->client->getResponse()->getContent(), true);
23
        $this->assertEquals(1, count($content));
24
        $this->assertEquals('AA123', $content[0]['plateNumber']);
25
    }
26
27
    public function testGetsActionWithFilterOnPlateNumner() {
28
        $filter = json_encode(array(
29
            array('property'=>'plateNumber','value'=>'BB243')
30
        ));
31
        $this->client->request('GET', '/cars.json?filter='.$filter);
32
        $content = json_decode($this->client->getResponse()->getContent(), true);
33
        $this->assertEquals(1, count($content));
34
    }
35
36
    public function testGetsActionWithFilterOnBothReturnNothing() {
37
        $filter = json_encode(array(
38
            array('property'=>'name', 'value'=>'Ford'),
39
            array('property'=>'plateNumber', 'value'=>'BB243')
40
        ));
41
        $this->client->request('GET', '/cars.json?filter='.$filter);
42
        $content = json_decode($this->client->getResponse()->getContent(), true);
43
        $this->assertEquals(0, count($content));
44
    }
45
46 View Code Duplication
    public function testGetsActionWithSortASC() {
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...
47
        $sort = json_encode(array(
48
            array('property'=>'name', 'direction'=>'ASC')
49
        ));
50
        $this->client->request('GET', '/cars.json?sort='.$sort);
51
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
52
        $content = json_decode($this->client->getResponse()->getContent(), true);
53
        $this->assertEquals('Ford', $content[0]['name']);
54
        $this->assertEquals('Honda', $content[1]['name']);
55
    }
56
57
    public function testGetsActionWithSortDESC() {
58
        $sort = json_encode(array(
59
            array('property'=>'name', 'direction'=>'DESC')
60
        ));
61
        $this->client->request('GET', '/cars.json?sort='.$sort);
62
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
63
        $content = json_decode($this->client->getResponse()->getContent(), true);
64
        $this->assertEquals('Ford', $content[2]['name']);
65
        $this->assertEquals('Honda', $content[1]['name']);
66
        $this->assertEquals('Toyota', $content[0]['name']);
67
    }
68
69 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...
70
        $this->client->request('GET', '/cars.json?start=1');
71
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
72
        $content = json_decode($this->client->getResponse()->getContent(), true);
73
        $this->assertEquals(2, count($content));
74
    }
75
76 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...
77
        $this->client->request('GET', '/cars.json?limit=1');
78
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
79
        $content = json_decode($this->client->getResponse()->getContent(), true);
80
        $this->assertEquals(1, count($content));
81
    }
82
83 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...
84
        $this->client->request('GET', '/cars.json?page=2');
85
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
86
        $content = json_decode($this->client->getResponse()->getContent(), true);
87
        $this->assertEquals(0, count($content));
88
        $this->client->request('GET', '/cars.json?page=2&limit=1');
89
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
90
        $content = json_decode($this->client->getResponse()->getContent(), true);
91
        $this->assertEquals(1, count($content));
92
    }
93
94 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...
95
        $repo = $this->client->getContainer()->get('doctrine.orm.default_entity_manager')->getRepository('TestTestBundle:Car');
96
        $cars = $repo->findAll();
97
        /** @var Car $car */
98
        $car = $cars[0];
99
        $this->client->request('GET', '/cars/'.$car->getId().'.json');
100
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
101
        $content = json_decode($this->client->getResponse()->getContent(), true);
102
        $this->assertEquals($car->getId(), $content['id']);
103
        $this->assertEquals($car->getName(), $content['name']);
104
        $this->assertEquals($car->getPlateNumber(), $content['plateNumber']);
105
    }
106
107
    public function testPostAction() {
108
        $this->client->request('POST', '/cars.json', array(), array(), array(), json_encode(array(
109
            'name'=>'BMW',
110
            'plateNumber'=>'ZZ1267',
111
        )));
112
        $this->assertEquals("201", $this->client->getResponse()->getStatusCode());
113
        $repo = $this->client->getContainer()->get('doctrine.orm.default_entity_manager')->getRepository('TestTestBundle:Car');
114
        $this->assertEquals(
115
            4, count($repo->findAll())
116
        );
117
        $record = json_decode($this->client->getResponse()->getContent(), true);
118
        $this->assertEquals('BMW', $record['name']);
119
        $this->assertEquals('ZZ1267', $record['plateNumber']);
120
    }
121
122 View Code Duplication
    public function testPostActionWithJMSGroup() {
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...
123
        $this->client->request('POST', '/cars.json', array(), array(), array(), json_encode(array(
124
            'name'=>'BMW',
125
            'plateNumber'=>'ZZ1267',
126
            'password'=>'xxx',
127
        )));
128
        $this->assertEquals("201", $this->client->getResponse()->getStatusCode());
129
        $repo = $this->client->getContainer()->get('doctrine.orm.default_entity_manager')->getRepository('TestTestBundle:Car');
130
        $record = json_decode($this->client->getResponse()->getContent(), true);
131
        $this->assertArrayNotHasKey('password', $record);
132
        $this->assertEquals('xxx', $repo->find($record['id'])->getPassword());
133
    }
134
135
    public function testPostActionWithError() {
136
        $this->client->request('POST', '/cars.json', array(), array(), array(), json_encode(array(
137
            'name'=>'BMW',
138
        )));
139
        $this->assertEquals("400", $this->client->getResponse()->getStatusCode(), $this->client->getResponse()->getContent());
140
    }
141
142 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...
143
        $record = $this->records[0];
144
        $this->client->request('PUT', '/cars/'.$record->getId().'.json', array(), array(), array(), json_encode(array(
145
            'name'=>'Mazda',
146
            'plateNumber'=>'AA00',
147
        )));
148
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode(), $this->client->getResponse()->getContent());
149
        $repo = $this->client->getContainer()->get('doctrine.orm.default_entity_manager')->getRepository('TestTestBundle:Car');
150
        $this->assertEquals(
151
            3, count($repo->findAll())
152
        );
153
        $record = $repo->find($record->getId());
154
        $this->assertEquals('Mazda', $record->getName());
155
        $this->assertEquals('AA00', $record->getPlateNumber());
156
    }
157
158 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...
159
        $record = $this->records[0];
160
        $this->client->request('PUT', '/cars/'.$record->getId().'.json', array(), array(), array(), json_encode(array(
161
            'name'=>'Mazda',
162
        )));
163
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
164
        $repo = $this->client->getContainer()->get('doctrine.orm.default_entity_manager')->getRepository('TestTestBundle:Car');
165
        $this->assertEquals(
166
            3, count($repo->findAll())
167
        );
168
        $record = $repo->find($record->getId());
169
        $this->assertEquals('Mazda', $record->getName());
170
        $this->assertEquals(null, $record->getPlateNumber());
171
    }
172
173 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...
174
        $originalRecord = $this->records[0];
175
        $this->client->request('PATCH', '/cars/'.$originalRecord->getId().'.json', array(), array(), array(), json_encode(array(
176
            'name'=>'Mazda',
177
        )));
178
        $this->assertEquals("200", $this->client->getResponse()->getStatusCode());
179
        $repo = $this->client->getContainer()->get('doctrine.orm.default_entity_manager')->getRepository('TestTestBundle:Car');
180
        $record = $repo->find($originalRecord->getId());
181
        $this->assertEquals(
182
            3, count($repo->findAll())
183
        );
184
        $this->assertEquals('Mazda', $record->getName());
185
        $this->assertEquals($originalRecord->getPlateNumber(), $record->getPlateNumber());
186
    }
187
188 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...
189
        $record = $this->records[0];
190
        $id = $record->getId();
191
        $this->client->request('DELETE', '/cars/'.$id.'.json');
192
        $this->assertEquals("204", $this->client->getResponse()->getStatusCode());
193
        $repo = $this->client->getContainer()->get('doctrine.orm.default_entity_manager')->getRepository('TestTestBundle:Car');
194
        $this->assertNull($repo->find($id));
195
    }
196
}