-
-
Save gilbitron/5cac0ac5fa07e9b354ac to your computer and use it in GitHub Desktop.
APP_ENV=testing | |
APP_KEY=SomeRandomString | |
DB_CONNECTION=testing | |
DB_TEST_USERNAME=root | |
DB_TEST_PASSWORD= | |
CACHE_DRIVER=array | |
SESSION_DRIVER=array | |
QUEUE_DRIVER=sync |
language: php | |
php: | |
- 5.6 | |
before_script: | |
- cp .env.travis .env | |
- mysql -e 'create database homestead_test;' | |
- composer self-update | |
- composer install --no-interaction | |
script: | |
- vendor/bin/phpunit |
<?php | |
return [ | |
//... | |
'default' => env('DB_CONNECTION', 'mysql'), | |
//... | |
'connections' => [ | |
'mysql' => [ | |
'driver' => 'mysql', | |
'host' => env('DB_HOST', 'localhost'), | |
'database' => env('DB_DATABASE', 'homestead'), | |
'username' => env('DB_USERNAME', 'homestead'), | |
'password' => env('DB_PASSWORD', 'secret'), | |
'charset' => 'utf8', | |
'collation' => 'utf8_unicode_ci', | |
'prefix' => '', | |
'strict' => false, | |
], | |
'testing' => [ | |
'driver' => 'mysql', | |
'host' => env('DB_TEST_HOST', 'localhost'), | |
'database' => env('DB_TEST_DATABASE', 'homestead_test'), | |
'username' => env('DB_TEST_USERNAME', 'homestead'), | |
'password' => env('DB_TEST_PASSWORD', 'secret'), | |
'charset' => 'utf8', | |
'collation' => 'utf8_unicode_ci', | |
'prefix' => '', | |
'strict' => false, | |
], | |
], | |
//... | |
]; |
<?xml version="1.0" encoding="UTF-8"?> | |
<phpunit backupGlobals="false" | |
backupStaticAttributes="false" | |
bootstrap="bootstrap/autoload.php" | |
colors="true" | |
convertErrorsToExceptions="true" | |
convertNoticesToExceptions="true" | |
convertWarningsToExceptions="true" | |
processIsolation="false" | |
stopOnFailure="false" | |
syntaxCheck="false"> | |
<testsuites> | |
<testsuite name="Application Test Suite"> | |
<directory>./tests/</directory> | |
</testsuite> | |
</testsuites> | |
<filter> | |
<whitelist> | |
<directory suffix=".php">app/</directory> | |
</whitelist> | |
</filter> | |
<php> | |
<env name="APP_ENV" value="testing"/> | |
<env name="DB_CONNECTION" value="testing"/> | |
<env name="CACHE_DRIVER" value="array"/> | |
<env name="SESSION_DRIVER" value="array"/> | |
<env name="QUEUE_DRIVER" value="sync"/> | |
</php> | |
</phpunit> |
Cool 👍
Just saved my day, bro.
I just had to add to more lines on my .travis.yml to get it to work properly. Since I'm new to Laravel and Travis, can't say if I'm crossing a line placing those additional commands.
👍
https://github.com/nilohouse/code-club-matching/blob/master/.travis.yml
you should add key generate
- php artisan key:generate
I've amended this a little to handle automated builds... thought I'd share back as you provided the basis for it.
- Stop using xdebug
- Install correct Node Version
- Auto migrate DB
- Gulp all assets
- Execute PHPUnit
- Cache resources for speedy runs
Travis YML
language: php
php:
- 7.0
before_script:
- phpenv config-rm xdebug.ini
- cp .env.travis .env
- composer self-update
- composer install --no-interaction
- php artisan key:generate
- php artisan migrate
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION
- npm install --global gulp-cli
- npm install
- gulp --production
before_install:
- mysql -e 'CREATE DATABASE travis;'
script:
- phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml
services:
- mysql
cache:
directories:
- node_modules
- vendor
env:
- TRAVIS_NODE_VERSION="4"
@Rexeh does laravel necessarily use gulp?
Laravel 5.4 no longer does
Worked like a charm with a little modification, thanks!
.travis.yml
language: php
php:
- 7.0
before_script:
- cp .env.travis .env
- composer self-update
- composer install --no-interaction
script:
- php artisan key:generate
- vendor/bin/phpunit
.env.travis
APP_ENV=testing
APP_KEY=SomeRandomString
DB_CONNECTION=testing
DB_TEST_USERNAME=root
DB_TEST_PASSWORD=
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
beStrictAboutCoversAnnotation="true">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
Laravel 5.5
Error:
Cannot open file "{project_name}/bootstrap/autoload.php".
Why?
In Laravel 5.5 autoload remove. Now vendor/autoload.php
@gilbitron update gist. U can check my gist
@isneezy Why do you have db stuff in env you are using in memory db theres no need?
Thank you very much!
I had to make some changes to make it work:
language: php
php:
- 7.2.1
addons:
mariadb: '10.1'
before_script:
- cp .env.travis .env
- mysql -e 'create database homestead_test;'
- composer self-update
- composer install --no-interaction
- rm vendor/nzesalem/lastus/src/migrations/2017_10_18_124315_add_status_field_to_users_table.php
- php artisan key:generate
- php artisan migrate --step
script:
- vendor/bin/phpunit
Has anyone been able to get this to work with Laravel 5.8?
I keep getting this error:
$ mysql -e 'create database homestead_test;'
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
The command "mysql -e 'create database homestead_test;'" failed and exited with 1 during .
@DubStepMad I add
services:
- mysql
This is my complete script:
language: php
dist: bionic
php:
- 7.3
services:
- mysql
before_script:
- cp .env.travis .env
- mysql -e 'create database homestead_test;'
- composer self-update
- composer install --no-interaction
- php artisan key:generate
- php artisan migrate
script:
- vendor/bin/phpunit
I'm using SQLite as service may you show me how my .travis.yml should look like ?
It's awesome... I will try it right now...