【发布时间】:2019-04-05 08:32:46
【问题描述】:
我正在将我的 Symfony 2.8 应用程序升级到 3.4,我在现有的 PHPUnit 测试中遇到了一些问题。
这是我的security.yml:
security:
firewalls:
default:
simple_preauth:
provider: fos_userbundle
authenticator: appbundle.admin.tokenauthenticator
我最近将 friendsofsymfony/user-bundle 升级到 v2.1.2 作为 Symfony 3.4 升级的一部分。
config_test.yml(用于 PHPUnit):
security:
providers:
appbundle.security.api.key_user_provider:
apiusers:
users:
server:
apikey: testUserValidRole
roles:
- 'ROLE_API_USER'
我也将 PHP 升级到 7.2,将 PHPUnit 升级到 7.4.3。
在我的测试中,我有这个:
$crawler = $client->request('POST', '/api/sso', [
'apikey' => 'testUserValidRole',
'site' => $site->getId(),
]);
$this->assertEquals(
\Symfony\Component\HttpFoundation\Response::HTTP_OK,
$client->getResponse()->getStatusCode()
);
$response = json_decode($client->getResponse()->getContent());
$this->assertTrue(isset($response->target));
$security = $client->getProfile()->getCollector('security');
// The user should only be authenticated anonymously.
$this->assertTrue($security->isAuthenticated());
$this->assertEquals(
'Symfony\Component\Security\Core\Authentication\Token\AnonymousToken',
$security->getTokenClass()
);
// Check that we can login with a valid loginToken.
// Note: A successful login will redirect and remove the loginToken.
$client->enableProfiler();
$crawler = $client->request('GET', $response->target);
// The user should be authenticated correctly.
$security = $client->getProfile()->getCollector('security');
$this->assertTrue($security->isAuthenticated());
$this->assertEquals(
'Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken',
$security->getTokenClass()
);
PreAuthenticatedToken 上的最后一个断言失败,PHPUnit 吐出错误:
断言 Symfony\Component\VarDumper\Cloner\Data 对象失败 &00000000299a8bd300000000690a732b 匹配预期 'Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken'。
完整输出在这里:https://gist.github.com/crmpicco/a927716570a4949caafec4ca1361bf63
我在 Symfony 升级说明中的安全部分看不到任何可以指出导致此错误的原因,我必须承认我现在对此有点困惑。是不是配置有误?
【问题讨论】:
-
您是否在您的 app/logs/test.log 中看到任何其他错误或弃用?
标签: php unit-testing symfony symfony-3.4 php-7.2