for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace tests\AppBundle\Controller\Api;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ApiDefaultControllerTest extends WebTestCase
{
public function testLogin()
$client = static::createClient();
$json = '{"email":"[email protected]",
"password":"intern1"}';
$client->request('POST', '/api/login', [], [], [], $json
);
$this->assertEquals(200, $client->getResponse()->getStatusCode());
$content = $client->getResponse()->getContent();
$arrayContent = json_decode($content, true);
$token = $arrayContent['X-AUTH-TOKEN'];
$headers = ['HTTP_X-AUTH-TOKEN' => $token];
$client->request('GET', '/api/user', [], [], $headers);
$headers = ['HTTP_X-AUTH-TOKEN' => null];
$this->assertEquals(401, $client->getResponse()->getStatusCode());
}