I was searching for a long time to test on Travis my symfony application using postgis extension.
I read the Travis documentation to enabled Postgis and my .travis.yml
was this one:
# Project language (I use php)
language: php
# To start postgresql
services:
- postgresql
php:
# aliased to a recent 7.0.x version
- 7.1
# aliased to a nightly version
- nightly
# Matrix to test in every php version
matrix:
# Fast finish allows to set the build as "finished" even if the "allow_failures" matrix elements are not finished yet.
fast_finish: true
allow_failures:
- php: nightly
# Define an environment variable
env:
- SYMFONY_VERSION="3.3.*" DB=postgresql
# Update composer
before-install:
- composer self-update
before_script:
# Testing to reinstall it
- sudo apt-get install postgresql-9.6-postgis-2.3 postgis -y -q
# Parameters are copied
- cp app/config/parameters.yml.travis app/config/parameters.yml
# Database creation
- psql -c 'create database symfony;' -U postgres
# Postgis extension creation
- psql -U postgres -c "create extension postgis" -d symfony
# - psql -c 'CREATE EXTENSION postgis_topology;' -U postgres -d symfony
# excution de composer
- composer install
# Database migration to current version
- php bin/console doctrine:migrations:migrate --no-interaction
# loading data for phpunit and codecept tests
- php bin/console doctrine:fixtures:load --fixtures ./src/AppBundle/DataFixtures -n --env=test
script:
# Tests de versions
- psql --version
- psql -d symfony -c 'SELECT PostGIS_version();' -U postgres
# Phpunit
- if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then travis_wait 40 php vendor/phpunit/phpunit/phpunit --coverage-clover build/logs/clover.xml; fi
- if [ "$TRAVIS_PHP_VERSION" != "7.1" ]; then php vendor/phpunit/phpunit/phpunit; fi
But an error occured when creating postgis extension. Error occured on this line:
$ psql -U postgres -c "create extension postgis" -d symfony
ERROR: could not access file "$libdir/postgis-2.3": No such file or directory
Best Answer
I search the web and I found Error to create postgis extension which is similar.
It seems that there is more than one Postgis version on Travis dockers and Postgis don't know which version to install. The Travis documentation is clearly incomplete. After 20 or more tries on Travis, I found the solution! I share it here.
To resolv this kind of problem on Travis environment, you should:
So I added on my travis file these lines:
Here is a link to the failing job
Here is a link to the successful job