1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\KI\FoyerBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Tests\KI\CoreBundle\WebTestCase; |
6
|
|
|
|
7
|
|
|
class BeersControllerTest extends WebTestCase |
8
|
|
|
{ |
9
|
|
|
// On crée une ressource sur laquelle seront effectués les tests. |
10
|
|
|
// Ne pas oublier de supprimer à la fin avec le test DELETE. |
11
|
|
|
public function testPost() |
12
|
|
|
{ |
13
|
|
|
$this->client->request( |
14
|
|
|
'POST', '/beers', [ |
15
|
|
|
'name' => 'Test Kro', |
16
|
|
|
'price' => 1, |
17
|
|
|
'alcohol' => 1, |
18
|
|
|
'volume' => 1 |
19
|
|
|
] |
20
|
|
|
); |
21
|
|
|
$response = $this->client->getResponse(); |
22
|
|
|
$this->assertJsonResponse($response, 201); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testGet() |
26
|
|
|
{ |
27
|
|
|
$this->client->request('GET', '/beers'); |
28
|
|
|
$response = $this->client->getResponse(); |
29
|
|
|
$this->assertJsonResponse($response, 200); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testPatch() |
33
|
|
|
{ |
34
|
|
|
$this->client->request('PATCH', '/beers/test-kro', ['alcohol' => 100]); |
35
|
|
|
$response = $this->client->getResponse(); |
36
|
|
|
$this->assertJsonResponse($response, 204); |
37
|
|
|
|
38
|
|
|
$this->client->request('PATCH', '/beers/test-kro', ['alcohol' => 'blah']); |
39
|
|
|
$response = $this->client->getResponse(); |
40
|
|
|
$this->assertJsonResponse($response, 400); |
41
|
|
|
|
42
|
|
|
$this->client->request('PATCH', '/beers/test-ksdqsdqsdsdqsdsdqsro', ['alcohol' => 'blah']); |
43
|
|
|
$response = $this->client->getResponse(); |
44
|
|
|
$this->assertJsonResponse($response, 404); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
public function testDelete() |
48
|
|
|
{ |
49
|
|
|
$this->client->request('DELETE', '/beers/test-kro'); |
50
|
|
|
$response = $this->client->getResponse(); |
51
|
|
|
$this->assertJsonResponse($response, 204); |
52
|
|
|
|
53
|
|
|
$this->client->request('DELETE', '/beers/test-kro'); |
54
|
|
|
$response = $this->client->getResponse(); |
55
|
|
|
$this->assertJsonResponse($response, 404); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|