Reputation: 61
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 ?
Upvotes: 1
Views: 1210
Reputation: 2369
It's not using my User entity for tests
This happens because the in memory provider uses the built in UserInterface
implementation. InMemoryUserProvider will never use your entity -- it's based on a whole different system than a doctrine user provider.
You have a couple of ways around this.
InMemoryUserProvider
but uses your custom entity class.Upvotes: 1