Added Core::getEnv, allowing the developer to load environment variables using a default fallback.
This commit is contained in:
parent
d4bf138533
commit
eec9eda22d
19
.drone.yml
Normal file
19
.drone.yml
Normal file
@ -0,0 +1,19 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: test
|
||||
|
||||
steps:
|
||||
- name: composer
|
||||
image: composer:latest
|
||||
commands:
|
||||
- composer install
|
||||
|
||||
- name: phpunit
|
||||
image: phpunit:7.3
|
||||
commands:
|
||||
- vendor/bin/phpunit -c test/phpunit.xml
|
||||
|
||||
- name: coverage
|
||||
image: phpunit:7.3
|
||||
commands:
|
||||
- vendor/bin/phpunit -c test/phpunit.xml --coverage-text
|
@ -1,82 +0,0 @@
|
||||
before_script:
|
||||
# Install dependencies
|
||||
- set -xe
|
||||
- apt-get update -yqq
|
||||
- apt-get install git zip unzip -yqq
|
||||
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
- deploy
|
||||
|
||||
build:composer:
|
||||
image: php:7.2
|
||||
stage: build
|
||||
script:
|
||||
- curl -sS https://getcomposer.org/installer | php
|
||||
- php composer.phar install
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
||||
|
||||
test:7.1:
|
||||
stage: test
|
||||
image: php:7.1
|
||||
script:
|
||||
- vendor/bin/phpunit -c test/phpunit.xml
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor
|
||||
|
||||
test:7.2:
|
||||
stage: test
|
||||
image: php:7.2
|
||||
script:
|
||||
- vendor/bin/phpunit -c test/phpunit.xml
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
||||
|
||||
test:7.3:
|
||||
stage: test
|
||||
image: php:7.3
|
||||
script:
|
||||
- vendor/bin/phpunit -c test/phpunit.xml
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
||||
|
||||
test:coverage:
|
||||
stage: test
|
||||
image: php:7.2
|
||||
script:
|
||||
- pecl install xdebug
|
||||
- docker-php-ext-enable xdebug
|
||||
- vendor/bin/phpunit -c test/phpunit.xml --coverage-text
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
||||
|
||||
release:
|
||||
stage: deploy
|
||||
image: php:7.2
|
||||
only:
|
||||
- master
|
||||
script:
|
||||
- pecl install xdebug
|
||||
- docker-php-ext-enable xdebug
|
||||
- vendor/bin/phpunit -c test/phpunit.xml --coverage-text
|
||||
artifacts:
|
||||
name: "${CI_BUILD_NAME}_${CI_BUILD_REF_NAME}"
|
||||
paths:
|
||||
- build/
|
||||
expire_in: 3 weeks
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
12
.travis.yml
12
.travis.yml
@ -1,12 +0,0 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
|
||||
script:
|
||||
- php vendor/bin/phpunit -v -c test/phpunit.xml --coverage-text
|
||||
|
||||
before_script:
|
||||
- composer install
|
@ -148,6 +148,26 @@ class Core
|
||||
Logger::stopLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a variable name from the php environment, while also providing a fallback variable
|
||||
*
|
||||
* @param string $varName
|
||||
* @param string|null $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getEnv(string $varName, string $default = null)
|
||||
{
|
||||
// First retrieve the environment variable
|
||||
$var = getenv($varName);
|
||||
|
||||
// If the environment variable doesn't exist, use the default one
|
||||
if ($var === FALSE)
|
||||
return $default;
|
||||
|
||||
// Otherwise return the variable itself
|
||||
return $var;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the current running version of PHP is equal to the input string.
|
||||
*
|
||||
|
@ -71,5 +71,21 @@ class coreTest extends CoreTestAbstract
|
||||
{
|
||||
$this->assertTrue(Core::isPHP('1.2.0'));
|
||||
$this->assertFalse(Core::isphp('9999.9.9'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getEnv
|
||||
*/
|
||||
public function testGetEnv()
|
||||
{
|
||||
// First push some test variables
|
||||
putenv('TESTGETENV=AFFIRMED');
|
||||
|
||||
// Then try and fetch using the method
|
||||
$this->assertEquals('AFFIRMED', Core::getEnv('TESTGETENV'));
|
||||
|
||||
// Also test variables that don't exist
|
||||
$this->assertNull(Core::getEnv('TESTNOTEXIST'));
|
||||
$this->assertEquals('replacement', Core::getEnv('TESTNOTEXISTTWO', 'replacement'));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user