Passing parameters to PHPUnit

后端 未结 9 632
我寻月下人不归
我寻月下人不归 2020-12-24 11:03

I\'m starting to write PHPUnit tests and I\'d like the tests to be run from developers machines as well as from our servers. Developers machines are set up differently than

9条回答
  •  青春惊慌失措
    2020-12-24 11:27

    You can use PHPUnit's --bootstrap switch for this.

    --bootstrap        A "bootstrap" PHP file that is run before the tests.
    

    Then, make a bootstrap.php file that contains variables:

    $port = 4445;
    

    In your tests, you can grab those values:

    global $port;
    $this->setPort($port);
    

    Then run:

    phpunit --bootstrap boot.php MyTest.php
    

提交回复
热议问题