[英]Symfony functional test in_memory user getId
我在Symfony 3中有一個帶有Web應用程序和REST API的應用程序。
我正在使用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());
}
我有針對API的OAuth身份驗證和針對Webapp的form_login。 對於我的測試,我使用http_basic,這是我的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' ] }
在我的控制器中,我得到如下用戶:
$this->getUser()->getId()
當我啟動phpunit時,我得到
Error: Call to undefined method Symfony\Component\Security\Core\User\User::getId()
它沒有使用我的User實體進行測試,該怎么辦?
它沒有使用我的用戶實體進行測試
發生這種情況是因為內存中的提供程序使用了內置的UserInterface
實現 。 InMemoryUserProvider永遠不會使用您的實體-它基於與學說的用戶提供程序不同的系統。
您有幾種解決方法。
InMemoryUserProvider
行為但使用您的自定義實體類的自定義用戶提供程序 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.