4

我使用 hautelook/alice-bundle。

由于以下错误($ 解释为对对象的引用),我无法在我的夹具中使用编码的 bcrypt 密码:

在 SimpleObjectGenerator.php 第 114 行:

生成夹具“受训者”(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

你知道为什么吗?谢谢

4

3 回答 3

6

您可以将哈希密码放入参数中,如下所示:

parameters:
    hash: $2y$13$I5uLW8atzRPmC3NcvirYqO2htdMHH1l4uFQ3z0V8wHowO0FqTXl7u

App\Document\Trainee:
    trainee (template):
        password: <{hash}>
        ...
于 2019-05-21T10:47:19.817 回答
0

你必须简单地逃避每$一个\$

对于您的示例:

App\Document\Trainee:
    trainee (template):
        [...]
        password: '\$2y\$13\$I5uLW8atzRPmC3NcvirYqO2htdMHH1l4uFQ3z0V8wHowO0FqTXl7u'
于 2020-04-03T19:00:17.147 回答
-1

我建议您在测试环境中简单地设置一个明文编码器,并在您的夹具中设置明文密码。

首先,在环境中切换到明文密码编码器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
}
于 2020-08-27T21:03:25.333 回答