In my Travis file I have several PHP versions and a script entry like this:
php:
- 5.6
- 5.5
- 5.4
- 5.3
script:
- export CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror"
- phpize #and lots of other stuff here.
- make
I want to run the export CFLAGS
line only when the PHP version matches 5.6.
I could theoretically do that with a nasty hack to detect the PHP version from the command line, but how can I do this through the Travis configuration script?
Check PHP Version 1 Open the Command Prompt or Terminal. If you have PHP installed locally, you can use the Command Prompt or Terminal to check the version. ... 2 Enter the command to check the PHP version. When you run the command, the installed version of PHP will be displayed. 3 Fix the version not appearing in Windows. See More....
Travis CI provides several PHP versions, all of which include XDebug and PHPUnit. Travis CI uses phpenv to manage the different PHP versions installed on the virtual machines. An example .travis.yml file that tests various PHP versions:
Then you can check compatibility of your code with specified PHP version using shell: find . -name *.php | xargs -n1 /usr/bin/php -l. php -l command runs PHP in syntax check only mode. The command above will check each PHP file in your project againts compatibility with PHP version located at /usr/bin/php.
Mac - Open Terminal from the Utilities folder. Linux - Open Terminal from the dash, or by pressing Ctrl + Alt + T. Enter the command to check the PHP version. When you run the command, the installed version of PHP will be displayed. Fix the version not appearing in Windows.
You can either use shell conditionals to do this:
php:
- 5.6
- 5.5
- 5.4
- 5.3
script:
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.6" ]]; then export CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror"; fi
- phpize #and lots of other stuff here.
- make
Or use the build matrix with explicit inclusions:
matrix:
include:
- php: 5.6
env: CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror"
- php: 5.5
env: CFLAGS=""
- php: 5.4
env: CFLAGS=""
- php: 5.3
env: CFLAGS=""
script:
- phpize #and lots of other stuff here.
- make
The latter is probably what you're looking for, the former is a little less verbose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With