| Conditions | 1 |
| Paths | 1 |
| Total Lines | 107 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 140 | public function testUpdateFiles() |
||
| 141 | { |
||
| 142 | $timeFormat = 'Y-m-d\TH:i:sP'; |
||
| 143 | |||
| 144 | $jsonData = '{ |
||
| 145 | "links": [ |
||
| 146 | { |
||
| 147 | "$ref": "http://localhost/testcase/readonly/101", |
||
| 148 | "type": "owner" |
||
| 149 | }, |
||
| 150 | { |
||
| 151 | "$ref": "http://localhost/testcase/readonly/102", |
||
| 152 | "type": "module" |
||
| 153 | } |
||
| 154 | ], |
||
| 155 | "metadata": { |
||
| 156 | "action":[{"command":"print"},{"command":"archive"}] |
||
| 157 | } |
||
| 158 | }'; |
||
| 159 | |||
| 160 | $uploadedFile = $this->getUploadFile('test.txt'); |
||
| 161 | $client = $this->createClient(); |
||
| 162 | $client->request( |
||
| 163 | 'POST', |
||
| 164 | '/file', |
||
| 165 | [ |
||
| 166 | 'metadata' => $jsonData, |
||
| 167 | ], |
||
| 168 | [ |
||
| 169 | 'upload' => $uploadedFile, |
||
| 170 | ] |
||
| 171 | ); |
||
| 172 | $response = $client->getResponse(); |
||
| 173 | $location = $response->headers->get('location'); |
||
| 174 | |||
| 175 | $this->assertEquals(Response::HTTP_CREATED, $response->getStatusCode()); |
||
| 176 | $this->assertContains('/file/', $location); |
||
| 177 | |||
| 178 | // receive generated file information |
||
| 179 | $client = $this->createClient(); |
||
| 180 | $client->request('GET', $location, [], [], ['HTTP_ACCEPT' => 'application/json']); |
||
| 181 | |||
| 182 | $response = $client->getResponse(); |
||
| 183 | $contentArray = json_decode($response->getContent(), true); |
||
| 184 | |||
| 185 | // Check contain data |
||
| 186 | $this->assertArrayHasKey('modificationDate', $contentArray['metadata']); |
||
| 187 | $this->assertArrayHasKey('createDate', $contentArray['metadata']); |
||
| 188 | // Test Metadata, and Remove date. |
||
| 189 | $originalAt = \DateTime::createFromFormat($timeFormat, $contentArray['metadata']['modificationDate']); |
||
| 190 | unset($contentArray['metadata']['modificationDate']); |
||
| 191 | unset($contentArray['metadata']['createDate']); |
||
| 192 | |||
| 193 | // PUT Lets UPDATE some additional Params |
||
| 194 | $client = $this->createClient(); |
||
| 195 | $value = new \stdClass(); |
||
| 196 | $value->name = 'aField'; |
||
| 197 | $value->value = 'aValue'; |
||
| 198 | $contentArray['metadata']['additionalProperties'] = [$value]; |
||
| 199 | sleep(1); |
||
| 200 | $client->request( |
||
| 201 | 'PUT', |
||
| 202 | $location, |
||
| 203 | [ |
||
| 204 | 'metadata' => json_encode($contentArray), |
||
| 205 | ] |
||
| 206 | ); |
||
| 207 | $response = $client->getResponse(); |
||
| 208 | $this->assertEquals(Response::HTTP_NO_CONTENT, $response->getStatusCode(), $response->getContent()); |
||
| 209 | |||
| 210 | $client = $this->createClient(); |
||
| 211 | $client->request('GET', $location, [], [], ['HTTP_ACCEPT' => 'application/json']); |
||
| 212 | |||
| 213 | $response = $client->getResponse(); |
||
| 214 | $contentUpdatedArray = json_decode($response->getContent(), true); |
||
| 215 | $modifiedAt = \DateTime::createFromFormat($timeFormat, $contentUpdatedArray['metadata']['modificationDate']); |
||
| 216 | |||
| 217 | $this->assertTrue($modifiedAt > $originalAt, 'File put should have changed modification date and did not'); |
||
|
|
|||
| 218 | |||
| 219 | // PATCH Lets patch, and time should be changed |
||
| 220 | $value->value = 'bValue'; |
||
| 221 | $patchJson = json_encode( |
||
| 222 | array( |
||
| 223 | 'op' => 'replace', |
||
| 224 | 'path' => '/metadata/additionalProperties', |
||
| 225 | 'value' => [$value] |
||
| 226 | ) |
||
| 227 | ); |
||
| 228 | sleep(1); |
||
| 229 | $client = $this->createClient(); |
||
| 230 | $client->request('PATCH', $location, array(), array(), array(), $patchJson); |
||
| 231 | $response = $client->getResponse(); |
||
| 232 | $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); |
||
| 233 | |||
| 234 | $client->request('GET', $location, [], [], ['HTTP_ACCEPT' => 'application/json']); |
||
| 235 | $response = $client->getResponse(); |
||
| 236 | $contentPatchedArray = json_decode($response->getContent(), true); |
||
| 237 | $pacthedAt = \DateTime::createFromFormat($timeFormat, $contentPatchedArray['metadata']['modificationDate']); |
||
| 238 | $this->assertTrue($pacthedAt > $modifiedAt, 'File patched should have changed modification date and did not'); |
||
| 239 | |||
| 240 | // clean up |
||
| 241 | $client = $this->createClient(); |
||
| 242 | $client->request( |
||
| 243 | 'DELETE', |
||
| 244 | $location |
||
| 245 | ); |
||
| 246 | } |
||
| 247 | |||
| 333 |