首页 文章

使用Symfony2 PHPUnit的问题

提问于
浏览
3

我使用Symfony2完成了我的第一个“真正的”Web应用程序 . 到目前为止还没有单元测试 - 因为项目增长非常快 - 我需要添加它们以在每次发布之前检查错误 . (目前我手动测试一切)

当我第一次使用“phpunit -c app /”时,我得到了这个弃用消息:

剩余的弃用通知(37)Symfony \ Component \ DependencyInjection \ Definition :: setFactoryMethod(createNamed)自2.6版以来不推荐使用,将在3.0中删除 . 使用Definition :: setFactory()代替:myControllerTest中的4x 4x :: MyNamespace中的testxyAction \ XYZBundle \ Tests \ Controller Symfony \ Component \ DependencyInjection \ Definition :: setFactoryService(form.factory)自版本2.6起不再使用,将在3.0中删除 . 使用Definition :: setFactory()代替:myControllerTest中的4x 4x :: MyNamespace中的testMyAction \ XYZBundle \ Tests \ Controller文件中的“pattern”选项“/ var / www / myproject / vendor / friendsofsymfony / user-bundle / FOS / UserBundle /Resources/config/routing/security.xml“自版本2.2以来已弃用,将在3.0中删除 . 使用路径定义中的“path”选项:myxtrollerTest中的3x 3x :: MyNamespace \ XYZBundle中的testMyAction \ Tests \ Controller Twig函数“form_enctype”已弃用 . 使用“form_start”代替FOSUserBundle:Profile:edit_content.html.twig at line 1:1x 1x in myControllerTest :: testMyAction from MyNamespace \ XYZBundle \ Tests \ Controller使用“Twig_Function_Method”实例的函数“vich_uploader_asset”自版本以来不推荐使用1.21 . 使用Twig_SimpleFunction代替:MyControllerTest中的1x 1x ::来自MyNamespace \ XYZBundle \ Tests \ Controller的testMyAction Twig_Function类自1.12版以来已弃用,将在2.0中删除 . 使用Twig_SimpleFunction:myxtrollerTest中的1x 1x :: MyNamespace中的testxyAction \ XYZBundle \ Tests \ Controller文件“/ var / www / myproject / vendor / friendsofsymfony”中服务“fos_user.resetting.form.handler.default”的“scope”属性/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/resetting.xml“自版本2.8以来不推荐使用,将在myControllerTest中删除3.0:1x 1x :: myM空间中的testMyAction \ XYZBundle \ Tests \ Controller Twig_Function_Method类自版本1.12起不推荐使用,将在2.0中删除 . 使用Twig_SimpleFunction:myxtrollerTest中的1x 1x ::来自MyNamespace \ XYZBundle \ tests \ Controller的testMyAction Twig函数“form_enctype”已弃用 . 在FOSUserBundle中使用“form_start”:第1行中的group:new_content.html.twig:myControllerTest中的1x 1x :: MyNamespace中的testMyAction \ XYZBundle \ Tests \ Controller Twig函数“form_enctype”已弃用 . 在FOSUserBundle中使用“form_start”:第1行中的group:edit_content.html.twig:myControllerTest中的1x 1x :: MyNamespace中的testMyAction \ XYZBundle \ Tests \ Controller Twig函数“form_enctype”已弃用 . 在FOSUserBundle中使用“form_start”:注册:第1行中的register_content.html.twig:myControllerTest中的1x 1x ::来自MyNamespace \ XYZBundle \ tests \ Controller的测试模型Twig函数“form_enctype”已弃用 . 使用“form_start”代替FOSUserBundle:ChangePassword:changePassword_content.html.twig at line 1:1x 1x in myControllerTest :: testMyAction from MyNamespace \ XYZBundle \ Tests \ Controller“_method”要求路径“fos_user_security_check”在文件“/ var / www / myproject / vendor / friendsofsymfony / user-bundle / FOS / UserBundle / Resources / config / routing / security.xml“自版本2.2起不再使用,将在3.0中删除 . 请改为使用“methods”属性:myControllerTest中的1x 1x :: MyNamespace \ XYZBundle中的testMyAction \ Tests \ Controller Twig函数“form_enctype”已弃用 . 在FOSUserBundle中使用“form_start”:重置:第1行的reset_content.html.twig:myControllerTest中的1x 1x :: MyNamespace的测试MyM空间\ XYZBundle \ Tests \ Controller服务“fos_user.resetting.form”的“factory-service”属性文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/resetting.xml”自2.6版以来已弃用,将在3.0中删除 . 改为使用“factory”元素:myControllerTest中的1x 1x :: MyNamespace中的testMyAction \ XYZBundle \ Tests \ Controller文件中服务“fos_user.change_password.form.handler.default”的“scope”属性“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/change_password.xml”自版本2.8起不再使用,将在myControllerTest中以3.0:1x 1x删除: :来自MyNamespace \ XYZBundle \ Tests \ Controller的testMyAction文件“/ var / www / myproject / vendor / friendsofsymfony / user-bundle / FOS / UserBundle / DependencyInjection /”中服务“fos_user.profile.form”的“factory-method”属性../Resources/config/profile.xml“自版本2.6以来已弃用,将在3.0中删除 . 改为使用“factory”元素:myControllerTest中的1x 1x :: MyNamespace中的testMyAction \ XYZBundle \ Tests \ Controller文件“/ var / www / myproject / vendor”中服务“fos_user.profile.form”的“factory-service”属性/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/profile.xml“自版本2.6起不再使用,将在3.0中删除 . 改为使用“factory”元素:MyControllerTest中的1x 1x :: MyNamespace中的testxyAction \ XYZBundle \ Tests \ Controller Symfony \ Component \ DependencyInjection \ Definition :: setFactoryService(doctrine)自2.6版以来不推荐使用,将在3.0中删除 . 使用Definition :: setFactory()代替:myControllerTest中的1x 1x :: MyNamespace中的testMyAction \ XYZBundle \ Tests \ Controller文件“/ var / www / myproject / vendor /”中服务“fos_user.entity_manager”的“factory-service”属性自版本2.6以来,不推荐使用friendsofsymfony / user-bundle / FOS / UserBundle / DependencyInjection /../ Resources / config / orm.xml“,并将在3.0中删除 . 改为使用“factory”元素:myControllerTest中的1x 1x :: MyNamespace中的testxyAction \ XYZBundle \ Tests \ Controller Symfony \ Component \ DependencyInjection \ Definition :: setFactoryMethod(getManager)自2.6版以来不推荐使用,将在3.0中删除 . 使用Definition :: setFactory()代替:myControllerTest中的1x 1x :: MyNamespace中的testMyAction \ XYZBundle \ Tests \ Controller文件“/ var / www /”中服务“fos_user.profile.form.handler.default”的“scope”属性myproject / vendor / friendsofsymfony / user-bundle / FOS / UserBundle / DependencyInjection /../ Resources / config / profile.xml“从版本2.8开始不推荐使用,将在myControllerTest中删除3.0:1x 1x :: myM空间中的testMyAction \ XYZBundle \ Tests \ Controller文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config”中服务“fos_user.registration.form”的“factory-method”属性/registration.xml“自2.6版以来已弃用,将在3.0中删除 . 改为使用“factory”元素:myControllerTest中的1x 1x :: MyNamespace中的testMyAction \ XYZBundle \ Tests \ Controller文件“/ var / www / myproject / vendor”中服务“fos_user.change_password.form”的“factory-service”属性/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/change_password.xml“自版本2.6起不再使用,将在3.0中删除 . 使用“factory”元素:myxtrollerTest中的1x 1x :: MyNamespace中的testxyAction \ XYZBundle \ Tests \ Controller文件“/ var / www / myproject / vendor / friendsofsymfony”中服务“fos_user.entity_manager”的“factory-method”属性/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/orm.xml“自版本2.6起不再使用,将在3.0中删除 . 改为使用“factory”元素:myControllerTest中的1x 1x :: MyNamespace中的testMyAction \ XYZBundle \ Tests \ Controller文件“/ var / www / myproject / vendor”中服务“fos_user.change_password.form”的“factory-method”属性/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/change_password.xml“自版本2.6起不再使用,将在3.0中删除 . 改为使用“factory”元素:myControllerTest中的1x 1x :: MyNamespace中的testMyAction \ XYZBundle \ Tests \ Controller文件“/ var / www / myproject”中服务“fos_user.registration.form.handler.default”的“scope”属性/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/registration.xml“自版本2.8以来不推荐使用,将在myControllerTest中删除3.0:1x 1x :: myM空间中的testMyAction \ XYZBundle \ Tests \ Controller文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/”中服务“fos_user.registration.form”的“factory-service”属性“registration.xml”自2.6版以来已弃用,将在3.0中删除 . 请改用“factory”元素:1x 1x in来自MyNamespace \ XYZBundle \ Tests \ Controller的myControllerTest :: testMyAction文件“/ var / www / myproject / vendor / friendsofsymfony / user-bundle / FOS / UserBundle /”中服务“fos_user.resetting.form”的“factory-method”属性从版本2.6开始,不推荐使用DependencyInjection /../ Resources / config / resetting.xml,将在3.0中删除 . 改为使用“factory”元素:myControllerTest中的1x 1x ::来自MyNamespace \ XYZBundle \ Tests \ Controller的testMyAction

在第一次(缓存得到构建)之后,只剩下这个:

剩余的弃用通知(320)

“Symfony \ Bundle \ AsseticBundle \ Config \ AsseticResource”类正在通过ResourceInterface :: isFresh()执行资源检查,自2.8以来不推荐使用它,并且将在myControllerTest中删除3.0:320x 320x :: myM空间中的testMyAction \ XYZBundle \测试\控制器

我搜索了如何抑制已弃用的警告,因为它们来自依赖项,而不是来自我的代码 . 我发现这个解决方案:

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

所以我把它添加到我的phpunit.xml但它没有解决问题 . 希望你能帮帮我吧!

1 回答

  • 5

    这个弃用摘要由Symfony PHPunit桥显示 . 它有一个弃用助手,它存储所有已触发的弃用通知,并在所有测试运行后显示它们 .

    可以使用 SYMFONY_DEPRECATIONS_HELPER env变量配置弃用助手 . 这可以有几个不同的值:

    • weak - 表示当前的弃用通知是由第三方库引起的 . 它现在只显示 Remaining deprecation notices (320) ,测试脚本将返回 0 (成功) .

    • Any number - 表示允许的弃用通知数 . 在您的情况下,您知道320弃用通知是由Assetic而不是您的代码引起的 . 如果将 SYMFONY_DEPRECATIONS_HELPER 设置为 320 ,只要通知数低于320,构建就会通过 . 这非常有用,因为它会在您引入新的弃用时立即发出警告 .

    • A regex - 一旦触发与正则表达式匹配的弃用,这将停止构建 . 这对于调试弃用通知很有用 .

    设置env变量可以在命令行上完成:

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

    或者在 phpunit.xml(.dist) 文件中:

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

相关问题