Validation 未验证FOS用户捆绑包的自定义字段验证

Validation 未验证FOS用户捆绑包的自定义字段验证,validation,symfony,fosuserbundle,behat,Validation,Symfony,Fosuserbundle,Behat,我是usign FOS用户包,我添加了一些自定义字段名称、姓氏、地址。。。我在下面的validation.yml配置中将这些字段标记为所需 问题是,在注册表单中,当我将这些字段留空并尝试提交表单时,我无法提交表单,因为它们具有所需的html标记和下面的minlen、maxlen属性 因此,捆绑包似乎正确地使用了配置文件 但我发现了一个问题。我正在使用behat测试应用程序,并创建了一个测试来验证帐户创建是否有效。在其中一个场景中,我故意将姓名留空,以便看到错误消息。问题是表单被发送是因为mink

我是usign FOS用户包,我添加了一些自定义字段名称、姓氏、地址。。。我在下面的validation.yml配置中将这些字段标记为所需

问题是,在注册表单中,当我将这些字段留空并尝试提交表单时,我无法提交表单,因为它们具有所需的html标记和下面的minlen、maxlen属性

因此,捆绑包似乎正确地使用了配置文件

但我发现了一个问题。我正在使用behat测试应用程序,并创建了一个测试来验证帐户创建是否有效。在其中一个场景中,我故意将姓名留空,以便看到错误消息。问题是表单被发送是因为mink不关心html验证,并且name和姓氏中的空值不被验证。所有操作都以数据库异常结束,试图在必填字段中为空值插入空值:

An exception occurred while executing 'INSERT INTO user (username, username_canonical, email, email_canonical, enabled, salt, password, last_login, locked, expired, expires_at, confirmation_token, password_requested_at, roles, credentials_expired, credentials_expire_at, name, surname, company, address) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["test@dirital.com", "test@dirital.com", "test@dirital.com", "test@dirital.com", 0, "3njo6hthk8ao040okco08wggk4sk4wk", "namJcPop4lXUwAK4OQXIzRsfKYurv9K+XdvVMTZ4CSEvMf+bLTl4oYTFSKExMI1ROj557mjR89ltnj6L0ETBXA==", null, 0, 0, null, "o7V72h5PK12VlAZBAVH8QSK6PPsOYL9--iVEUTKE8XQ", null, "a:0:{}", 0, null, null, null, null, null]:
  │
  │ SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: user.name 
我有另一个测试,我测试,如果我留下空白的电子邮件和密码,我应该得到一个错误消息,这些工作正常

因此,在验证中,我的配置似乎有问题,或者类似的问题,但我无法确定

validation.yml

UserBundle\Entity\User:
properties:
    name:
        - NotBlank:
            message: fos_user.field.blank
            groups: [ "UserRegistration", "UserProfile" ]
        - Length:
            min: 2
            minMessage: fos_user.field.short
            max: 100
            maxMessage: fos_user.field.long
            groups: [ "UserRegistration", "ResetPassword" ]
    surname:
        - NotBlank:
            message: fos_user.field.blank
            groups: [ "UserRegistration", "DiritalUserProfile" ]
        - Length:
            min: 2
            minMessage: fos_user.field.short
            max: 100
            maxMessage: fos_user.field.long
            groups: [ "UserRegistration", "ResetPassword" ]
表单中生成的HTML验证代码 名称


非常感谢每一位可能阅读过这一长期问题的人。要检查的内容包括:验证文件是否在正确的目录中?这可能与验证组有关吗?@CarlosGranados验证文件位于config文件夹中的my custom UserBundle中。我猜验证加载正确,因为验证已添加到html中的输入字段中
</div>

<div class="form-group">
    <label class="control-label required" for="fos_user_registration_form_surname">Surname</label>
    <input type="text" id="fos_user_registration_form_surname" name="fos_user_registration_form[surname]" required="required" maxlength="100" pattern=".{2,}" class="form-control" />

</div>
Scenario: When the user doesn't fill all the fields of the form error messages should appear
Given I am on "/create-account/"
When I press "Send"
# This works
Then I should see "The email is required to create your account"
When I fill in "Email" with "test@domain.com"
And I press "Send"
# This works as well, only the password error shown, the email field has been filled
Then I should not see "Please fill in the email"
And I should see "Please fill in the password"
When I fill in "Password" with "12345"
And I press "Send"
# This also works, different passwords should not be sent
Then I should see "The entered passwords don't match"
When I fill in "Password" with "12345"
And I fill in "Repeat password" with "12345"
And I press "Send"
# And there is where I get the exception instead the error message for not filling the name, surname fields
And print last response without tags