3

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

当我第一次使用“phpunit -c app/”时,我收到了以下弃用消息:

剩余的弃用通知 (37)

Symfony\Component\DependencyInjection\Definition::setFactoryMethod(createNamed) 自 2.6 版起已弃用,并将在 3.0 版中删除。使用 Definition::setFactory() 代替: 4x 4x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

Symfony\Component\DependencyInjection\Definition::setFactoryService(form.factory) 自 2.6 版以来已弃用,并将在 3.0 中删除。使用 Definition::setFactory() 代替: 4x 4x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/routing/security.xml”中的“模式”选项自 2.2 版起已弃用,并将在 3.0 版中删除。改用路由定义中的“路径”选项: 3x 3x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

不推荐使用 Twig 函数“form_enctype”。在第 1 行的 FOSUserBundle:Profile:edit_content.html.twig 中使用“form_start”:1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

自 1.21 版起,不推荐使用函数“vich_uploader_asset”的“Twig_Function_Method”实例。改用 Twig_SimpleFunction:1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

Twig_Function 类自 1.12 版起已弃用,并将在 2.0 版中删除。改用 Twig_SimpleFunction: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 版以来已弃用,并将在 3.0 中删除: 1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

Twig_Function_Method 类自 1.12 版以来已弃用,并将在 2.0 中删除。改用 Twig_SimpleFunction:1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

不推荐使用 Twig 函数“form_enctype”。在第 1 行的 FOSUserBundle:Group:new_content.html.twig 中使用“form_start”:1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

不推荐使用 Twig 函数“form_enctype”。在第 1 行的 FOSUserBundle:Group:edit_content.html.twig 中使用“form_start”:MyNamespace\XYZBundle\Tests\Controller 的 myControllerTest::testMyAction 中的 1x 1x

不推荐使用 Twig 函数“form_enctype”。在第 1 行的 FOSUserBundle:Registration:register_content.html.twig 中使用“form_start”:1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

不推荐使用 Twig 函数“form_enctype”。在第 1 行的 FOSUserBundle:ChangePassword:changePassword_content.html.twig 中使用“form_start”:1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/routing/security.xml”中路由“fos_user_security_check”的“_method”要求自2.2版起已弃用,并将在 3.0 中删除。改用“methods”属性:1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

不推荐使用 Twig 函数“form_enctype”。在第 1 行的 FOSUserBundle:Resetting:reset_content.html.twig 中使用“form_start”:1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/resetting.xml”中服务“fos_user.resetting.form”的“factory-service”属性" 自 2.6 版以来已弃用,并将在 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 版以来已弃用,并将在 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.xml”中服务“fos_user.profile.form”的“工厂方法”属性" 自 2.6 版以来已弃用,并将在 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.xml”中服务“fos_user.profile.form”的“factory-service”属性" 自 2.6 版以来已弃用,并将在 3.0 中删除。改用“工厂”元素:1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

Symfony\Component\DependencyInjection\Definition::setFactoryService(doctrine) 自 2.6 版起已弃用,并将在 3.0 版中删除。使用 Definition::setFactory() 代替: 1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/orm.xml”中服务“fos_user.entity_manager”的“factory-service”属性是自 2.6 版起已弃用,并将在 3.0 版中删除。改用“工厂”元素:1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

Symfony\Component\DependencyInjection\Definition::setFactoryMethod(getManager) 自 2.6 版起已弃用,并将在 3.0 版中删除。使用 Definition::setFactory() 代替: 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 版以来已弃用,并将在 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.xml”中服务“fos_user.registration.form”的“工厂方法”属性" 自 2.6 版以来已弃用,并将在 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.xml”中服务“fos_user.change_password.form”的“factory-service”属性" 自 2.6 版以来已弃用,并将在 3.0 中删除。改用“工厂”元素:1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

文件“/var/www/myproject/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/../Resources/config/orm.xml”中服务“fos_user.entity_manager”的“工厂方法”属性是自 2.6 版起已弃用,并将在 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.xml”中服务“fos_user.change_password.form”的“工厂方法”属性" 自 2.6 版以来已弃用,并将在 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 版以来已弃用,并将在 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.xml”中服务“fos_user.registration.form”的“factory-service”属性" 自 2.6 版以来已弃用,并将在 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.xml”中服务“fos_user.resetting.form”的“工厂方法”属性" 自 2.6 版以来已弃用,并将在 3.0 中删除。改用“工厂”元素:1x 1x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests\Controller

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

剩余的弃用通知 (320)

“Symfony\Bundle\AsseticBundle\Config\AsseticResource”类正在通过 ResourceInterface::isFresh() 执行资源检查,自 2.8 起已弃用,并将在 3.0 中删除:320x 320x in myControllerTest::testMyAction from MyNamespace\XYZBundle\Tests \控制器

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

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

所以我将它添加到我的 phpunit.xml 中,但它并没有解决问题。希望你能帮助我!

4

1 回答 1

5

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

可以使用SYMFONY_DEPRECATIONS_HELPERenv 变量配置 deprecations 帮助程序。这可以有几个不同的值:

  • weak- 表示当前的弃用通知是由第三方库引起的。它现在只会显示Remaining deprecation notices (320)并且测试脚本将返回0(成功)。
  • 任何数字- 表示允许的弃用通知的数量。就您而言,您知道 320 条弃用通知是由 Assetic 而不是您的代码引起的。如果您设置SYMFONY_DEPRECATIONS_HELPER320,只要通知数低于 320,构建就会通过。这非常有用,因为它会在您引入新的弃用时立即警告您。
  • 正则表达式- 一旦触发与正则表达式匹配的弃用,这将停止构建。这对于调试弃用通知很有用。

可以在命令行上设置 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>
于 2016-02-13T09:56:58.587 回答