| Conditions | 1 |
| Paths | 1 |
| Total Lines | 89 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 107 | public function testActionsBulk() |
||
| 108 | { |
||
| 109 | $client = static::createClient( array(), array( |
||
| 110 | 'PHP_AUTH_USER' => 'admin', |
||
| 111 | 'PHP_AUTH_PW' => 'adminpass', |
||
| 112 | ) ); |
||
| 113 | |||
| 114 | $client->request( 'OPTIONS', '/unittest/jsonadm' ); |
||
| 115 | $json = json_decode( $client->getResponse()->getContent(), true ); |
||
| 116 | $token = $json['meta']['csrf']['value']; |
||
| 117 | |||
| 118 | |||
| 119 | $content = '{"data":[ |
||
| 120 | {"type":"stock/type","attributes":{"stock.type.code":"symfony","stock.type.label":"symfony"}}, |
||
| 121 | {"type":"stock/type","attributes":{"stock.type.code":"symfony2","stock.type.label":"symfony"}} |
||
| 122 | ]}'; |
||
| 123 | $client->request( 'POST', '/unittest/jsonadm/stock/type', ['_token' => $token], [], [], $content ); |
||
| 124 | $response = $client->getResponse(); |
||
| 125 | |||
| 126 | $json = json_decode( $response->getContent(), true ); |
||
| 127 | |||
| 128 | $this->assertNotNull( $json ); |
||
| 129 | $this->assertEquals( 201, $response->getStatusCode() ); |
||
| 130 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
| 131 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] ); |
||
| 132 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] ); |
||
| 133 | $this->assertEquals( 'symfony', $json['data'][0]['attributes']['stock.type.label'] ); |
||
| 134 | $this->assertEquals( 'symfony', $json['data'][1]['attributes']['stock.type.label'] ); |
||
| 135 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
| 136 | |||
| 137 | $ids = array( $json['data'][0]['attributes']['stock.type.id'], $json['data'][1]['attributes']['stock.type.id'] ); |
||
| 138 | |||
| 139 | |||
| 140 | $content = '{"data":[ |
||
| 141 | {"type":"stock/type","id":' . $ids[0] . ',"attributes":{"stock.type.label":"symfony2"}}, |
||
| 142 | {"type":"stock/type","id":' . $ids[1] . ',"attributes":{"stock.type.label":"symfony2"}} |
||
| 143 | ]}'; |
||
| 144 | $client->request( 'PATCH', '/unittest/jsonadm/stock/type', ['_token' => $token], [], [], $content ); |
||
| 145 | $response = $client->getResponse(); |
||
| 146 | |||
| 147 | $json = json_decode( $response->getContent(), true ); |
||
| 148 | |||
| 149 | $this->assertNotNull( $json ); |
||
| 150 | $this->assertEquals( 200, $response->getStatusCode() ); |
||
| 151 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
| 152 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] ); |
||
| 153 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] ); |
||
| 154 | $this->assertEquals( 'symfony2', $json['data'][0]['attributes']['stock.type.label'] ); |
||
| 155 | $this->assertEquals( 'symfony2', $json['data'][1]['attributes']['stock.type.label'] ); |
||
| 156 | $this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) ); |
||
| 157 | $this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) ); |
||
| 158 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
| 159 | |||
| 160 | |||
| 161 | $getParams = array( 'filter' => array( '&&' => array( |
||
| 162 | array( '=~' => array( 'stock.type.code' => 'symfony' ) ), |
||
| 163 | array( '==' => array( 'stock.type.label' => 'symfony2' ) ) |
||
| 164 | ) ), |
||
| 165 | 'sort' => 'stock.type.code', 'page' => array( 'offset' => 0, 'limit' => 3 ) |
||
| 166 | ); |
||
| 167 | $client->request( 'GET', '/unittest/jsonadm/stock/type', $getParams ); |
||
| 168 | $response = $client->getResponse(); |
||
| 169 | |||
| 170 | $json = json_decode( $response->getContent(), true ); |
||
| 171 | |||
| 172 | $this->assertNotNull( $json ); |
||
| 173 | $this->assertEquals( 200, $response->getStatusCode() ); |
||
| 174 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
| 175 | $this->assertEquals( 'symfony', $json['data'][0]['attributes']['stock.type.code'] ); |
||
| 176 | $this->assertEquals( 'symfony2', $json['data'][1]['attributes']['stock.type.code'] ); |
||
| 177 | $this->assertEquals( 'symfony2', $json['data'][0]['attributes']['stock.type.label'] ); |
||
| 178 | $this->assertEquals( 'symfony2', $json['data'][1]['attributes']['stock.type.label'] ); |
||
| 179 | $this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) ); |
||
| 180 | $this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) ); |
||
| 181 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
| 182 | |||
| 183 | |||
| 184 | $content = '{"data":[ |
||
| 185 | {"type":"stock/type","id":' . $ids[0] . '}, |
||
| 186 | {"type":"stock/type","id":' . $ids[1] . '} |
||
| 187 | ]}'; |
||
| 188 | $client->request( 'DELETE', '/unittest/jsonadm/stock/type', ['_token' => $token], [], [], $content ); |
||
| 189 | $response = $client->getResponse(); |
||
| 190 | |||
| 191 | $json = json_decode( $response->getContent(), true ); |
||
| 192 | |||
| 193 | $this->assertNotNull( $json ); |
||
| 194 | $this->assertEquals( 200, $response->getStatusCode() ); |
||
| 195 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
| 196 | } |
||
| 198 |