我試圖在Travis-CI上設置php項目的集成測試。集成測試使用Behat作爲行爲驅動框架。當Apache2啓動時,環境變量沒有設置Travis-CI
我設置的數據庫連接信息作爲環境變量插入Travi-CI的存儲庫設置,我可以看到他們在執行過程中導出:
Setting environment variables from repository settings
$ export DB_USERNAME=travis
$ export DB_PASSWORD=[secure]
$ export DB_HOSTNAME=127.0.0.1
$ export DB_PORT=3306
$ export DB_NAME=oraproject_test
,但我沒能得到使用getenv()
這些值代入我的php代碼,因爲它們在apache中是未定義的。
我嘗試添加PassEnv到虛擬主機的定義,但我得到這樣的警告當Apache啓動:
[warn] PassEnv variable DB_HOSTNAME was undefined
[warn] PassEnv variable DB_PORT was undefined
[warn] PassEnv variable DB_NAME was undefined
[warn] PassEnv variable DB_USERNAME was undefined
[warn] PassEnv variable DB_PASSWORD was undefined
我配置了Apache + PHP的建議爲特拉維斯-CI文檔(http://docs.travis-ci.com/user/languages/php/#Apache-%2B-PHP),這是我travis.yml
language: php
php:
- 5.5
- 5.4
env:
- APPLICATION_ENV=acceptance
addons:
hosts:
- ora.local
install:
- composer self-update
before_script:
- sudo apt-get install apache2 libapache2-mod-fastcgi
# enable php-fpm
- sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
- sudo a2enmod rewrite actions fastcgi alias
- echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm
- sudo cp -f build/travis-ci-apache /etc/apache2/sites-available/default
- sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/default
- sudo service apache2 restart
# Set the GitHub OAuth token to make use of the 5000 per hour rate limit
- "mkdir -p ~/.composer"
- cp .travis.composer.config.json ~/.composer/config.json
- composer install -d src --dev
- mysql -e 'create database oraproject_test;'
- src/vendor/bin/doctrine-module orm:schema-tool:create
- mysql ${DB_NAME} < tests/sql/init.sql
script:
- phpunit --configuration tests/phpunit.xml
- cd tests
- ../src/vendor/bin/behat
如何告訴Apache「讀取」環境變量並讓它們可用於PHP應用程序?
非常感謝