I have an application in Symfony 3 with web app and a REST API.
I am writing a functional test using Symfony\Bundle\FrameworkBundle\Test\WebTestCase
$this->client = static::createClient(array(), array(
'PHP_AUTH_USER' => 'test',
'PHP_AUTH_PW' => 'test',
));
public function testIndex()
{
$this->client->request(
'GET',
'/titles'
);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
I have OAuth authentication for the API and form_login for webapp. For my tests, I use http_basic, here's my config_test.yml:
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
firewalls:
api:
http_basic: ~
main:
http_basic: ~
providers:
in_memory:
memory:
users:
test: { password: test, roles: [ 'ROLE_USER' ] }
In my controller, I get User like this:
$this->getUser()->getId()
When I launch phpunit, I get
Error: Call to undefined method Symfony\Component\Security\Core\User\User::getId()
It's not using my User entity for tests, how do I do ?