简体   繁体   中英

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 wich 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 wich 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM