Travis: How to configure Symfony to cooperation?

Travis & Symfony

You are happy user of the Symfony framework, and you heard something about Travis than you decide to test it. In this article, I describe how to connect popular tests’ tools (PHPUnit, phpspec, Behat) to Travis, when you have Symfony on your backend.

Before, we started configuring Symfony for supporting Travis you should know what is Continuous Integration and why that idea is very useful.

In simple words, Continuous Integration is when your code is merged with master branch and tested a few times of a day automatically. In previous ages, programmer deployed application once, maybe twice a year, now we can publish our changes in minutes to a production server, and millions of users can start using it immediately.

Check their website.
[toc]

Travis – what is it?

In open source community, Travis is the most popular tool for Continuous Integrations. There are some reasons why:

  • it’s free for open source projects,
  • integration with GitHub is extremely easy,
  • looks modern,
  • easy to configure.

You can configure it for running test application and deploy it to production, stage servers on Amazon (AWS S3) or Heroku. In this article, I will focus on configuration for automation tests.

How to use it in Symfony project

As I said, the configuration Symfony project to co-works with Travis is so easy. You have to only create one file .travis.yml which contains that code:

language: php
php:
  - '7.0'
  - '7.1'
  - nightly
install:
  - composer install --dev

As you see it is regular YAML file with three parameters.

  • language declares language that you can use.
  • php tells Travis with that version of php you want to test your app.
  • install list of commands that Travis has to run before run tests.

Assign the tests framework

Before you start you have to add that following line to your .travis.yml. There we will declare command to run particular test’s framework.

script:

Below you have lines which you need to add to .travis.yml then you want to add some test framework to Travis. Of course, you have to install each framework in your project before you configure Travis to work with it.

Behat

  - ./vendor/bin/behat

phpspec

  - ./vendor/bin/phpspec run

PHPunit

  - ./vendor/bin/phpunit

Screens behind login

Branches

Image 4 of 5

You can run Travis not only for master branch, but for each one.

Author: Marcin Pilsniak

I have been using PHP for 13 years. Furthermore, for the last 4 years I have been using AWS in my everyday work. I’m certified AWS Architect, Developer and SysOps.