1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
<?php
namespace tests\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class SecurityControllerTest extends WebTestCase
{
/**
* @var Symfony\Bundle\FrameworkBundle\Client
*/
private $client = null;
public function setUp()
{
parent::setUp();
$this->client = static::createClient();
}
/**
* Test the login.
*
* @see SecurityController::login()
*/
public function testLoginPass()
{
// Make the request
$this->client->request(
'POST',
'/api/login_check',
array(
'_username' => 'username',
'_password' => 'password',
)
);
// Check the content body
$data = json_decode($this->client->getResponse()->getContent(), true);
$this->assertArrayHasKey('token', $data);
// Check the statut code
$this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
// Check if the response is successful
$this->assertTrue($this->client->getResponse()->isSuccessful());
}
} |
Partager