Search code examples
phpphpunitwhitelist

Setting up whitelists in PHPUnit


I'm running into the following problem when setting up a whitelist for PHP:

I've set the following filter in the phpunit xml:

<filter>
    <whitelist>
        <directory suffix=".php">../..</directory>
        <exclude>
            <directory>../../cache</directory>
            <directory>../../public_html</directory>
            <directory>../../temp</directory>
            <directory>../../tools</directory>
        </exclude>
    </whitelist>
</filter>

Without that whitelist, everything works fine, but when I put it, the system crashes because it tries to include all the files. That makes it include a file which has a require_once, and thus it crashes the application.

EDIT At startup the system defines some constants. Since those constants ain't defined when it includes all the data to create the whitelist, it tries to access a folder which doesn't exist (PHP assumes the constant is a string), thus the require_once fails, and given it's a require, it crashes.

Also, in case it's of any help, the whitelist is being used to use it with Selenium. Maybe that's the source of the problem?


Solution

  • Well to collect code coverage information the system kinda has to require all the files so that is expected behavior. (Technically it doesn't have to, but it does)

    If you are using require_once that should not be a problem as phpunit also uses a "_once" to require the files.

    We use whitelisting on a codebase full of require_once statements and the only issue I've run into is having a class that was defined in two places.