| Conditions | 2 |
| Paths | 1 |
| Total Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 10 | public function testComments() |
||
| 11 | { |
||
| 12 | $this->client->request('GET', '/newsitems/le-jeu/comments'); |
||
| 13 | $response = $this->client->getResponse(); |
||
| 14 | $this->assertJsonResponse($response, 200); |
||
| 15 | |||
| 16 | $this->client->request('POST', '/newsitems/le-jeu/comments'); |
||
| 17 | $response = $this->client->getResponse(); |
||
| 18 | $this->assertJsonResponse($response, 400); |
||
| 19 | |||
| 20 | $this->client->request('POST', '/newsitems/le-jeu/comments', ['text' => 'J\'ai perdu.']); |
||
| 21 | $response = $this->client->getResponse(); |
||
| 22 | $this->assertJsonResponse($response, 201); |
||
| 23 | |||
| 24 | $comment = json_decode($response->getContent(), true); |
||
| 25 | |||
| 26 | $this->assertTrue(isset($comment['id']) && !empty($comment['id'])); |
||
| 27 | $id = $comment['id']; |
||
| 28 | |||
| 29 | $this->client->request('PATCH', '/comments/'.$id, ['text' => 'J\'ai perdu au Jeu.']); |
||
| 30 | $response = $this->client->getResponse(); |
||
| 31 | $this->assertJsonResponse($response, 204); |
||
| 32 | |||
| 33 | $this->client->request('PATCH', '/comments/'.$id, ['text' => '']); |
||
| 34 | $response = $this->client->getResponse(); |
||
| 35 | $this->assertJsonResponse($response, 400); |
||
| 36 | |||
| 37 | $this->client->request('PATCH', '/comments/qsdqdsq', ['text' => 'J\'ai perdu au Jeu.']); |
||
| 38 | $response = $this->client->getResponse(); |
||
| 39 | $this->assertJsonResponse($response, 404); |
||
| 40 | |||
| 41 | $this->client->request('POST', '/comments/'.$id.'/like'); |
||
| 42 | $response = $this->client->getResponse(); |
||
| 43 | $this->assertJsonResponse($response, 204); |
||
| 44 | |||
| 45 | $this->client->request('DELETE', '/comments/'.$id.'/like'); |
||
| 46 | $response = $this->client->getResponse(); |
||
| 47 | $this->assertJsonResponse($response, 204); |
||
| 48 | |||
| 49 | $this->client->request('POST', '/comments/'.$id.'/dislike'); |
||
| 50 | $response = $this->client->getResponse(); |
||
| 51 | $this->assertJsonResponse($response, 204); |
||
| 52 | |||
| 53 | $this->client->request('DELETE', '/comments/'.$id.'/dislike'); |
||
| 54 | $response = $this->client->getResponse(); |
||
| 55 | $this->assertJsonResponse($response, 204); |
||
| 56 | |||
| 57 | $this->client->request('DELETE', '/comments/'.$id, ['text' => 'J\'ai perdu au Jeu.']); |
||
| 58 | $response = $this->client->getResponse(); |
||
| 59 | $this->assertJsonResponse($response, 204); |
||
| 60 | |||
| 61 | $this->client->request('DELETE', '/comments/sqdqsdqs', ['text' => 'J\'ai perdu au Jeu.']); |
||
| 62 | $response = $this->client->getResponse(); |
||
| 63 | $this->assertJsonResponse($response, 404); |
||
| 64 | } |
||
| 65 | } |
||
| 66 |