1

.travis.yml is:

sudo: false

language: php

php:
  - 5.6
  - 7.0
  - 7.1
  - hhvm

matrix:
  allow_failures:
  - php: 7.1

before_script:
  - composer install --no-suggest ;

script:
  - if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then
      vendor/bin/phpunit --coverage-clover clover.xml ;
      vendor/bin/phpcs ;
    else
      vendor/bin/phpunit ;
    fi

after_script:
  - if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then
      vendor/bin/coveralls --coverage_clover=clover.xml -v ;
    fi  

https://lint.travis-ci.org/ no found errors and shell on travis-ci.org work fine

but https://insight.sensiolabs.com mark Critical error YAML files should not contain syntax error with:

Unable to parse at line 20 (near "    vendor/bin/phpunit --coverage-clover clover.xml ;").

How can I fix this?

Anthon
  • 69,918
  • 32
  • 186
  • 246
1f7
  • 575
  • 4
  • 11

2 Answers2

2

The PHP YAML parser is documented to parse a subset of YAML for configuration files.

It supports just the needed features to handle configuration files.

One things that is more difficult to get right, and what was left out is handling of multi-line scalar strings, the documentation even states that the much more simple to implement multi-line quoted messages (i.e. scalar strings) are not supported.

Codebeautify, who claim to be the best online YAML validator, cannot handle this correct YAML document either, with the same error, so they seem to be using the deficient PHP YAML parser as well.

If you are stuck with PHP, then you can do three things, the more readable is using literal style scalars as below (note the | after the sequence element indicator -):

sudo: false

language: php

php:
  - 5.6
  - 7.0
  - 7.1
  - hhvm

matrix:
  allow_failures:
  - php: 7.1

before_script:
  - composer install --no-suggest ;

script:
  - |
    if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then
      vendor/bin/phpunit --coverage-clover clover.xml ;
      vendor/bin/phpcs ;
    else
      vendor/bin/phpunit ;
    fi

after_script:
  - |
    if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then
      vendor/bin/coveralls --coverage_clover=clover.xml -v ;
    fi  

this however changes the strings in that the newlines are preserved.

Similar to this is the folded style scalar string, if it weren't for the indented lines, it would remove the newlines at YAML load time. So if the above doesn't work you can do:

sudo: false

language: php

php:
  - 5.6
  - 7.0
  - 7.1
  - hhvm

matrix:
  allow_failures:
  - php: 7.1

before_script:
  - composer install --no-suggest ;

script:
  - >-
    if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then
    vendor/bin/phpunit --coverage-clover clover.xml ;
    vendor/bin/phpcs ;
    else
    vendor/bin/phpunit ;
    fi

after_script:
  - >-
    if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then
    vendor/bin/coveralls --coverage_clover=clover.xml -v ;
    fi

And the final option is to rewrite the scalar strings to one line:

sudo: false

language: php

php:
  - 5.6
  - 7.0
  - 7.1
  - hhvm

matrix:
  allow_failures:
  - php: 7.1

before_script:
  - composer install --no-suggest ;

script:
  - if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then vendor/bin/phpunit --coverage-clover clover.xml ; vendor/bin/phpcs ; else vendor/bin/phpunit ; fi

after_script:
  - if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then vendor/bin/coveralls --coverage_clover=clover.xml -v ; fi

This last version and the folded style load exactly the same as your YAML source by a more complete YAML parser than the one used by PHP. The literal style loads something different, but that might still work if your application treats newlines and spaces within those scalar strings in the same way.

Anthon
  • 69,918
  • 32
  • 186
  • 246
0

Found answer, one more: use the literal scalar

sudo: false

language: php

php:
  - 5.6
  - 7.0
  - 7.1
  - hhvm

matrix:
  allow_failures:
  - php: 7.1

before_script:
  - composer install --no-suggest ;

script:
  - |
    if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then
      vendor/bin/phpunit --coverage-clover clover.xml ;
      vendor/bin/phpcs ;
    else
      vendor/bin/phpunit ;
    fi

after_script:
  - |
    if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then
      vendor/bin/coveralls --coverage_clover=clover.xml -v ;
    fi
Community
  • 1
  • 1
1f7
  • 575
  • 4
  • 11
  • That changes the scalar by introducing newlines, that might not affect the outcome in the program, but you should have indicated that. – Anthon Dec 27 '16 at 19:31
  • Had not realised this was self-answered, I guess literal style scalars work for Travis **and** Sensiolabs. – Anthon Dec 27 '16 at 19:38
  • ~@Anthon Thank you for a detailed answer! – 1f7 Dec 27 '16 at 19:39