1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace tests\AppBundle\Controller\Api; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
6
|
|
|
|
7
|
|
|
class ApiDefaultControllerTest extends WebTestCase |
8
|
|
|
{ |
9
|
|
|
public function testLogin() |
10
|
|
|
{ |
11
|
|
|
exec('./bin/console d:d:c --env=test'); |
12
|
|
|
exec('./bin/console d:s:c --env=test'); |
13
|
|
|
exec('./bin/console h:f:l -n --env=test'); |
14
|
|
|
|
15
|
|
|
$client = static::createClient(); |
16
|
|
|
|
17
|
|
|
$json = '{ |
18
|
|
|
"user": { |
19
|
|
|
"email": "[email protected]", |
20
|
|
|
"password":"intern1" |
21
|
|
|
} |
22
|
|
|
}'; |
23
|
|
|
|
24
|
|
|
$client->request('POST', '/api/login', [], [], [], $json |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
28
|
|
|
|
29
|
|
|
$content = $client->getResponse()->getContent(); |
30
|
|
|
|
31
|
|
|
$arrayContent = json_decode($content, true); |
32
|
|
|
|
33
|
|
|
$token = $arrayContent['X-AUTH-TOKEN']; |
34
|
|
|
|
35
|
|
|
$headers = ['HTTP_X-AUTH-TOKEN' => $token]; |
36
|
|
|
|
37
|
|
|
$client->request('GET', '/api/user', [], [], $headers); |
38
|
|
|
|
39
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
40
|
|
|
|
41
|
|
|
$headers = ['HTTP_X-AUTH-TOKEN' => null]; |
42
|
|
|
|
43
|
|
|
$client->request('GET', '/api/user', [], [], $headers); |
44
|
|
|
|
45
|
|
|
$this->assertEquals(401, $client->getResponse()->getStatusCode()); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|