phpunit/phpunit-memprof-listener

此包已被废弃,不再维护。未建议替代包。

PHPUnit 的内存分析 TestListener,可用于导出内存分析信息

dev-master / 1.0.x-dev 2019-10-23 09:11 UTC

This package is auto-updated.

Last update: 2020-02-23 09:55:01 UTC


README

使用PHPUnitmemprof 扩展导出内存分析信息的 TestListener。

安装

您可以使用 Composer 将此库作为本地、项目特定、开发时间依赖项添加到您的项目中

composer require --dev phpunit/phpunit-memprof-listener

使用方法

以下示例展示了如何在您的 PHPUnit XML 配置文件中激活和配置此测试监听器

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.5/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         forceCoversAnnotation="true"
         beStrictAboutCoversAnnotation="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutTodoAnnotatedTests="true"
         verbose="true">
    <testsuite>
        <directory suffix="Test.php">tests</directory>
    </testsuite>

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>

    <listeners>
        <listener class="PHPUnit\MemoryProfiler\TestListener">
            <arguments>
                <string>/tmp</string>
                <string>callgrind</string>
            </arguments>
        </listener>
    </listeners>
</phpunit>

以下元素与该测试监听器和其配置相关

  • <listeners> 是测试监听器的配置部分
  • <listener>PHPUnit\MemoryProfiler\TestListener 类配置为测试监听器
  • <arguments> 是该测试监听器的配置
  • 第一个参数是要导出内存分析信息的目录路径,在这个例子中是 /tmp
  • 第二个参数是内存分析信息导出格式的期望值,在这个例子中是 callgrind(有效值有 callgrindpprof

上面所示的其余 phpunit.xml 示例是使用 phpunit --generate-configuration 生成的最佳实践配置默认值。