Paul Peelen
Paul Peelen

Reputation: 10329

PHPUnit test files using prefix

I need to test all classes in a range of subfolders. However, I do not want to test the other files in these subfolders until I have done a large refactoring.

The files I want to test all start with class., e.g. class.apis.php, class.something.php.

So, in order to run my tests I have the folloring configuration for PHPUnit:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="true" backupStaticAttributes="true" colors="true"
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true" convertWarningsToExceptions="true"
    processIsolation="false"
    stopOnFailure="false" syntaxCheck="true" verbose="true"
    strict="true">
    <php>
        <includePath>../</includePath>
    </php>

    <testsuites>
        <testsuite name="MSBO Test Suite">
            <directory>PHPUnit</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist addUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">../classes/</directory>
            <directory suffix=".php">../modules/</directory>
            <exclude>
                <directory>../classes/external/</directory>
            </exclude>
        </whitelist>
    </filter>
</phpunit>

But I cannot find anything on how to add a prefix to the whitelisting. Any ideas?

Upvotes: 4

Views: 2701

Answers (2)

AnhellO
AnhellO

Reputation: 1059

Pretty old thread, but just to complement the previous responses. This feature was added for PHPUnit 6.5.10. You can check the related updates at:

Also available at phpunit >v7.2 (tested on v7.5.17 and worked fine). Not sure on which specific version was added tho.

Upvotes: 0

Steven Scott
Steven Scott

Reputation: 11250

We use different extensions, instead of a prefix, so we have:

<directory suffix=".class">lib/UTIL</directory>

You might be able to use a wild card in the file name filter, although I have not tried this.

<file>lib/UTIL/AJAX*.class</file>

Upvotes: 2

Related Questions