Skip to content

Commit

Permalink
增加自动化测试脚本。
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Jul 3, 2017
1 parent 70bb782 commit c512412
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
35 changes: 35 additions & 0 deletions .travis.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

$db = $argv[1] ?? 'mysql';
$connection = [];
switch ($db) {
case 'pgsql':
$connection = [
'DB_CONNECTION' => 'pgsql',
'DB_HOST' => '127.0.0.1',
'DB_PORT' => '5432',
'DB_DATABASE' => 'plus',
'DB_USERNAME' => 'postgres',
'DB_PASSWORD' => 'postgres',
];
break;

case 'mysql':
default:
$connection = [
'DB_CONNECTION' => 'mysql',
'DB_HOST' => '127.0.0.1',
'DB_PORT' => '3306',
'DB_DATABASE' => 'plus',
'DB_USERNAME' => 'root',
'DB_PASSWORD' => '',
];
break;
}

$env = file_get_contents(__DIR__.'/.env.example');
foreach ($connection as $key => $value) {
$env = preg_replace("/{$key}=(.*)?/i", "{$key}={$value}", $env);
}

file_put_contents(__DIR__.'/.env.travis', $env);
16 changes: 15 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
sudo: false

language: php

php:
- 7.0
- 7.1

env:
- DB=mysql
- DB=postgres

services:
- postgresql
- mysql

before_install:
- psql -c 'create database travis_ci_test;' -U postgres
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'create database plus;' -U postgres
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE IF NOT EXISTS plus;'
- sh -c "php ./.travis.php "$DB""
- php -r "file_exists('.env') || copy('.env.travis', '.env');"

install:
- composer install
- php artisan key:generate

script:
- php artisan migrate
- php artisan db:seed
- php artisan vendor:publish --force
- php vendor/bin/phpunit --coverage-clover=./storage/logs/coverage.xml

after_script:
- php vendor/bin/codacycoverage clover ./storage/logs/coverage.xml

0 comments on commit c512412

Please sign in to comment.