language: php

sudo: true

php:
- 5.6
- 7.0
- 7.1
- hhvm
- nightly

matrix:
  fast_finish: true
 
  allow_failures:
    - php: hhvm
    - php: nightly

services:
  - mysql

before_script:
  # prevent MySQL went away error
  - mysql -u root -e 'SET @@GLOBAL.wait_timeout=28800;'
  
  # Create a new database and add all priveleges
  - mysql -u root -e "create database IF NOT EXISTS chatter;"
  
  # Current DIR
  - pwd

  # Move up one directory
  - cd ../

  # Create a New Laravel App
  - composer create-project --prefer-dist laravel/laravel=5.3.* chatter-app

  # CD into the new laravel app
  - cd chatter-app

  # Include Chatter Package & Markdown package
  - composer require devdojo/chatter dev-master
  - composer require graham-campbell/markdown

  # Remove the current version
  - rm -rf vendor/devdojo/chatter

  # Move this build into the chatter folder
  - mv /home/travis/build/thedevdojo/chatter /home/travis/build/thedevdojo/chatter-app/vendor/devdojo/chatter

  # Move up one folder and rename chatter-app to chatter
  - cd ../
  - mv chatter-app chatter
  - cd chatter
  - composer dump-autoload

  # Add the database credentials
  - sed 's/DB_DATABASE=homestead/DB_DATABASE=chatter/g' .env > environment
  - sed 's/DB_USERNAME=homestead/DB_USERNAME=root/g' environment > .env
  - sed 's/DB_PASSWORD=secret/DB_PASSWORD=/g' .env > environment
  - rm .env
  - mv environment .env

  # Add the service providers
  - sed 's/App\\Providers\\RouteServiceProvider\:\:class,/App\\Providers\\RouteServiceProvider\:\:class, DevDojo\\Chatter\\ChatterServiceProvider\:\:class,/g' config/app.php > config/app-temp.php
  - rm config/app.php
  - mv config/app-temp.php config/app.php
    
  # Temponary fix for testing with another charset
  - php -r "file_put_contents('config/database.php', str_replace('utf8mb4', 'utf8', file_get_contents('config/database.php')));"
  
  # Install chatter
  - php artisan make:auth
  - php artisan vendor:publish
  - composer dump-autoload
  - php artisan migrate --verbose
  - php artisan db:seed --class=ChatterTableSeeder

  # Remove the default phpunit.xml and replace it with chatter phpunit.xml
  - rm phpunit.xml
  - cp vendor/devdojo/chatter/phpunit.xml phpunit.xml
  

script:
  # - vendor/bin/phpunit
