xtremer360
1 year ago

TravisCI Build DB Connection Times Out

Posted 1 year ago by xtremer360

I'm trying to figure out why when I run my CI Build it says that my connection to the database times out. My database is created because my migrations run completely but when it gets to my test suite then it loses connection.

The command "php artisan key:generate" exited with 0.
31.27s$ vendor/bin/phpunit
PHPUnit Pretty Result Printer 0.19.14 by Codedungeon and contributors.
==> Configuration:~/build/me/app/vendor/codedungeon/phpunit-result-printer/phpunit-printer.yml
PHPUnit 7.3.5 by Sebastian Bergmann and contributors.
 ==> Tests\Feature\Module\MyTest⚈
Time: 31.12 seconds, Memory: 24.00MB
There was 1 error:
1) Tests\Feature\Module\Test::my_test_method
Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] Connection timed out (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

Caused by
Doctrine\DBAL\Driver\PDOException: SQLSTATE[HY000] [2002] Connection timed out

.env.travis

APP_ENV=testing
APP_KEY=
APP_DEBUG=true

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=my_database_name
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync

.travis.yml

language: php

php:
  - 7.1

services:
  - mysql  

before_script:
  - cp .env.travis .env
  - mysql -e 'CREATE DATABASE my_database_name;'
  - composer self-update
  - composer install --no-interaction
  - php artisan key:generate
  - php artisan migrate 

script:
  - vendor/bin/phpunit

cache:
  directories:
    - vendor

Please sign in or create an account to participate in this conversation.