【问题标题】:PHPUnit + symfony2: Excesive loggingPHPUnit + symfony2:过多的日志记录
【发布时间】:2013-11-22 12:51:29
【问题描述】:

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

每次我运行 PHP 功能测试时,我都会收到大量的日志消息,格式如下:

 [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

【问题讨论】:

    标签: php symfony ant phpunit


    【解决方案1】:

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

    【讨论】:

    • 我的 config.yml 中没有关于 Monolog 的任何内容...我不确定你的意思
    猜你喜欢
    • 2013-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    • 1970-01-01
    • 2018-12-08
    • 1970-01-01
    • 2014-01-11
    相关资源
    最近更新 更多