Prev Next

Appendix B. The XML Configuration File

...

Test Suite

...

<phpunit>
  <testsuite name="My Test Suite">
    <directory>/path/to/*Test.php files</directory>
    <file>/path/to/MyTest.php</file>
  </testsuite>
</phpunit>

Groups

...

<phpunit>
  <groups>
    <include>
      <group>name</group>
    </include>
    <exclude>
      <group>name</group>
    </exclude>
  </groups>
</phpunit>

The XML configuration above corresponds to invoking the TextUI test runner with the following arguments:

  • --group name

  • --exclude-group name

Including and Excluding Files for Code Coverage

...

<phpunit>
  <filter>
    <blacklist>
      <directory suffix=".php">/path/to/files</directory>
      <file>/path/to/file</file>
      <exclude>
        <directory suffix=".php">/path/to/files</directory>
        <file>/path/to/file</file>
      </exclude>
    </blacklist>
    <whitelist>
      <directory suffix=".php">/path/to/files</directory>
      <file>/path/to/file</file>
      <exclude>
        <directory suffix=".php">/path/to/files</directory>
        <file>/path/to/file</file>
      </exclude>
    </whitelist>
  </filter>
</phpunit>

The XML configuration above corresponds to using the PHPUnit_Util_Filter class as follows:

PHPUnit_Util_Filter::addDirectoryToFilter(
  '/path/to/files', '.php'
);

PHPUnit_Util_Filter::addFileToFilter('/path/to/file');

PHPUnit_Util_Filter::removeDirectoryFromFilter(
  '/path/to/files', '.php'
);

PHPUnit_Util_Filter::removeFileFromFilter('/path/to/file');

PHPUnit_Util_Filter::addDirectoryToWhitelist(
  '/path/to/files', '.php'
);

PHPUnit_Util_Filter::addFileToWhitelist('/path/to/file');

PHPUnit_Util_Filter::removeDirectoryFromWhitelist(
  '/path/to/files', '.php'
);

PHPUnit_Util_Filter::removeFileFromWhitelist('/path/to/file');

Logging

...

<phpunit>
  <logging>
    <log type="coverage-html" target="/tmp/report" charset="UTF-8"
         yui="true" highlight="false"
         lowUpperBound="35" highLowerBound="70"/>
    <log type="coverage-xml" target="/tmp/coverage.xml"/>
    <log type="graphviz" target="/tmp/logfile.dot"/>
    <log type="json" target="/tmp/logfile.json"/>
    <log type="metrics-xml" target="/tmp/metrics.xml"/>
    <log type="plain" target="/tmp/logfile.txt"/>
    <log type="pmd-xml" target="/tmp/pmd.xml" cpdMinLines="5" cpdMinMatches="70"/>
    <log type="tap" target="/tmp/logfile.tap"/>
    <log type="test-xml" target="/tmp/logfile.xml" logIncompleteSkipped="false"/>
    <log type="testdox-html" target="/tmp/testdox.html"/>
    <log type="testdox-text" target="/tmp/testdox.txt"/>
  </logging>
</phpunit>

The XML configuration above corresponds to invoking the TextUI test runner with the following arguments:

  • --coverage-html /tmp/report

  • --coverage-xml /tmp/coverage.xml

  • --log-graphviz /tmp/logfile.dot

  • --log-json /tmp/logfile.json

  • --log-metrics /tmp/metrics.xml

  • > /tmp/logfile.txt

  • --log-pmd /tmp/pmd.xml

  • --log-tap /tmp/logfile.tap

  • --log-xml /tmp/logfile.xml

  • --testdox-html /tmp/testdox.html

  • --testdox-text /tmp/testdox.txt

PMD Rules

...

<phpunit>
  <logging>
    <pmd>
      <rule class="PHPUnit_Util_Log_PMD_Rule_Project_CRAP"
            threshold="5,30"/>
      <rule class="PHPUnit_Util_Log_PMD_Rule_Class_DepthOfInheritanceTree"
            threshold="6"/>
      <rule class="PHPUnit_Util_Log_PMD_Rule_Class_EfferentCoupling"
            threshold="20"/>
      <rule class="PHPUnit_Util_Log_PMD_Rule_Class_ExcessiveClassLength"
            threshold="1000"/>
      <rule class="PHPUnit_Util_Log_PMD_Rule_Class_ExcessivePublicCount"
            threshold="45"/>
      <rule class="PHPUnit_Util_Log_PMD_Rule_Class_TooManyFields"
            threshold="15"/>
      <rule class="PHPUnit_Util_Log_PMD_Rule_Function_CodeCoverage"
            threshold="35,70"/>
      <rule class="PHPUnit_Util_Log_PMD_Rule_Function_CRAP"
            threshold="30"/>
      <rule class="PHPUnit_Util_Log_PMD_Rule_Function_CyclomaticComplexity"
            threshold="20"/>
      <rule class="PHPUnit_Util_Log_PMD_Rule_Function_ExcessiveMethodLength"
            threshold="100"/>
      <rule class="PHPUnit_Util_Log_PMD_Rule_Function_ExcessiveParameterList"
            threshold="10"/>
      <rule class="PHPUnit_Util_Log_PMD_Rule_Function_NPathComplexity"
            threshold="200"/>
    </pmd>
  </logging>
</phpunit>

The <rule>s above correspond to the default configuration of the built-in PMD rules.

Setting PHP INI settings and Global Variables

...

<phpunit>
  <php>
    <ini name="foo" value="bar"/>
    <var name="foo" value="bar"/>
  </php>
</phpunit>

The XML configuration above corresponds to the following PHP code:

ini_set('foo', 'bar');
$GLOBALS['foo'] = 'bar';
Prev Next
1. Automating Tests
2. PHPUnit's Goals
3. Installing PHPUnit
4. Writing Tests for PHPUnit
Data Providers
Testing Exceptions
Testing PHP Errors
5. The Command-Line Test Runner
6. Fixtures
More setUp() than tearDown()
Variations
Sharing Fixture
7. Organizing Test Suites
Suite-Level Setup
8. TestCase Extensions
Testing Output
Testing Performance
9. Database Testing
Datasets
Flat XML Data Set
XML Data Set
Operations
Database Testing Best Practices
10. Incomplete and Skipped Tests
Incomplete Tests
Skipping Tests
11. Mock Objects
Self-Shunting
Stubs
12. Testing Practices
During Development
During Debugging
13. Test-First Programming
BankAccount Example
14. Code Coverage Analysis
Specifying Covered Methods
Ignoring Code Blocks
Including and Excluding Files
15. Other Uses for Tests
Agile Documentation
Cross-Team Tests
16. Logging
XML Format
Code Coverage (XML)
JavaScript Object Notation (JSON)
Test Anything Protocol (TAP)
GraphViz Markup
Test Database
17. Skeleton Generator
Annotations
18. PHPUnit and Selenium
Selenium RC
PHPUnit_Extensions_SeleniumTestCase
19. Continuous Integration
CruiseControl
phpUnderControl
Apache Maven
20. PHPUnit's Implementation
21. PHPUnit API
Overview
PHPUnit_Framework_Assert
PHPUnit_Framework_Test
PHPUnit_Framework_TestCase
PHPUnit_Framework_TestSuite
PHPUnit_Framework_TestResult
Package Structure
22. Extending PHPUnit
Subclass PHPUnit_Framework_TestCase
Assert Classes
Subclass PHPUnit_Extensions_TestDecorator
Implement PHPUnit_Framework_Test
Subclass PHPUnit_Framework_TestResult
Implement PHPUnit_Framework_TestListener
New Test Runner
A. Assertions
B. The XML Configuration File
Test Suite
Groups
Including and Excluding Files for Code Coverage
Logging
PMD Rules
Setting PHP INI settings and Global Variables
C. PHPUnit for PHP 4
D. Index
E. Bibliography
F. Copyright