gpt4 book ai didi

unit-testing - Symfony 2 单元测试中的表单验证

转载 作者:行者123 更新时间:2023-12-03 00:31:29 28 4
gpt4 key购买 nike

在 Symfony 2 Cookbook 中 How to Unit Test your Forms ,页面中间有一条注释:

Don't test the validation: it is applied by a listener that is not active in the test case and it relies on validation configuration. Instead, unit test your custom constraints directly.

我希望在单元测试中打开验证,以便我可以进行测试以确保验证配置正确。

我可以在 Symfony 2 单元测试中安全地激活表单验证吗?我该怎么做?

最佳答案

我不熟悉 Symfony 2,但一般来说你应该单独测试它们:

您的表单测试将测试表单是否发布正确的值,在验证返回有效时执行正确的操作,并在验证返回无效时执行不同的操作。

您的验证测试将测试当您提供错误的电话号码时验证返回 false,或者当您提供好的电话号码时验证返回 true,等等。

关于unit-testing - Symfony 2 单元测试中的表单验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19233849/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com