phpunit/phpunit-tideways-listener

TestListener for PHPUnit that can dump profile information

dev-master / 1.0.x-dev 2018-01-07 13:12 UTC

README

Test Listener for PHPUnit that uses the tideways_xhprof extension to dump memory profile information.

Installation

You can add this library as a local, per-project, development-time dependency to your project using Composer:

composer require --dev phpunit/phpunit-tideways-listener

Usage

The example below shows how you activate and configure this test listener in your PHPUnit XML configuration file:

<?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\Tideways\TestListener">
            <arguments>
                <string>/tmp</string>
            </arguments>
        </listener>
    </listeners>
</phpunit>

The following elements are relevant to this test listener and its configuration:

  • <listeners> is the configuration section for test listeners
  • <listener> configures (an instance of) the PHPUnit\Tideways\TestListener class as a test listener
  • <arguments> is the configuration for that test listener
  • The only argument is the path to the directory where the profile information for each test is to be dumped, in this example /tmp

The rest of the phpunit.xml example shown above are best practice configuration defaults that were generated using phpunit --generate-configuration.

For each test that was run there will be a .json file in the specified directory. These file contain the json_encode()d profiling data returned by the tideways_xhprof extension.