有人能帮我理解为什么我的环境变量没有在我的 phpunit 测试中从 travis.ci 中读取吗?
所以我正在尝试使用 travis 为我正在开发的 php/javascript 应用程序编写一些自动测试。但是,当我编写测试以检查从 travis 读取到 phpunit 的环境变量时,它们失败了。这意味着(据我所知)环境变量无法被 phpunit 读取,或者它们没有正确传递给 travis 测试。
.travis.yml
language: php
php:
- '7.0'
- '7.1'
before_install:
- echo "extension=ldap.so" >>php --ini | grep "Loaded Configuration" | sed -e "s|.:\s||"``
install:
- cd test
- npm install
- cd ..
script:
- echo $API_BASE_URL
- phpunit test/build_tests.php
notifications:
on_success: never
on_failure: never
phpunit 测试文件
<?php
use PHPUnit\Framework\TestCase;
class build_tests extends TestCase
{
public function testForEnv()
{
$this->assertEquals(isset($_ENV['API_BASE_URL']), true);
$this->assertEquals(isset($_ENV['DRINK_SERVER_URL']), true);
$this->assertEquals(isset($_ENV['LOCAL_DRINK_SERVER_URL']), true);
$this->assertEquals(isset($_ENV['RATE_LIMIT_DROPS_DROP']), true);
$this->assertEquals(isset($_ENV['DEBUG']), true);
$this->assertEquals(isset($_ENV['DEBUG_USER_UID']), true);
$this->assertEquals(isset($_ENV['DEBUG_USER_CN']), true);
$this->assertEquals(isset($_ENV['USE_LOCAL_DRINK_SERVER']), true);
}
}
?>
travis 导出环境变量
$ Setting environment variables from repository settings
$ export DRINK_SERVER_URL=https://drink.csh.rit.edu:8080
$ export LOCAL_DRINK_SERVER_URL=http://localhost:3000
$ export RATE_LIMIT_DROPS_DROP=3
$ export DEBUG=true
$ export DEBUG_USER_UID=[secure]
$ export DEBUG_USER_CN=[secure]
$ export USE_LOCAL_DRINK_SERVER=true
$ export API_BASE_URL='api/index.php?request='
phpunit 结果
PHPUnit 6.1.1 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 260 ms, Memory: 6.00MB
There was 1 failure:
1) build_tests::testForEnv
Failed asserting that true matches expected false.
/home/travis/build/devinmatte/WebDrink-2.0/test/build_tests.php:9
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
有人可以帮我理解为什么我的环境变量没有在我的 phpunit 测试中被读取吗?我真的很感激。
最佳答案
尝试使用 getenv
函数调用。在 travis 环境中,$_ENV 变量不可用
关于php - Travis.ci 环境变量不在 phpunit 中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43834568/