简体   繁体   English

使用Symfony2 + PHPUnit的问题

[英]Problems using Symfony2 + PHPUnit

I've finished my first "real" web-application using Symfony2. 我使用Symfony2完成了我的第一个“真正的”Web应用程序。 Until now there are no unit tests - since the project grows very fast - I need to add them to check for errors before every release. 到目前为止还没有单元测试 - 因为项目增长非常快 - 我需要添加它们以在每次发布之前检查错误。 (Currently I test everything manually) (目前我手动测试一切)

When i first use "phpunit -c app/" i get this deprecation-messages: 当我第一次使用“phpunit -c app /”时,我得到了这个弃用消息:

Remaining deprecation notices (37) 其余弃用通知(37)

Symfony\\Component\\DependencyInjection\\Definition::setFactoryMethod(createNamed) is deprecated since version 2.6 and will be removed in 3.0. Symfony \\ Component \\ DependencyInjection \\ Definition :: setFactoryMethod(createNamed)自2.6版以来不推荐使用,将在3.0中删除。 Use Definition::setFactory() instead: 4x 4x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 使用Definition :: setFactory()代替:myControllerTest中的4x 4x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

Symfony\\Component\\DependencyInjection\\Definition::setFactoryService(form.factory) is deprecated since version 2.6 and will be removed in 3.0. Symfony \\ Component \\ DependencyInjection \\ Definition :: setFactoryService(form.factory)自2.6版以来不推荐使用,将在3.0中删除。 Use Definition::setFactory() instead: 4x 4x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 使用Definition :: setFactory()代替:myControllerTest中的4x 4x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

The "pattern" option in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/routing/security.xml" is deprecated since version 2.2 and will be removed in 3.0. 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/routing/security.xml”中的“pattern”选项自版本2.2起不再使用,将在3.0中删除。 Use the "path" option in the route definition instead: 3x 3x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 改为使用路径定义中的“path”选项:myControllerTest中的3x 3x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

Twig Function "form_enctype" is deprecated. 不推荐使用Twig函数“form_enctype”。 Use "form_start" instead in FOSUserBundle:Profile:edit_content.html.twig at line 1: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 使用“form_start”代替FOSUserBundle:Profile:edit_content.html.twig at line 1:1x 1x in myControllerTest :: testMyAction from MyNamespace \\ XYZBundle \\ Tests \\ Controller

Using an instance of "Twig_Function_Method" for function "vich_uploader_asset" is deprecated since version 1.21. 从版本1.21开始,不推荐使用函数“vich_uploader_asset”的“Twig_Function_Method”实例。 Use Twig_SimpleFunction instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 使用Twig_SimpleFunction:myxtrollerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

The Twig_Function class is deprecated since version 1.12 and will be removed in 2.0. Twig_Function类自版本1.12起不推荐使用,将在2.0中删除。 Use Twig_SimpleFunction instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 使用Twig_SimpleFunction:myxtrollerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

The "scope" attribute of service "fos_user.resetting.form.handler.default" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/resetting.xml" is deprecated since version 2.8 and will be removed in 3.0: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/resetting”中服务“fos_user.resetting.form.handler.default”的“范围”属性.xml“从版本2.8开始不推荐使用,将在myControllerTest中删除3.0:1x 1x:myNamespace \\ XYZBundle \\ Tests \\ Controller中的testMyAction

The Twig_Function_Method class is deprecated since version 1.12 and will be removed in 2.0. Twig_Function_Method类自版本1.12起不推荐使用,将在2.0中删除。 Use Twig_SimpleFunction instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 使用Twig_SimpleFunction:myxtrollerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

Twig Function "form_enctype" is deprecated. 不推荐使用Twig函数“form_enctype”。 Use "form_start" instead in FOSUserBundle:Group:new_content.html.twig at line 1: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 在FOSUserBundle中使用“form_start”:第1行中的group:new_content.html.twig:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

Twig Function "form_enctype" is deprecated. 不推荐使用Twig函数“form_enctype”。 Use "form_start" instead in FOSUserBundle:Group:edit_content.html.twig at line 1: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 在FOSUserBundle中使用“form_start”:Group:edit_content.html.twig at line 1:1x 1x in myControllerTest :: testMyAction from MyNamespace \\ XYZBundle \\ Tests \\ Controller

Twig Function "form_enctype" is deprecated. 不推荐使用Twig函数“form_enctype”。 Use "form_start" instead in FOSUserBundle:Registration:register_content.html.twig at line 1: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 在FOSUserBundle中使用“form_start”:注册:第1行的register_content.html.twig:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

Twig Function "form_enctype" is deprecated. 不推荐使用Twig函数“form_enctype”。 Use "form_start" instead in FOSUserBundle:ChangePassword:changePassword_content.html.twig at line 1: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 使用“form_start”代替FOSUserBundle:ChangePassword:changePassword_content.html.twig at line 1:1x 1x in myControllerTest :: testMyAction from MyNamespace \\ XYZBundle \\ Tests \\ Controller

The "_method" requirement of route "fos_user_security_check" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/routing/security.xml" is deprecated since version 2.2 and will be removed in 3.0. 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/routing/security.xml”中路由“fos_user_security_check”的“_method”要求自版本2.2起不再使用,并且将是在3.0中删除。 Use the "methods" attribute instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 改为使用“methods”属性:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

Twig Function "form_enctype" is deprecated. 不推荐使用Twig函数“form_enctype”。 Use "form_start" instead in FOSUserBundle:Resetting:reset_content.html.twig at line 1: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 在FOSUserBundle中使用“form_start”:重置:第1行的reset_content.html.twig:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

The "factory-service" attribute of service "fos_user.resetting.form" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/resetting.xml" is deprecated since version 2.6 and will be removed in 3.0. 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/resetting.xml”中服务“fos_user.resetting.form”的“factory-service”属性“自版本2.6以来已弃用,将在3.0中删除。 Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 改为使用“factory”元素:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

The "scope" attribute of service "fos_user.change_password.form.handler.default" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/change_password.xml" is deprecated since version 2.8 and will be removed in 3.0: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/change_password”中服务“fos_user.change_password.form.handler.default”的“范围”属性.xml“从版本2.8开始不推荐使用,将在myControllerTest中删除3.0:1x 1x:myNamespace \\ XYZBundle \\ Tests \\ Controller中的testMyAction

The "factory-method" attribute of service "fos_user.profile.form" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/profile.xml" is deprecated since version 2.6 and will be removed in 3.0. 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/profile.xml”中服务“fos_user.profile.form”的“factory-method”属性“自版本2.6以来已弃用,将在3.0中删除。 Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 改为使用“factory”元素:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

The "factory-service" attribute of service "fos_user.profile.form" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/profile.xml" is deprecated since version 2.6 and will be removed in 3.0. 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/profile.xml”中服务“fos_user.profile.form”的“factory-service”属性“自版本2.6以来已弃用,将在3.0中删除。 Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 改为使用“factory”元素:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

Symfony\\Component\\DependencyInjection\\Definition::setFactoryService(doctrine) is deprecated since version 2.6 and will be removed in 3.0. Symfony \\ Component \\ DependencyInjection \\ Definition :: setFactoryService(doctrine)自2.6版以来不推荐使用,将在3.0中删除。 Use Definition::setFactory() instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 使用Definition :: setFactory()代替:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

The "factory-service" attribute of service "fos_user.entity_manager" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/orm.xml" is deprecated since version 2.6 and will be removed in 3.0. 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/orm.xml”中服务“fos_user.entity_manager”的“factory-service”属性是自2.6版以来已弃用,将在3.0中删除。 Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 改为使用“factory”元素:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

Symfony\\Component\\DependencyInjection\\Definition::setFactoryMethod(getManager) is deprecated since version 2.6 and will be removed in 3.0. Symfony \\ Component \\ DependencyInjection \\ Definition :: setFactoryMethod(getManager)自2.6版以来不推荐使用,将在3.0中删除。 Use Definition::setFactory() instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 使用Definition :: setFactory()代替:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

The "scope" attribute of service "fos_user.profile.form.handler.default" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/profile.xml" is deprecated since version 2.8 and will be removed in 3.0: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/profile”中服务“fos_user.profile.form.handler.default”的“范围”属性.xml“从版本2.8开始不推荐使用,将在myControllerTest中删除3.0:1x 1x:myNamespace \\ XYZBundle \\ Tests \\ Controller中的testMyAction

The "factory-method" attribute of service "fos_user.registration.form" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/registration.xml" is deprecated since version 2.6 and will be removed in 3.0. 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/registration.xml”中服务“fos_user.registration.form”的“factory-method”属性“自版本2.6以来已弃用,将在3.0中删除。 Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 改为使用“factory”元素:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

The "factory-service" attribute of service "fos_user.change_password.form" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/change_password.xml" is deprecated since version 2.6 and will be removed in 3.0. 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/change_password.xml”中服务“fos_user.change_password.form”的“factory-service”属性“自版本2.6以来已弃用,将在3.0中删除。 Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 改为使用“factory”元素:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

The "factory-method" attribute of service "fos_user.entity_manager" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/orm.xml" is deprecated since version 2.6 and will be removed in 3.0. 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/orm.xml”中服务“fos_user.entity_manager”的“factory-method”属性是自2.6版以来已弃用,将在3.0中删除。 Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 改为使用“factory”元素:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

The "factory-method" attribute of service "fos_user.change_password.form" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/change_password.xml" is deprecated since version 2.6 and will be removed in 3.0. 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/change_password.xml”中服务“fos_user.change_password.form”的“factory-method”属性“自版本2.6以来已弃用,将在3.0中删除。 Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 改为使用“factory”元素:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

The "scope" attribute of service "fos_user.registration.form.handler.default" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/registration.xml" is deprecated since version 2.8 and will be removed in 3.0: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/registration”中服务“fos_user.registration.form.handler.default”的“范围”属性.xml“从版本2.8开始不推荐使用,将在myControllerTest中删除3.0:1x 1x:myNamespace \\ XYZBundle \\ Tests \\ Controller中的testMyAction

The "factory-service" attribute of service "fos_user.registration.form" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/registration.xml" is deprecated since version 2.6 and will be removed in 3.0. 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/registration.xml”中服务“fos_user.registration.form”的“factory-service”属性“自版本2.6以来已弃用,将在3.0中删除。 Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 改为使用“factory”元素:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

The "factory-method" attribute of service "fos_user.resetting.form" in file "/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/resetting.xml" is deprecated since version 2.6 and will be removed in 3.0. 文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/resetting.xml”中服务“fos_user.resetting.form”的“factory-method”属性“自版本2.6以来已弃用,将在3.0中删除。 Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller 改为使用“factory”元素:myControllerTest中的1x 1x ::来自MyNamespace \\ XYZBundle \\ Tests \\ Controller的testMyAction

After the first time (cache got build) only this remains: 在第一次(缓存得到构建)之后,只剩下这个:

Remaining deprecation notices (320) 剩余的弃用通知(320)

The class "Symfony\\Bundle\\AsseticBundle\\Config\\AsseticResource" is performing resource checking through ResourceInterface::isFresh(), which is deprecated since 2.8 and will be removed in 3.0: 320x 320x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller “Symfony \\ Bundle \\ AsseticBundle \\ Config \\ AsseticResource”类正在通过ResourceInterface :: isFresh()执行资源检查,自2.8以来不推荐使用它,并将在myControllerTest中删除3.0:320x 320x :: myM空间中的testMyAction \\ XYZBundle \\ Tests \\控制器

I searched how to suppress deprecated warnings as they are from dependencies and not from my code. 我搜索了如何抑制已弃用的警告,因为它们来自依赖项,而不是来自我的代码。 I found this solution: 我发现这个解决方案:

<php>
<ini name="error_reporting" value="-16385" />
</php>      

So I added this to my phpunit.xml but it doesn't solve the problem. 所以我把它添加到我的phpunit.xml但它没有解决问题。 Hope you can help me with it! 希望你能帮帮我吧!

This summary of deprecations is shown by the Symfony PHPunit bridge. 这个弃用摘要由Symfony PHPunit桥显示。 It has a deprecations helper, that stores all deprecation notices that were triggered and show them after all tests have run. 它有一个弃用助手,它存储所有已触发的弃用通知,并在所有测试运行后显示它们。

The deprecations helper can be configured using the SYMFONY_DEPRECATIONS_HELPER env variable. 可以使用SYMFONY_DEPRECATIONS_HELPER env变量配置弃用助手。 This can have a couple different values: 这可以有几个不同的值:

  • weak - indicates that the current deprecation notices are caused by third party libraries. weak - 表示当前的弃用通知是由第三方库引起的。 It'll now only show Remaining deprecation notices (320) and the test script will return 0 (success). 它现在只显示Remaining deprecation notices (320) ,测试脚本将返回0 (成功)。
  • Any number - indicates the number of deprecation notices that are allowed. 任何数字 - 表示允许的弃用通知数。 In your case, you know that 320 deprecation notices are caused by Assetic and not your code. 在您的情况下,您知道320弃用通知是由Assetic而不是您的代码引起的。 If you set SYMFONY_DEPRECATIONS_HELPER to 320 , the build will pass as long as the number of notices is below 320. This is very usefull, as it'll warn you as soon as you introduce new deprecations. 如果将SYMFONY_DEPRECATIONS_HELPER设置为320 ,只要通知数低于320 ,构建就会通过。这非常有用,因为它会在您引入新的弃用时立即发出警告。
  • A regex - This will stop the build as soon as a deprecation was triggered that matches the regex. 正则表达式 - 只要触发与正则表达式匹配的弃用,就会停止构建。 This is usefull to debug deprecation notices. 这对于调试弃用通知很有用。

Setting the env variable can be done on the command line: 设置env变量可以在命令行上完成:

# unix
$ SYMFONY_DEPRECATIONS_HELPER=320 phpunit -c app
# windows
> set SYMFONY_DEPRECATIONS_HELPER=320
> phpunit -c app

Or in the phpunit.xml(.dist) file: 或者在phpunit.xml(.dist)文件中:

<php>
    <env name="SYMFONY_DEPRECATIONS_HELPER" value="320"/>
</php>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM