我使用hautelook/alice-bundle。
由于以下错误($ in解释为对对象的引用),我无法在我的fixture中使用编码的bcrypt密码:
在SimpleObjectGenerator.php第114行中:
生成装置"trainee“(App\Document\Trainee)时出错:在生成过程中无法解析值。
App\Document\Trainee:
# template
trainee (template):
firstName: <fr_FR:firstName()>
lastName: <fr_FR:lastName()>
email (unique): <fr_FR:email()>
password : $2y$13$I5uLW8atzRPmC3NcvirYqO2htdMHH1l4uFQ3z0V8wHowO0FqTXl7u
plainPassword: password
birthdate: <date('now')>
address: '@address_tr_*'
phoneNumber: <fr_FR:phoneNumber()>
profileCompleted: false你知道为什么吗?感恩节
发布于 2019-05-21 18:47:20
您可以将散列密码放入参数中,如下所示:
parameters:
hash: $2y$13$I5uLW8atzRPmC3NcvirYqO2htdMHH1l4uFQ3z0V8wHowO0FqTXl7u
App\Document\Trainee:
trainee (template):
password: <{hash}>
...发布于 2020-04-04 03:00:17
您必须使用\$对每个$进行简单转义
对于您的示例:
App\Document\Trainee:
trainee (template):
[...]
password: '\$2y\$13\$I5uLW8atzRPmC3NcvirYqO2htdMHH1l4uFQ3z0V8wHowO0FqTXl7u'发布于 2020-08-28 05:03:25
我建议您只需在测试环境中设置一个明文编码器,并在您的fixture中设置明文密码。
首先,在test环境下切换到明文密码编码器:
# config/packages/test/security.yaml
security:
encoders:
App\Entity\User:
algorithm: plaintext然后在你的灯具中:
App\Entity\User:
user1:
username: user1@example.com
password: 'password'现在,您可以在测试中使用明文密码:
public function testLoginWithUsernameAndPassword()
{
$response = static::createHttpClient()->request('POST', '/api/login', ['json' => [
'username' => 'user1@example.com',
'password' => 'password'
]]);
// assert $response
}https://stackoverflow.com/questions/54487000
复制相似问题