PHPUnit + symfony2:过度记录

时间:2013-11-22 12:51:29

标签: php symfony ant phpunit

我正在使用PHPUnit在使用symfony开发的Web应用程序上运行单元测试和功能测试。

每次我运行PHP Functional测试时,都会收到大量的日志消息,这种格式:

 [exec] [2013-11-22 12:42:05] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\TestSessionListener::onKernelRequest". [] {"uid":"58329be"}
 [exec] [2013-11-22 12:42:05] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] {"uid":"58329be"}
 [exec] [2013-11-22 12:42:05] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". [] {"uid":"58329be"}
 [exec] [2013-11-22 12:42:05] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". [] {"uid":"58329be"}

......以及其他一些堆栈跟踪,即使测试通过了。

这是我的Ant构建脚本中的目标:

<macrodef name="RunPHPUnitSuite">
    <attribute name="suite" />
    <sequential>
        <exec executable="php" failOnError="true" dir="${base.dir}">

        <arg value="C:\someDir\phpunit.phar" />

        <arg value="-c" />
        <arg value="symfony2\app" />

        <arg value="--testsuite" />
        <arg value="@{suite}" />

    </exec>
    </sequential>
</macrodef>

<target name="PHPUnitTests" depends="delete_test_reports">
    <RunPHPUnitSuite suite="UnitTests" />

    <replace file="${testReports.dir}\phpunit.xml" 
        token='testsuite name="UnitTests"' 
        value='testsuite name="PHP"' />

    <replaceregexp file="${testReports.dir}\phpunit.xml"
        match='testsuite name="(\w+\\)+'
        replace='testsuite name="'
        byline="true" />

    <replaceregexp file="${testReports.dir}\phpunit.xml"
        match='class="(\w+\\)+'
        replace='classname="PHPUnitTests.'
        byline="true" />

    <move file="${testReports.dir}\phpunit.xml" 
        tofile="${teamcityReports.dir}\php_unit_tests.xml" />
</target>

我怎样才能降低消息传递的水平?最佳输出将是我使用PHP单元测试获得的输出

 WebApp.PHPUnitTests:
      [exec] PHPUnit 3.7.19 by Sebastian Bergmann.
      [exec]
      [exec] Configuration read from C:\Work\Software\WebApp\symfony2\app\phpunit.xml.dist
      [exec]
      [exec] ...............................................................  63 / 148 ( 42%)
      [exec] ............................................................... 126 / 148 ( 85%)
      [exec] ......................
      [exec]
      [exec] Time: 2 seconds, Memory: 12.00Mb
      [exec]
      [exec] ←[30;42m←[2KOK (148 tests, 266 assertions)
      [exec] ←[0m←[2K
      [move] Moving 1 file to C:\Work\Software\TestReports\

 BUILD SUCCESSFUL
 Total time: 3 seconds

1 个答案:

答案 0 :(得分:0)

将config.yml中的日志记录的操作级别提高到“error”或“critical”会减少日志记录的数量,但是对于开发,它们可能会很有用。