0
我有一個應用程序在Symfony 3與Web應用程序和REST API。Symfony功能測試in_memory用戶getId
我寫使用的Symfony \包\ FrameworkBundle \測試\功能測試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和form_login爲webapp的OAuth認證。 對於我的測試中,我使用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()
它沒有使用我的用戶實體進行測試,我該怎麼辦?