简体   繁体   中英

Problems using Symfony2 + PHPUnit

I've finished my first "real" web-application using Symfony2. 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:

Remaining deprecation notices (37)

Symfony\\Component\\DependencyInjection\\Definition::setFactoryMethod(createNamed) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead: 4x 4x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

Symfony\\Component\\DependencyInjection\\Definition::setFactoryService(form.factory) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead: 4x 4x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

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. Use the "path" option in the route definition instead: 3x 3x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

Twig Function "form_enctype" is deprecated. Use "form_start" instead in 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. Use Twig_SimpleFunction instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

The Twig_Function class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

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

The Twig_Function_Method class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

Twig Function "form_enctype" is deprecated. Use "form_start" instead in FOSUserBundle:Group:new_content.html.twig at line 1: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

Twig Function "form_enctype" is deprecated. Use "form_start" instead in FOSUserBundle:Group:edit_content.html.twig at line 1: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

Twig Function "form_enctype" is deprecated. Use "form_start" instead in FOSUserBundle:Registration:register_content.html.twig at line 1: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

Twig Function "form_enctype" is deprecated. Use "form_start" instead in 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. Use the "methods" attribute instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

Twig Function "form_enctype" is deprecated. Use "form_start" instead in FOSUserBundle:Resetting:reset_content.html.twig at line 1: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

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. Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

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

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. Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

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. Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

Symfony\\Component\\DependencyInjection\\Definition::setFactoryService(doctrine) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

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. Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

Symfony\\Component\\DependencyInjection\\Definition::setFactoryMethod(getManager) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

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

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. Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

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. Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

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. Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

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. Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

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

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. Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

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. Use the "factory" element instead: 1x 1x in myControllerTest::testMyAction from MyNamespace\\XYZBundle\\Tests\\Controller

After the first time (cache got build) only this remains:

Remaining deprecation notices (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

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. Hope you can help me with it!

This summary of deprecations is shown by the Symfony PHPunit bridge. 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. This can have a couple different values:

  • weak - indicates that the current deprecation notices are caused by third party libraries. It'll now only show Remaining deprecation notices (320) and the test script will return 0 (success).
  • 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. 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.
  • 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:

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

Or in the phpunit.xml(.dist) file:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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