简体   繁体   中英

How to use $_SERVER['DOCUMENT_ROOT'] with Phpunit

I am trying to set up Phpunit and across my whole project, $_SERVER['DOCUMENT_ROOT'] is used to link all files/functions/the connection etc. In my test class if I link the absolute path of my global_php_includes.php file (which is the parent file that contains more includes for everything else) then it gets an error every time $_SERVER['DOCUMENT_ROOT'] is called.

I'm very new to Phpunit, is there any way to solve this? I installed it using composer. Here is my xml file:

<?xml version="1.0" encoding="UTF-8" ?>

<phpunit bootstrap="vendor/autoload.php" colors="true" verbose="true" stopOnFailure="true">

    <testsuites>
        <testsuite name="unit">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

</phpunit>

Facing this issue, you can't do it (as far as I know).

If you launch phpunit through CLI, it's not use by the server directly, but with PHP, so you have to specify the absolute path (the same way that if you do a cron job).

I recommend you to use classes with you website to make it easier to use PHPUnit, but use absolute path for you project

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