Added env function, added GitLab CI code coverage config

This commit is contained in:
Igor Scheller 2017-09-25 00:03:22 +02:00
parent c5c0a602aa
commit 449e2cdd00
4 changed files with 80 additions and 4 deletions

47
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,47 @@
image: php
cache:
paths:
- .composer
services:
- mysql:5.6
variables:
MYSQL_DATABASE: engelsystem
MYSQL_USER: engel
MYSQL_PASSWORD: engelsystem
COMPOSER_HOME: .composer
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
before_script:
# Install required Packages
- apt-get update -yqq
- apt-get install -yqq git unzip mysql-client
- docker-php-ext-install pdo pdo_mysql gettext
# Install xdebug
- pecl install xdebug
- docker-php-ext-enable xdebug
# MySQL DB
- mysql -h mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" < db/install.sql
- mysql -h mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" < db/update.sql
# Install Composer
- curl -sS https://getcomposer.org/installer | php -- --no-ansi --install-dir /usr/local/bin/ --filename composer
- /usr/local/bin/composer --no-ansi install
.test_template: &test_definition
artifacts:
name: "${CI_JOB_NAME}_${CI_PROJECT_ID}_${PHP_VERSION}"
expire_in: 1 week
paths:
- ./coverage/
coverage: '/^\s*Lines:\s*(\d+(?:\.\d+)?%)/'
script: vendor/bin/phpunit --colors=never --coverage-text --coverage-html ./coverage/
test:7.0:
image: php:7.0
<<: *test_definition
test:7.1:
image: php:7.1
<<: *test_definition

View File

@ -5,10 +5,10 @@
return [
// MySQL-Connection Settings
'database' => [
'host' => 'localhost',
'user' => 'root',
'pw' => '',
'db' => 'engelsystem',
'host' => env('MYSQL_HOST', (env('CI', false) ? 'mysql' : 'localhost')),
'user' => env('MYSQL_USER', 'root'),
'pw' => env('MYSQL_PASSWORD', ''),
'db' => env('MYSQL_DATABASE', 'engelsystem'),
],
// For accessing stats

View File

@ -64,6 +64,21 @@ function config_path($path = '')
return app('path.config') . (empty($path) ? '' : DIRECTORY_SEPARATOR . $path);
}
/**
* @param string $key
* @param mixed $default
* @return mixed
*/
function env($key, $default = null)
{
$value = getenv($key);
if ($value === false) {
return $default;
}
return $value;
}
/**
* @param string $key
* @param mixed $default

View File

@ -53,6 +53,20 @@ class HelpersTest extends TestCase
$this->assertEquals(['user' => 'FooBar'], config('mail'));
}
/**
* @covers \env
*/
public function testEnv()
{
putenv('envTestVar=someContent');
$env = env('envTestVar');
$this->assertEquals('someContent', $env);
$env = env('someRandomEnvVarThatShouldNeverExist', 'someDefaultValue');
$this->assertEquals('someDefaultValue', $env);
}
/**
* @covers \request
*/