Conditions | 1 |
Paths | 1 |
Total Lines | 82 |
Code Lines | 57 |
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 |
||
109 | public function testActionsBulk() |
||
110 | { |
||
111 | View::addLocation( dirname( __DIR__ ) . '/fixtures/views' ); |
||
112 | $this->app['session']->setPreviousUrl( 'http://localhost/unittest' ); |
||
113 | |||
114 | $params = ['site' => 'unittest', 'resource' => 'stock/type']; |
||
115 | $content = '{"data":[ |
||
116 | {"type":"stock/type","attributes":{"stock.type.code":"laravel","stock.type.label":"laravel"}}, |
||
117 | {"type":"stock/type","attributes":{"stock.type.code":"laravel2","stock.type.label":"laravel"}} |
||
118 | ]}'; |
||
119 | $response = $this->action( 'POST', '\Aimeos\Shop\Controller\JsonadmController@postAction', $params, [], [], [], [], $content ); |
||
120 | |||
121 | $json = json_decode( $response->getContent(), true ); |
||
122 | |||
123 | $this->assertEquals( 201, $response->getStatusCode() ); |
||
124 | $this->assertNotNull( $json ); |
||
125 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
126 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] ); |
||
127 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] ); |
||
128 | $this->assertEquals( 'laravel', $json['data'][0]['attributes']['stock.type.label'] ); |
||
129 | $this->assertEquals( 'laravel', $json['data'][1]['attributes']['stock.type.label'] ); |
||
130 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
131 | |||
132 | $ids = array( $json['data'][0]['attributes']['stock.type.id'], $json['data'][1]['attributes']['stock.type.id'] ); |
||
133 | |||
134 | |||
135 | $params = ['site' => 'unittest', 'resource' => 'stock/type']; |
||
136 | $content = '{"data":[ |
||
137 | {"type":"stock/type","id":' . $ids[0] . ',"attributes":{"stock.type.label":"laravel2"}}, |
||
138 | {"type":"stock/type","id":' . $ids[1] . ',"attributes":{"stock.type.label":"laravel2"}} |
||
139 | ]}'; |
||
140 | $response = $this->action( 'PATCH', '\Aimeos\Shop\Controller\JsonadmController@patchAction', $params, [], [], [], [], $content ); |
||
141 | |||
142 | $json = json_decode( $response->getContent(), true ); |
||
143 | |||
144 | $this->assertResponseOk(); |
||
145 | $this->assertNotNull( $json ); |
||
146 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
147 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] ); |
||
148 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] ); |
||
149 | $this->assertEquals( 'laravel2', $json['data'][0]['attributes']['stock.type.label'] ); |
||
150 | $this->assertEquals( 'laravel2', $json['data'][1]['attributes']['stock.type.label'] ); |
||
151 | $this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) ); |
||
152 | $this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) ); |
||
153 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
154 | |||
155 | |||
156 | $params = ['site' => 'unittest', 'resource' => 'stock/type']; |
||
157 | $getParams = ['filter' => ['&&' => [ |
||
158 | ['=~' => ['stock.type.code' => 'laravel']], |
||
159 | ['==' => ['stock.type.label' => 'laravel2']] |
||
160 | ]], |
||
161 | 'sort' => 'stock.type.code', 'page' => ['offset' => 0, 'limit' => 3] |
||
162 | ]; |
||
163 | $response = $this->action( 'GET', '\Aimeos\Shop\Controller\JsonadmController@getAction', $params, $getParams ); |
||
164 | |||
165 | $json = json_decode( $response->getContent(), true ); |
||
166 | |||
167 | $this->assertResponseOk(); |
||
168 | $this->assertNotNull( $json ); |
||
169 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
170 | $this->assertEquals( 'laravel', $json['data'][0]['attributes']['stock.type.code'] ); |
||
171 | $this->assertEquals( 'laravel2', $json['data'][1]['attributes']['stock.type.code'] ); |
||
172 | $this->assertEquals( 'laravel2', $json['data'][0]['attributes']['stock.type.label'] ); |
||
173 | $this->assertEquals( 'laravel2', $json['data'][1]['attributes']['stock.type.label'] ); |
||
174 | $this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) ); |
||
175 | $this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) ); |
||
176 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
177 | |||
178 | |||
179 | $params = ['site' => 'unittest', 'resource' => 'stock/type']; |
||
180 | $content = '{"data":[ |
||
181 | {"type":"stock/type","id":' . $ids[0] . '}, |
||
182 | {"type":"stock/type","id":' . $ids[1] . '} |
||
183 | ]}'; |
||
184 | $response = $this->action( 'DELETE', '\Aimeos\Shop\Controller\JsonadmController@deleteAction', $params, [], [], [], [], $content ); |
||
185 | |||
186 | $json = json_decode( $response->getContent(), true ); |
||
187 | |||
188 | $this->assertResponseOk(); |
||
189 | $this->assertNotNull( $json ); |
||
190 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
191 | } |
||
212 |