How to set $_SERVER[' '] variables when running phpunit tests through Jenkins

后端 未结 1 756
梦谈多话
梦谈多话 2021-02-04 08:26

I am trying to write unit tests for an application where a lot of code changes is not possible. Almost all the .php files in the code base uses some $_SERVER[\'\'] variables lik

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-04 09:22

    I'm not sure about #1, but PHPUnit itself would have to support it. I don't see any way to do that via the command line. However, if you put your current workaround into bootstrap.php you don't have to do it in each test.

    For #2, allows you to set environment variables using nested elements. I use this in Jenkins.

    
        
    
    

    Update: You typically create bootstrap.php to setup add the source directory to the include path and initialize the test environment however you need. This file isn't supplied by PHPUnit--unlike phpunit.xml.

    I place it in the same directory as phpunit.xml, but that's because I have a separate file for each project. It goes in the directory that holds your tests typically. This allows you to run phpunit from the command-line without telling it how to find those configuration files. Otherwise you have to use --bootstrap and/or --configuration to point to them.

    Here is how I structure a typical project:

    /
        build.xml
        src/
            MyClass.php
        test/
            MyClassTest.php
            phpunit.xml
            bootstrap.php
    

    0 讨论(0)
提交回复
热议问题