diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 74a330c..27f1f68 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -6,19 +6,19 @@ on:
- '*'
push:
branches:
- - master
+ - '*'
permissions:
contents: read
jobs:
- test:
+ coding-standard:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
- php-version: ['7.2', '7.4', '8.0', '8.1', '8.2']
- name: Test PHP ${{ matrix.php-version }}
+ php-version: ['5.5', '5.6', '7.1', '7.2', '7.4', '8.0', '8.1', '8.2']
+ name: Coding Standard ${{ matrix.php-version }}
steps:
- uses: actions/checkout@v3
@@ -33,16 +33,16 @@ jobs:
- name: Composer install
run: composer install
- - name: Run PHPUnit
- run: composer run-script test
-
- coverage-php:
+ - name: Run PHP CodeSniffer
+ run: composer run-script cs-check
+
+ test:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
- php-version: ['7.2', '7.4', '8.0', '8.1', '8.2']
- name: Coverage PHP ${{ matrix.php-version }}
+ php-version: ['5.5', '5.6', '7.1', '7.2', '7.4', '8.0', '8.1', '8.2']
+ name: Test PHP ${{ matrix.php-version }}
steps:
- uses: actions/checkout@v3
@@ -52,28 +52,21 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- coverage: pcov
+ coverage: none
- name: Composer install
run: composer install
- name: Run PHPUnit
- run: composer run-script coverage-clover
-
- - name: Upload to Codecov
- uses: codecov/codecov-action@v2
- with:
- token: ${{ secrets.CODE_COV_TOKEN }}
- files: ./tmp/coverage.xml
- verbose: true
+ run: composer run-script test-${{ matrix.php-version }}
- coding-standard:
+ coverage-php:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
- php-version: ['7.2', '7.4', '8.0', '8.1', '8.2']
- name: Coding Standard ${{ matrix.php-version }}
+ php-version: ['5.5', '5.6', '7.2', '7.4', '8.0', '8.1', '8.2'] # removed 7.1 as it seems to have an issue with no code coverage driver.
+ name: Coverage PHP ${{ matrix.php-version }}
steps:
- uses: actions/checkout@v3
@@ -83,34 +76,17 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- coverage: none
+ coverage: pcov
- name: Composer install
run: composer install
- - name: Run PHP CodeSniffer
- run: composer run-script cs-checkstyle | vendor/bin/cs2pr
-
- static-analysis:
- runs-on: ubuntu-22.04
- strategy:
- fail-fast: false
- matrix:
- php-version: ['7.2', '7.4', '8.0', '8.1', '8.2']
- name: Static Analysis - PHP ${{ matrix.php-version }}
-
- steps:
- - uses: actions/checkout@v3
+ - name: Run PHPUnit
+ run: composer run-script coverage-${{ matrix.php-version }}
- - name: Setup PHP
- uses: shivammathur/setup-php@v2
+ - name: Upload to Codecov
+ uses: codecov/codecov-action@v3
with:
- php-version: ${{ matrix.php-version }}
- extensions: mbstring, intl
- coverage: none
-
- - name: Composer install
- run: composer install
-
- - name: Run PHP Analyzer
- run: composer run-script phpstan-github
\ No newline at end of file
+ token: ${{ secrets.CODECOV_TOKEN }}
+ files: ./tmp/coverage.xml
+ verbose: true
diff --git a/.gitignore b/.gitignore
index ae40efe..06f69f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,11 @@
.DS_Store
build
composer.lock
-tmp
+tmp/*
+!tmp/.gitkeep
vendor
-.phpunit.result.cache
\ No newline at end of file
+.phpunit.result.cache
+/.phpunit.cache
+coverage.xml
+unitreport.xml
+.vscode
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.markdown
similarity index 100%
rename from CONTRIBUTING.md
rename to CONTRIBUTING.markdown
diff --git a/README.md b/README.markdown
similarity index 98%
rename from README.md
rename to README.markdown
index 001e2ef..ee97d2c 100644
--- a/README.md
+++ b/README.markdown
@@ -13,29 +13,20 @@ A `.env` file parsing and loading library for PHP.
## Requirements
-* PHP 5.5+|7.2+
+* PHP 5.5+
## Installation
_[Using [Composer](http://getcomposer.org/)]_
-Run `composer require josegonzalez/dotenv`
+Run `composer require josegonzalez/dotenv:dev-master`
Or add the plugin to your project's `composer.json` - something like this:
-For php 5.5 -> 7.4
-```json
+```javascript
{
"require": {
- "josegonzalez/dotenv": ~3.2"
- }
- }
-```
-For php 7.4 -> 8.2+
-```json
- {
- "require": {
- "josegonzalez/dotenv": ~4.0"
+ "josegonzalez/dotenv": "dev-master"
}
}
```
diff --git a/composer.json b/composer.json
index 8211bd1..5305cc3 100644
--- a/composer.json
+++ b/composer.json
@@ -18,12 +18,9 @@
"m1/env": "2.*"
},
"require-dev": {
- "php": ">=7",
- "squizlabs/php_codesniffer": "2.*|3.*",
- "php-coveralls/php-coveralls": "~2.5",
- "php-mock/php-mock-phpunit": "~2.6",
- "phpstan/phpstan": "^1.9",
- "staabm/annotate-pull-request-from-checkstyle": "^1.8"
+ "squizlabs/php_codesniffer": "~2.9||~3.7",
+ "php-coveralls/php-coveralls": "~2.0",
+ "php-mock/php-mock-phpunit": "~1.1||~2.0"
},
"autoload": {
"psr-0": {
@@ -33,16 +30,37 @@
"scripts": {
"ci": [
"@cs-check",
- "@phpstan",
- "@test"
+ "@test",
+ "@coverage-clover"
],
- "cs-check": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 ./src ./tests",
+ "test-5.5": "@test-5",
+ "test-5.6": "@test-5",
+ "test-7.0": "@test-7",
+ "test-7.1": "@test-7",
+ "test-7.2": "@test-7",
+ "test-7.4": "@test-7",
+ "test-8.0": "@test-8",
+ "test-8.1": "@test-8",
+ "test-8.2": "@test-8",
+ "coverage-5.5": "@coverage-5",
+ "coverage-5.6": "@coverage-5",
+ "coverage-7.0": "@coverage-7",
+ "coverage-7.1": "@coverage-7",
+ "coverage-7.2": "@coverage-7",
+ "coverage-7.4": "@coverage-7",
+ "coverage-8.0": "@coverage-8",
+ "coverage-8.1": "@coverage-8",
+ "coverage-8.2": "@coverage-8",
+ "cs-check": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --exclude=Generic.Files.LineLength ./src ./tests",
"cs-checkstyle": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --report=checkstyle ./src ./tests",
"cs-fix": "php -d memory_limit=-1 ./vendor/bin/phpcbf --standard=psr2 ./src ./tests",
- "phpstan": "php -d memory_limit=-1 ./vendor/bin/phpstan --no-progress -vvv",
- "phpstan-github": "php -d memory_limit=-1 ./vendor/bin/phpstan --no-progress -vvv --error-format=github",
- "test": "php -d memory_limit=-1 ./vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml",
- "coverage-clover": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-clover=tmp/coverage.xml --testdox",
+ "test": "@test-8",
+ "test-5": "php -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.5.xml --colors=always --log-junit unitreport.xml --testdox",
+ "test-7": "php -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.7.xml --colors=always --log-junit unitreport.xml --testdox",
+ "test-8": "php -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.8.xml --colors=always --log-junit unitreport.xml --testdox",
+ "coverage-5": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit -c phpunit.5.xml --coverage-text --coverage-clover=./tmp/coverage.xml --testdox",
+ "coverage-7": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit -c phpunit.7.xml --coverage-text --coverage-clover=./tmp/coverage.xml --testdox",
+ "coverage-8": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit -c phpunit.8.xml --coverage-text --coverage-clover=./tmp/coverage.xml --testdox",
"coveralls": "php -d memory_limit=-1 ./vendor/bin/vendor/bin/coveralls -v"
}
}
diff --git a/phpstan.neon b/phpstan.neon
deleted file mode 100644
index 14ce3b5..0000000
--- a/phpstan.neon
+++ /dev/null
@@ -1,9 +0,0 @@
-parameters:
- level: 7
- parallel:
- processTimeout: 900.0
- paths:
- - src
- - tests
- ignoreErrors:
- - '#Constant [A-Z_]+ not found.#'
diff --git a/phpunit.5.xml b/phpunit.5.xml
new file mode 100644
index 0000000..c7eb229
--- /dev/null
+++ b/phpunit.5.xml
@@ -0,0 +1,30 @@
+
+
+
+
+ tests/josegonzalez/Dotenv
+
+
+
+
+ ./docs
+ ./vendor
+ ./tests/bootstrap.php
+
+
+
+ src
+
+
+
diff --git a/phpunit.xml b/phpunit.7.xml
similarity index 66%
rename from phpunit.xml
rename to phpunit.7.xml
index 63336b0..3dca3e1 100644
--- a/phpunit.xml
+++ b/phpunit.7.xml
@@ -14,4 +14,12 @@
tests/josegonzalez/Dotenv
+
+
+
+ src
+
+
diff --git a/phpunit.8.xml b/phpunit.8.xml
new file mode 100644
index 0000000..5c67fb0
--- /dev/null
+++ b/phpunit.8.xml
@@ -0,0 +1,13 @@
+
+
+
+
+ ./src
+
+
+
+
+ tests/josegonzalez/Dotenv
+
+
+
diff --git a/phpunit.8.xml.bak b/phpunit.8.xml.bak
new file mode 100644
index 0000000..fd8447d
--- /dev/null
+++ b/phpunit.8.xml.bak
@@ -0,0 +1,32 @@
+
+
+
+
+ tests
+
+
+
+
+ ./src
+
+
+
diff --git a/src/josegonzalez/Dotenv/Expect.php b/src/josegonzalez/Dotenv/Expect.php
index 89d0d5c..f94eacd 100644
--- a/src/josegonzalez/Dotenv/Expect.php
+++ b/src/josegonzalez/Dotenv/Expect.php
@@ -7,33 +7,16 @@
class Expect
{
+ protected $environment = array();
- /** @var array The parsed variables. */
- protected $environment = [];
-
- /** @var bool If we should throw exceptions or not. */
protected $raise = true;
-
- /**
- * Checks the environment ans throws an exception of something is missing.
- *
- * @param array $environment The variables to check
- * @param bool $raise If we should throw exceptions or not.
- * @return void
- */
- public function __construct(array $environment, $raise = true)
+ public function __construct($environment, $raise = true)
{
$this->environment = $environment;
$this->raise = $raise;
}
- /**
- * Checks the environment ans throws an exception of something is missing.
- *
- * @return bool Actually always false
- * @throws \RuntimeException|\LogicException
- */
public function __invoke()
{
$args = func_get_args();
@@ -46,7 +29,7 @@ public function __invoke()
}
$keys = (array) $args;
- $missingEnvs = [];
+ $missingEnvs = array();
foreach ($keys as $key) {
if (!isset($this->environment[$key])) {
@@ -64,19 +47,9 @@ public function __invoke()
return true;
}
- /**
- * Throw and track exceptions
- *
- * @param \Exception|string $exception
- * @param string $message The message send with the exception.
- * @return bool Actually always false
- * @throws \Exception
- */
- protected function raise($exception, string $message): bool
+ protected function raise($exception, $message)
{
if ($this->raise) {
- // @todo Figure out how to properly define this line so phpstan can understand it.
- // @phpstan-ignore-next-line
throw new $exception($message);
}
diff --git a/src/josegonzalez/Dotenv/Filter/CallableFilter.php b/src/josegonzalez/Dotenv/Filter/CallableFilter.php
index e8d0968..5251926 100644
--- a/src/josegonzalez/Dotenv/Filter/CallableFilter.php
+++ b/src/josegonzalez/Dotenv/Filter/CallableFilter.php
@@ -2,16 +2,16 @@
namespace josegonzalez\Dotenv\Filter;
-class CallableFilter extends Filter
+class CallableFilter
{
/**
* Wraps a callable and invokes it upon the environment.
*
- * @param array $environment Array of environment data
- * @param array $config Array of configuration data that includes the callable
- * @return array|object
+ * @param array $environment Array of environment data
+ * @param array $config Array of configuration data that includes the callable
+ * @return array
*/
- public function __invoke(array $environment, $config = [])
+ public function __invoke(array $environment, array $config)
{
$callable = $config['callable'];
return $callable($environment, $config);
diff --git a/src/josegonzalez/Dotenv/Filter/Filter.php b/src/josegonzalez/Dotenv/Filter/Filter.php
deleted file mode 100644
index 5cd8065..0000000
--- a/src/josegonzalez/Dotenv/Filter/Filter.php
+++ /dev/null
@@ -1,18 +0,0 @@
- $environment Array of environment data
- * @param null|array $config Config values.
- * @return array
- */
- public function __invoke(array $environment, $config = null)
- {
- return $environment;
- }
-}
diff --git a/src/josegonzalez/Dotenv/Filter/LowercaseKeyFilter.php b/src/josegonzalez/Dotenv/Filter/LowercaseKeyFilter.php
index 705b7fc..66f5d8b 100644
--- a/src/josegonzalez/Dotenv/Filter/LowercaseKeyFilter.php
+++ b/src/josegonzalez/Dotenv/Filter/LowercaseKeyFilter.php
@@ -2,18 +2,17 @@
namespace josegonzalez\Dotenv\Filter;
-class LowercaseKeyFilter extends Filter
+class LowercaseKeyFilter
{
/**
* Lowercases all the keys for an environment to a single-depth.
*
- * @param array $environment Array of environment data
- * @param null|array $config Config values. Here to be compatible with Filter.
- * @return array
+ * @param array $environment Array of environment data
+ * @return array
*/
- public function __invoke(array $environment, $config = null)
+ public function __invoke(array $environment)
{
- $newEnvironment = [];
+ $newEnvironment = array();
foreach ($environment as $key => $value) {
$newEnvironment[strtolower($key)] = $value;
}
diff --git a/src/josegonzalez/Dotenv/Filter/NullFilter.php b/src/josegonzalez/Dotenv/Filter/NullFilter.php
index 3043a7f..d6b82dd 100644
--- a/src/josegonzalez/Dotenv/Filter/NullFilter.php
+++ b/src/josegonzalez/Dotenv/Filter/NullFilter.php
@@ -2,16 +2,15 @@
namespace josegonzalez\Dotenv\Filter;
-class NullFilter extends Filter
+class NullFilter
{
/**
* Returns the environment data without any changes.
*
- * @param array $environment Array of environment data
- * @param null|array $config Config values. Here to be compatible with Filter.
- * @return array
+ * @param array $environment Array of environment data
+ * @return array
*/
- public function __invoke(array $environment, $config = [])
+ public function __invoke(array $environment)
{
return $environment;
}
diff --git a/src/josegonzalez/Dotenv/Filter/RemapKeysFilter.php b/src/josegonzalez/Dotenv/Filter/RemapKeysFilter.php
index 24758f0..790156e 100644
--- a/src/josegonzalez/Dotenv/Filter/RemapKeysFilter.php
+++ b/src/josegonzalez/Dotenv/Filter/RemapKeysFilter.php
@@ -2,16 +2,16 @@
namespace josegonzalez\Dotenv\Filter;
-class RemapKeysFilter extends Filter
+class RemapKeysFilter
{
/**
* Remaps specific keys in a $config array to a set of values at a single-depth.
*
- * @param array $environment Array of environment data
- * @param array $config Config values.
- * @return array
+ * @param array $environment Array of environment data
+ * @param array $config Array of keys to remap to specific values
+ * @return array
*/
- public function __invoke(array $environment, $config = [])
+ public function __invoke(array $environment, array $config)
{
foreach ($config as $key => $value) {
if (array_key_exists($key, $environment)) {
diff --git a/src/josegonzalez/Dotenv/Filter/UnderscoreArrayFilter.php b/src/josegonzalez/Dotenv/Filter/UnderscoreArrayFilter.php
index 1f3d11e..37777f5 100644
--- a/src/josegonzalez/Dotenv/Filter/UnderscoreArrayFilter.php
+++ b/src/josegonzalez/Dotenv/Filter/UnderscoreArrayFilter.php
@@ -2,7 +2,7 @@
namespace josegonzalez\Dotenv\Filter;
-class UnderscoreArrayFilter extends Filter
+class UnderscoreArrayFilter
{
/**
* Expands a flat array to a nested array.
@@ -10,33 +10,32 @@ class UnderscoreArrayFilter extends Filter
* For example, `['0_Foo_Bar' => 'Far']` becomes
* `[['Foo' => ['Bar' => 'Far']]]`.
*
- * @param array $environment Array of environment data
- * @param null|array $config Config values. Here to be compatible with Filter.
- * @return array
+ * @param array $environment Array of environment data
+ * @return array
*/
- public function __invoke(array $environment, $config = null)
+ public function __invoke(array $environment)
{
- $result = [];
+ $result = array();
foreach ($environment as $flat => $value) {
$keys = explode('_', $flat);
$keys = array_reverse($keys);
- $child = [
+ $child = array(
$keys[0] => $value
- ];
+ );
array_shift($keys);
foreach ($keys as $k) {
- $child = [
+ $child = array(
$k => $child
- ];
+ );
}
- $stack = [[$child, &$result]];
+ $stack = array(array($child, &$result));
while (!empty($stack)) {
foreach ($stack as $curKey => &$curMerge) {
foreach ($curMerge[0] as $key => &$val) {
$hasKey = !empty($curMerge[1][$key]);
if ($hasKey && (array)$curMerge[1][$key] === $curMerge[1][$key] && (array)$val === $val) {
- $stack[] = [&$val, &$curMerge[1][$key]];
+ $stack[] = array(&$val, &$curMerge[1][$key]);
} else {
$curMerge[1][$key] = $val;
}
diff --git a/src/josegonzalez/Dotenv/Filter/UppercaseFirstKeyFilter.php b/src/josegonzalez/Dotenv/Filter/UppercaseFirstKeyFilter.php
index 734910c..07ae17f 100644
--- a/src/josegonzalez/Dotenv/Filter/UppercaseFirstKeyFilter.php
+++ b/src/josegonzalez/Dotenv/Filter/UppercaseFirstKeyFilter.php
@@ -2,18 +2,17 @@
namespace josegonzalez\Dotenv\Filter;
-class UppercaseFirstKeyFilter extends Filter
+class UppercaseFirstKeyFilter
{
/**
* Uppercases the first letter for all the keys for an environment to a single-depth.
*
- * @param array $environment Array of environment data
- * @param null|array $config Config values. Here to be compatible with Filter.
- * @return array
+ * @param array $environment Array of environment data
+ * @return array
*/
- public function __invoke(array $environment, $config = null)
+ public function __invoke(array $environment)
{
- $newEnvironment = [];
+ $newEnvironment = array();
foreach ($environment as $key => $value) {
$newEnvironment[ucfirst($key)] = $value;
}
diff --git a/src/josegonzalez/Dotenv/Filter/UrlParseFilter.php b/src/josegonzalez/Dotenv/Filter/UrlParseFilter.php
index fd17182..8a67440 100644
--- a/src/josegonzalez/Dotenv/Filter/UrlParseFilter.php
+++ b/src/josegonzalez/Dotenv/Filter/UrlParseFilter.php
@@ -2,47 +2,36 @@
namespace josegonzalez\Dotenv\Filter;
-class UrlParseFilter extends Filter
+class UrlParseFilter
{
/**
* When there is a key with the suffix `_URL`, this filter uses `parse_url`
* to add extra data to the environment.
*
- * @param array $environment Array of environment data
- * @param null|array $config Config values. Here to be compatible with Filter.
- * @return array
+ * @param array $environment Array of environment data
+ * @return array
*/
- public function __invoke(array $environment, $config = null)
+ public function __invoke(array $environment)
{
- $newEnvironment = [];
+ $newEnvironment = array();
foreach ($environment as $key => $value) {
$newEnvironment[$key] = $value;
if (substr($key, -4) === '_URL') {
$prefix = substr($key, 0, -3);
$url = parse_url($value);
- if (is_array($url)) {
- $newEnvironment[$prefix . 'SCHEME'] = $this->get($url, 'scheme', '');
- $newEnvironment[$prefix . 'HOST'] = $this->get($url, 'host', '');
- $newEnvironment[$prefix . 'PORT'] = $this->get($url, 'port', '');
- $newEnvironment[$prefix . 'USER'] = $this->get($url, 'user', '');
- $newEnvironment[$prefix . 'PASS'] = $this->get($url, 'pass', '');
- $newEnvironment[$prefix . 'PATH'] = $this->get($url, 'path', '');
- $newEnvironment[$prefix . 'QUERY'] = $this->get($url, 'query', '');
- $newEnvironment[$prefix . 'FRAGMENT'] = $this->get($url, 'fragment', '');
- }
+ $newEnvironment[$prefix . 'SCHEME'] = $this->get($url, 'scheme', '');
+ $newEnvironment[$prefix . 'HOST'] = $this->get($url, 'host', '');
+ $newEnvironment[$prefix . 'PORT'] = $this->get($url, 'port', '');
+ $newEnvironment[$prefix . 'USER'] = $this->get($url, 'user', '');
+ $newEnvironment[$prefix . 'PASS'] = $this->get($url, 'pass', '');
+ $newEnvironment[$prefix . 'PATH'] = $this->get($url, 'path', '');
+ $newEnvironment[$prefix . 'QUERY'] = $this->get($url, 'query', '');
+ $newEnvironment[$prefix . 'FRAGMENT'] = $this->get($url, 'fragment', '');
}
}
return $newEnvironment;
}
- /**
- * Gets the filter
- *
- * @param array $data The array to look at
- * @param int|string $key The key in $data to look for
- * @param null|mixed $default The default value to return if key isn't found
- * @return null|mixed The found value or $default
- */
public function get(array $data, $key, $default = null)
{
if (isset($data[$key])) {
diff --git a/src/josegonzalez/Dotenv/Loader.php b/src/josegonzalez/Dotenv/Loader.php
index 2593cb8..2fd4b00 100644
--- a/src/josegonzalez/Dotenv/Loader.php
+++ b/src/josegonzalez/Dotenv/Loader.php
@@ -1,8 +1,4 @@
List of thrown exceptsions being tracked. */
- protected $exceptions = [];
- /** @var null|array The parsed variables. */
protected $environment = null;
- /** @var array|null A list of file paths to use to fine the .env file. */
+ protected $exceptions = array();
+
protected $filepaths = null;
- /** @var array List of filters to use. */
- protected $filters = [];
+ protected $filters = array();
- /** @var null|string The prefix we should use for keys. */
protected $prefix = null;
- /** @var bool If we should raise exceptions. */
protected $raise = true;
- /** @var array Available sources and if they should be skipped. */
- protected $skip = [
+ protected $skip = array(
'apacheSetenv' => false,
'define' => false,
'putenv' => false,
'toEnv' => false,
'toServer' => false,
- ];
-
- /**
- * Constructor
- *
- * @param null|string|array $filepaths
- * @return void
- */
+ );
+
public function __construct($filepaths = null)
{
$this->setFilepaths($filepaths);
}
- /**
- * Creates the Loader object with a set of options.
- *
- * @param null|string|array $options
- * @return \josegonzalez\Dotenv\Loader
- */
public static function load($options = null)
{
$filepaths = null;
if (is_string($options)) {
$filepaths = $options;
- $options = [];
+ $options = array();
} elseif (isset($options['filepath'])) {
$filepaths = (array)$options['filepath'];
unset($options['filepath']);
@@ -85,7 +63,7 @@ public static function load($options = null)
$dotenv->filter();
}
- $methods = [
+ $methods = array(
'skipExisting',
'prefix',
'expect',
@@ -94,8 +72,7 @@ public static function load($options = null)
'putenv',
'toEnv',
'toServer',
- ];
-
+ );
foreach ($methods as $method) {
if (array_key_exists($method, $options)) {
$dotenv->$method($options[$method]);
@@ -105,77 +82,43 @@ public static function load($options = null)
return $dotenv;
}
- /**
- * Gets the current file path from the list.
- *
- * @return string
- */
public function filepath()
{
return current($this->filepaths);
}
- /**
- * Gets the list of files paths.
- *
- * @return array|null
- */
public function filepaths()
{
return $this->filepaths;
}
- /**
- * Sets a single file path
- *
- * @param null|string $filepath The path to add to the list.
- * @return self
- */
- public function setFilepath(?string $filepath = null)
+ public function setFilepath($filepath = null)
{
return $this->setFilepaths($filepath);
}
- /**
- * Sets the list of paths to look for the .env file
- *
- * @param null|string|array $filepaths One or more file paths to look in.
- * @return self
- */
public function setFilepaths($filepaths = null)
{
if ($filepaths == null) {
- $filepaths = [__DIR__ . DIRECTORY_SEPARATOR . '.env'];
+ $filepaths = array(__DIR__ . DIRECTORY_SEPARATOR . '.env');
}
if (is_string($filepaths)) {
- $filepaths = [$filepaths];
+ $filepaths = array($filepaths);
}
$this->filepaths = $filepaths;
return $this;
}
- /**
- * gets the filters to use.
- *
- * @return array The defined list of filters.
- */
public function filters()
{
return $this->filters;
}
- /**
- * Sets the filters to use.
- *
- * @param array $filters An array of filters to use.
- * @return self|bool
- * @throws \LogicException
- */
public function setFilters(array $filters)
{
- $newList = [];
+ $newList = array();
$keys = array_keys($filters);
$count = count($keys);
for ($i = 0; $i < $count; $i++) {
@@ -184,9 +127,9 @@ public function setFilters(array $filters)
if (is_string($filter)) {
$newList[$filter] = null;
} else {
- $newList['__callable__' . $i] = [
+ $newList['__callable__' . $i] = array(
'callable' => $filter
- ];
+ );
}
} else {
$newList[$keys[$i]] = $filters[$keys[$i]];
@@ -219,12 +162,6 @@ public function setFilters(array $filters)
return $this;
}
- /**
- * Filter variables
- *
- * @return self
- * @throws \InvalidArgumentException
- */
public function filter()
{
$this->requireParse('filter');
@@ -240,7 +177,6 @@ public function filter()
$filter = new $filterClass;
}
}
- /** @var \josegonzalez\Dotenv\Filter\Filter $filter */
$environment = $filter($environment, $config);
}
@@ -248,12 +184,6 @@ public function filter()
return $this;
}
- /**
- * Parses the .env file into the environment variable
- *
- * @return self|bool
- * @throws \InvalidArgumentException
- */
public function parse()
{
$contents = false;
@@ -287,19 +217,12 @@ public function parse()
}
}
- /** @var string $contents Come on phpstan. */
$parser = new Parser($contents);
$this->environment = $parser->getContent();
return $this;
}
- /**
- * Used to create an Expect object
- *
- * @return self|bool
- * @throws \Exception
- */
public function expect()
{
$this->requireParse('expect');
@@ -310,13 +233,6 @@ public function expect()
return $this;
}
- /**
- * Uses apache_setenv() to set variables
- *
- * @param bool $overwrite If we should overwrite variables via apache_setenv()
- * @return self|bool
- * @throws \Exception
- */
public function apacheSetenv($overwrite = false)
{
$this->requireParse('apache_setenv');
@@ -339,12 +255,6 @@ public function apacheSetenv($overwrite = false)
return $this;
}
- /**
- * Uses define() to set variables
- *
- * @return self|bool
- * @throws \Exception
- */
public function define()
{
$this->requireParse('define');
@@ -367,13 +277,6 @@ public function define()
return $this;
}
- /**
- * Uses putenv() to set variables
- *
- * @param bool $overwrite If we should overwrite variables via putenv()
- * @return self|bool
- * @throws \Exception
- */
public function putenv($overwrite = false)
{
$this->requireParse('putenv');
@@ -396,13 +299,6 @@ public function putenv($overwrite = false)
return $this;
}
- /**
- * Updates $_ENV
- *
- * @param bool $overwrite If we should overwrite the initial value of $_ENV values
- * @return self|bool
- * @throws \Exception
- */
public function toEnv($overwrite = false)
{
$this->requireParse('toEnv');
@@ -425,13 +321,6 @@ public function toEnv($overwrite = false)
return $this;
}
- /**
- * Updates $_SERVER
- *
- * @param bool $overwrite If we should overwrite the initial value of $_SERVER values
- * @return self|bool
- * @throws \Exception
- */
public function toServer($overwrite = false)
{
$this->requireParse('toServer');
@@ -454,12 +343,6 @@ public function toServer($overwrite = false)
return $this;
}
- /**
- * Sets what types to skip
- *
- * @param mixed $types The types to skip
- * @return self
- */
public function skipExisting($types = null)
{
$args = func_get_args();
@@ -472,7 +355,6 @@ public function skipExisting($types = null)
$types = array_keys($this->skip);
}
- /** @var string $type */
foreach ((array)$types as $type) {
$this->skip[$type] = true;
}
@@ -480,14 +362,9 @@ public function skipExisting($types = null)
return $this;
}
- /**
- * Returns list of variables to skip.
- *
- * @return array
- */
public function skipped()
{
- $skipped = [];
+ $skipped = array();
foreach ($this->skip as $key => $value) {
if ($value == true) {
$skipped[] = $key;
@@ -496,25 +373,13 @@ public function skipped()
return $skipped;
}
- /**
- * Sets the prefix.
- *
- * @param string|null $prefix
- * @return self
- */
- public function prefix(?string $prefix = null)
+ public function prefix($prefix = null)
{
$this->prefix = $prefix;
return $this;
}
- /**
- * Add prefix to a key
- *
- * @param string $key The key that may need to be prefixed.
- * @return string The modified key.
- */
- public function prefixed(string $key)
+ public function prefixed($key)
{
if (!!$this->prefix) {
$key = $this->prefix . $key;
@@ -523,24 +388,12 @@ public function prefixed(string $key)
return $key;
}
- /**
- * Flags if we should raise exceptions, or ignore them
- *
- * @param bool $raise If we should allow exceptions
- * @return self
- */
public function raiseExceptions($raise = true)
{
$this->raise = $raise;
return $this;
}
- /**
- * Creates and return an array from the known environment.
- *
- * @return array|null
- * @throws \Exception
- */
public function toArray()
{
$this->requireParse('toArray');
@@ -548,38 +401,25 @@ public function toArray()
return null;
}
- $environment = [];
+ $environment = array();
foreach ($this->environment as $key => $value) {
$environment[$this->prefixed($key)] = $value;
}
return $environment;
}
- /**
- * Converts array to json string
- *
- * @return string
- */
public function __toString()
{
try {
$data = $this->toArray();
} catch (LogicException $e) {
- $data = [];
+ $data = array();
}
- $json = json_encode($data);
- return $json ? $json : '';
+ return json_encode($data);
}
- /**
- * Requires the the .env has been parsed first.
- *
- * @param string $method The message send with the exception.
- * @return void|bool
- * @throws \Exception
- */
- protected function requireParse(string $method)
+ protected function requireParse($method)
{
if (!is_array($this->environment)) {
return $this->raise(
@@ -589,19 +429,9 @@ protected function requireParse(string $method)
}
}
- /**
- * Throw and track exceptions
- *
- * @param \Exception|string $exception
- * @param string $message The message send with the exception.
- * @return bool Actually always false
- * @throws \Exception
- */
- protected function raise($exception, string $message): bool
+ protected function raise($exception, $message)
{
if ($this->raise) {
- // @todo Figure out how to properly define this line so phpstan can understand it.
- // @phpstan-ignore-next-line
throw new $exception($message);
}
diff --git a/tests/josegonzalez/Dotenv/ExpectTest.php b/tests/josegonzalez/Dotenv/ExpectTest.php
index bd7c4f9..5220fad 100644
--- a/tests/josegonzalez/Dotenv/ExpectTest.php
+++ b/tests/josegonzalez/Dotenv/ExpectTest.php
@@ -3,24 +3,29 @@
namespace josegonzalez\Dotenv;
use josegonzalez\Dotenv\Expect;
-use PHPUnit\Framework\TestCase;
+use \PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
-class ExpectTest extends TestCase
+class ExpectTest extends PHPUnit_Framework_TestCase
{
+ protected $env = array();
- /** @var array */
- protected $env = [];
-
- /** @var array */
- protected $server = [];
+ protected $server = array();
- public function setUp(): void
+ /**
+ * Hopefully this will allow php > 7.1 to run.
+ * Phpunit >= 8.0 uses setUp(): void which this needs to match, but will break php 5.x
+ */
+ public function compatibleSetUp()
{
$this->env = $_ENV;
$this->server = $_SERVER;
}
- public function tearDown(): void
+ /**
+ * Hopefully this will allow php > 7.1 to run.
+ * Phpunit >= 8.0 uses tearDown(): void which this needs to match, but will break php 5.x
+ */
+ public function compatibleTearDown()
{
$_ENV = $this->env;
$_SERVER = $this->server;
@@ -33,38 +38,54 @@ public function tearDown(): void
* @covers \josegonzalez\Dotenv\Expect::__invoke
* @covers \josegonzalez\Dotenv\Expect::raise
*/
- public function testExpect(): void
+ public function testExpect()
{
+ $this->compatibleSetUp();
$expect = new Expect($this->server);
$this->assertTrue($expect('USER'));
- $this->assertTrue($expect(['USER', 'HOME']));
+ $this->assertTrue($expect(array('USER', 'HOME')));
$expect = new Expect($this->server, false);
$this->assertFalse($expect('FOO'));
- $this->assertFalse($expect(['USER', 'FOO']));
+ $this->assertFalse($expect(array('USER', 'FOO')));
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Expect::__construct
* @covers \josegonzalez\Dotenv\Expect::__invoke
* @covers \josegonzalez\Dotenv\Expect::raise
+ * @expectedException LogicException
+ * @expectedExceptionMessage No arguments were passed to expect()
*/
- public function testExpectLogicException(): void
+ public function testExpectLogicException()
{
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('No arguments were passed to expect()');
+ $this->compatibleSetUp();
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('No arguments were passed to expect()');
+ }
$expect = new Expect($this->server);
$expect();
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Expect::__construct
* @covers \josegonzalez\Dotenv\Expect::__invoke
* @covers \josegonzalez\Dotenv\Expect::raise
+ * @expectedException RuntimeException
+ * @expectedExceptionMessage Required ENV vars missing: ['INVALID']
*/
- public function testExpectRuntimeException(): void
+ public function testExpectRuntimeException()
{
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage("Required ENV vars missing: ['INVALID']");
+ $this->compatibleSetUp();
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\RuntimeException::class);
+ $this->expectExceptionMessage("Required ENV vars missing: ['INVALID']");
+ }
$expect = new Expect($this->server);
$expect('INVALID');
+ $this->compatibleTearDown();
}
}
diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php
index c100439..558a173 100644
--- a/tests/josegonzalez/Dotenv/LoaderTest.php
+++ b/tests/josegonzalez/Dotenv/LoaderTest.php
@@ -4,44 +4,42 @@
use josegonzalez\Dotenv\Loader;
use phpmock\phpunit\PHPMock;
-use PHPUnit\Framework\TestCase;
+use \PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
-/**
- * Just return what was handed to it.
- * @param mixed $data basically anything
- * @return mixed Whatever was in $data
- */
function doNothing($data)
{
return $data;
}
-class LoaderTest extends TestCase
+class LoaderTest extends PHPUnit_Framework_TestCase
{
use PHPMock;
+ protected $env = array();
- /** @var array */
- protected $env = [];
-
- /** @var array */
- protected $server = [];
+ protected $server = array();
- /** @var string */
protected $fixturePath = '';
- /** @var \josegonzalez\Dotenv\Loader */
protected $Loader;
- public function setUp(): void
+ /**
+ * Hopefully this will allow php > 7.1 to run.
+ * Phpunit >= 8.0 uses setUp(): void which this needs to match, but will break php 5.x
+ */
+ public function compatibleSetUp()
{
$this->env = $_ENV;
$this->server = $_SERVER;
$this->fixturePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR;
$this->Loader = new Loader($this->fixturePath . '.env');
- $GLOBALS['apache_test_data'] = [];
+ $GLOBALS['apache_test_data'] = array();
}
- public function tearDown(): void
+ /**
+ * Hopefully this will allow php > 7.1 to run.
+ * Phpunit >= 8.0 uses tearDown(): void which this needs to match, but will break php 5.x
+ */
+ public function compatibleTearDown()
{
$_ENV = $this->env;
$_SERVER = $this->server;
@@ -52,44 +50,64 @@ public function tearDown(): void
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::filepath
*/
- public function testFilepath(): void
+ public function testFilepath()
{
+ $this->compatibleSetUp();
$this->assertEquals($this->fixturePath . '.env', $this->Loader->filepath());
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::filepaths
*/
- public function testFilepaths(): void
+ public function testFilepaths()
{
- $this->assertEquals([$this->fixturePath . '.env'], $this->Loader->filepaths());
+ $this->compatibleSetUp();
+ $this->assertEquals(array($this->fixturePath . '.env'), $this->Loader->filepaths());
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
* @covers \josegonzalez\Dotenv\Loader::setFilepath
* @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::filepath
*/
- public function testSetFilepath(): void
+ public function testSetFilepath()
{
+ $this->compatibleSetUp();
$this->Loader->setFilepath('/tmp/.env');
$this->assertEquals('/tmp/.env', $this->Loader->filepath());
$this->Loader->setFilepath(null);
- $basePath = realpath(implode(DIRECTORY_SEPARATOR, [
+ $basePath = realpath(implode(DIRECTORY_SEPARATOR, array(
__DIR__,
'..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..',
'src' . DIRECTORY_SEPARATOR . 'josegonzalez' . DIRECTORY_SEPARATOR . 'Dotenv',
- ]));
+ )));
$this->assertEquals($basePath . DIRECTORY_SEPARATOR .'.env', $this->Loader->filepath());
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepath
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::toArray
* @covers \josegonzalez\Dotenv\Loader::parse
*/
- public function testParse(): void
+ public function testParse()
{
+ $this->compatibleSetUp();
$this->Loader->setFilepath($this->fixturePath . 'all.env');
$this->Loader->parse();
$environment = $this->Loader->toArray();
@@ -116,11 +134,10 @@ public function testParse(): void
$this->assertEquals('bar', $environment['CFOO']);
$this->assertEquals('with spaces', $environment['CSPACED']);
$this->assertEquals('a value with a # character', $environment['CQUOTES']);
- $this->assertEquals('a value with a # character & a quote " ' .
- 'character inside quotes', $environment['CQUOTESWITHQUOTE']);
+ $this->assertEquals('a value with a # character & a quote " character inside quotes', $environment['CQUOTESWITHQUOTE']);
$this->assertSame(null, $environment['CNULL']);
- $this->assertEquals([
+ $this->assertEquals(array(
'FOO' => 'bar',
'BAR' => 'baz',
'SPACED' => 'unquotedwithspaces spaces',
@@ -165,279 +182,418 @@ public function testParse(): void
'STRING_EMPTY' => '',
'STRING_EMPTY_2' => '',
'NO_VALUE_INLINE_COMMENT' => null,
- ], $environment);
+ ), $environment);
$this->Loader->setFilepath($this->fixturePath . 'cake.env');
$this->Loader->parse();
$environment = $this->Loader->toArray();
$this->assertEquals('app', $environment['APP_NAME']);
- $this->assertSame(2, $environment['DEBUG']);
- $this->assertIsInt($environment['DEBUG']);
+ if (method_exists($this, 'assertInternalType')) {
+ $this->assertInternalType('int', $environment['DEBUG']);
+ }
+ $this->assertSame(2, $environment['DEBUG']); // this also tests the typecast, in this case, an int.
$this->assertEquals('DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi', $environment['SECURITY_SALT']);
$this->assertEquals('76859309657453542496749683645', $environment['SECURITY_CIPHER_SEED']);
- // lines are split to make phpcs happy
- // | WARNING | Line exceeds 120 characters; contains xxx characters
- $this->assertEquals('mysql://user:password@localhost' .
- '/database_name?encoding=utf8', $environment['DATABASE_URL']);
- $this->assertEquals('mysql://user:password@localhost' .
- '/test_database_name?encoding=utf8', $environment['DATABASE_TEST_URL']);
- $this->assertEquals('file:///vagrant/app/tmp/' .
- '?prefix=app_&duration=+2 minutes', $environment['CACHE_URL']);
- $this->assertEquals('file:///vagrant/app/tmp/' .
- '?prefix=app_debug_kit_&duration=+2 minutes', $environment['CACHE_DEBUG_KIT_URL']);
- $this->assertEquals('file:///vagrant/app/tmp/' .
- '?prefix=app_cake_core_&duration=+2 minutes', $environment['CACHE_CAKE_CORE_URL']);
- $this->assertEquals('file:///vagrant/app/tmp/' .
- '?prefix=app_cake_model_&duration=+2 minutes', $environment['CACHE_CAKE_MODEL_URL']);
- $this->assertEquals('file:///vagrant/app/logs/' .
- '?types=notice,info,debug&file=debug', $environment['LOG_URL']);
- $this->assertEquals('file:///vagrant/app/logs/' .
- '?types=warning,error,critical,alert,emergency&file=error', $environment['LOG_ERROR_URL']);
- $this->assertEquals('mail://localhost/?' .
- 'from=you@localhost', $environment['EMAIL_URL']);
- $this->assertEquals('smtp://user:secret@localhost:25/' .
- '?from[site@localhost]=My+Site&timeout=30', $environment['EMAIL_SMTP_URL']);
- $this->assertEquals('smtp://user:secret@localhost:25/' .
- '?from=you@localhost&messageId=1&template=0&layout=0&timeout=30', $environment['EMAIL_FAST_URL']);
+ $this->assertEquals('mysql://user:password@localhost/database_name?encoding=utf8', $environment['DATABASE_URL']);
+ $this->assertEquals('mysql://user:password@localhost/test_database_name?encoding=utf8', $environment['DATABASE_TEST_URL']);
+ $this->assertEquals('file:///vagrant/app/tmp/?prefix=app_&duration=+2 minutes', $environment['CACHE_URL']);
+ $this->assertEquals('file:///vagrant/app/tmp/?prefix=app_debug_kit_&duration=+2 minutes', $environment['CACHE_DEBUG_KIT_URL']);
+ $this->assertEquals('file:///vagrant/app/tmp/?prefix=app_cake_core_&duration=+2 minutes', $environment['CACHE_CAKE_CORE_URL']);
+ $this->assertEquals('file:///vagrant/app/tmp/?prefix=app_cake_model_&duration=+2 minutes', $environment['CACHE_CAKE_MODEL_URL']);
+ $this->assertEquals('file:///vagrant/app/logs/?types=notice,info,debug&file=debug', $environment['LOG_URL']);
+ $this->assertEquals('file:///vagrant/app/logs/?types=warning,error,critical,alert,emergency&file=error', $environment['LOG_ERROR_URL']);
+ $this->assertEquals('mail://localhost/?from=you@localhost', $environment['EMAIL_URL']);
+ $this->assertEquals('smtp://user:secret@localhost:25/?from[site@localhost]=My+Site&timeout=30', $environment['EMAIL_SMTP_URL']);
+ $this->assertEquals('smtp://user:secret@localhost:25/?from=you@localhost&messageId=1&template=0&layout=0&timeout=30', $environment['EMAIL_FAST_URL']);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::setFilepath
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::parse
- * @expectedExceptionMessage
+ * @expectedException M1\Env\Exception\ParseException
+ * @expectedExceptionMessage Key can only contain alphanumeric and underscores and can not start with a number: 01SKIPPED near 01SKIPPED at line 1
*/
- public function testParseException(): void
+ public function testParseException()
{
- $this->expectException(\M1\Env\Exception\ParseException::class);
- $this->expectExceptionMessage('Key can only contain alphanumeric' .
+ $this->compatibleSetUp();
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\M1\Env\Exception\ParseException::class);
+ $this->expectExceptionMessage('Key can only contain alphanumeric' .
' and underscores and can not start with a number: 01SKIPPED near 01SKIPPED at line 1');
+ }
$this->Loader->setFilepath($this->fixturePath . 'parse_exception.env');
$this->Loader->parse();
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::setFilepath
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::parse
+ * @expectedException InvalidArgumentException
+ * @expectedExceptionMessage Environment file '.env' is not found
*/
- public function testParseFileNotFound(): void
+ public function testParseFileNotFound()
{
- $this->expectException(\InvalidArgumentException::class);
- $this->expectExceptionMessage("Environment file '.env' is not found");
+ $this->compatibleSetUp();
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage("Environment file '.env' is not found");
+ }
$this->Loader->setFilepath('.env');
$this->Loader->parse();
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::setFilepath
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::parse
+ * @expectedException InvalidArgumentException
+ * @expectedExceptionMessage Environment file '/tmp' is a directory. Should be a file
*/
- public function testParseFileIsDirectory(): void
+ public function testParseFileIsDirectory()
{
- $this->expectException(\InvalidArgumentException::class);
- $this->expectExceptionMessage("Environment file '/tmp' is a directory. Should be a file");
+ $this->compatibleSetUp();
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage("Environment file '/tmp' is a directory. Should be a file");
+ }
$this->Loader->setFilepath('/tmp');
$this->Loader->parse();
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::setFilepath
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::parse
+ * @expectedException InvalidArgumentException
+ * @expectedExceptionMessage Environment file '/tmp/php-dotenv-unreadable' is not readable
*/
- public function testParseFileIsUnreadable(): void
+ public function testParseFileIsUnreadable()
{
- $this->expectException(\InvalidArgumentException::class);
- $this->expectExceptionMessage("Environment file '/tmp/php-dotenv-unreadable' is not readable");
+ $this->compatibleSetUp();
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage("Environment file '/tmp/php-dotenv-unreadable' is not readable");
+ }
touch('/tmp/php-dotenv-unreadable');
chmod('/tmp/php-dotenv-unreadable', 0000);
$this->Loader->setFilepath('/tmp/php-dotenv-unreadable');
$this->Loader->parse();
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::filters
*/
- public function testFilters(): void
+ public function testFilters()
{
- $this->assertSame([], $this->Loader->filters());
+ $this->compatibleSetUp();
+ $this->assertSame(array(), $this->Loader->filters());
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filters
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::setFilters
*/
- public function testSetFilters(): void
+ public function testSetFilters()
{
- $this->assertSame([], $this->Loader->filters());
- $this->assertEquals($this->Loader, $this->Loader->setFilters([
+ $this->compatibleSetUp();
+ $this->assertSame(array(), $this->Loader->filters());
+ $this->assertEquals($this->Loader, $this->Loader->setFilters(array(
'josegonzalez\Dotenv\Filter\NullFilter',
- ]));
+ )));
- $this->assertEquals($this->Loader, $this->Loader->setFilters([
+ $this->assertEquals($this->Loader, $this->Loader->setFilters(array(
'josegonzalez\Dotenv\doNothing',
- ]));
+ )));
- $this->assertEquals($this->Loader, $this->Loader->setFilters([
- 'josegonzalez\Dotenv\doNothing' => ['key' => 'value'],
- ]));
+ $this->assertEquals($this->Loader, $this->Loader->setFilters(array(
+ 'josegonzalez\Dotenv\doNothing' => array('key' => 'value'),
+ )));
- $this->assertEquals($this->Loader, $this->Loader->setFilters([
+ $this->assertEquals($this->Loader, $this->Loader->setFilters(array(
function () {
- return [];
+ return array();
}
- ]));
+ )));
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::setFilters
+ * @expectedException LogicException
+ * @expectedExceptionMessage Invalid filter class SomeFilter
*/
- public function testSetFilterNonexistentFilter(): void
+ public function testSetFilterNonexistentFilter()
{
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('Invalid filter class SomeFilter');
- $this->assertEquals($this->Loader, $this->Loader->setFilters([
+ $this->compatibleSetUp();
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('Invalid filter class SomeFilter');
+ }
+ $this->assertEquals($this->Loader, $this->Loader->setFilters(array(
'SomeFilter'
- ]));
+ )));
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::setFilters
+ * @expectedException LogicException
+ * @expectedExceptionMessage Invalid filter class
*/
- public function testSetFilterInvalidCallable(): void
+ public function testSetFilterInvalidCallable()
{
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('Invalid filter class');
- $this->assertEquals($this->Loader, $this->Loader->setFilters([
+ $this->compatibleSetUp();
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('Invalid filter class');
+ }
+ $this->assertEquals($this->Loader, $this->Loader->setFilters(array(
$this
- ]));
+ )));
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::setFilters
+ * @covers \josegonzalez\Dotenv\Loader::toArray
* @covers \josegonzalez\Dotenv\Loader::filter
* @covers \josegonzalez\Dotenv\Filter\NullFilter::__invoke
*/
- public function testFilter(): void
+ public function testFilter()
{
- $this->assertEquals($this->Loader, $this->Loader->setFilters([
+ $this->compatibleSetUp();
+ $this->assertEquals($this->Loader, $this->Loader->setFilters(array(
'josegonzalez\Dotenv\Filter\NullFilter',
- ]));
+ )));
$this->Loader->parse();
$this->Loader->filter();
- $this->assertEquals([
+ $this->assertEquals(array(
'FOO' => 'bar',
'BAR' => 'baz',
'SPACED' => 'with spaces',
'EQUALS' => 'pgsql:host=localhost;dbname=test',
- ], $this->Loader->toArray());
+ ), $this->Loader->toArray());
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::setFilters
+ * @covers \josegonzalez\Dotenv\Loader::toArray
* @covers \josegonzalez\Dotenv\Loader::filter
* @covers \josegonzalez\Dotenv\Filter\CallableFilter::__invoke
*/
- public function testFilterCallable(): void
+ public function testFilterCallable()
{
- $this->assertEquals($this->Loader, $this->Loader->setFilters([
+ $this->compatibleSetUp();
+ $this->assertEquals($this->Loader, $this->Loader->setFilters(array(
function () {
- return ['FOO' => 'BAR'];
+ return array('FOO' => 'BAR');
}
- ]));
+ )));
$this->Loader->parse();
$this->Loader->filter();
- $this->assertEquals(['FOO' => 'BAR'], $this->Loader->toArray());
+ $this->assertEquals(array('FOO' => 'BAR'), $this->Loader->toArray());
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::filter
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepath
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::setFilters
+ * @covers \josegonzalez\Dotenv\Loader::toArray
* @covers \josegonzalez\Dotenv\Filter\LowercaseKeyFilter::__invoke
*/
- public function testLowercaseKeyFilter(): void
+ public function testLowercaseKeyFilter()
{
- $this->Loader->setFilters([
+ $this->compatibleSetUp();
+ $this->Loader->setFilters(array(
'josegonzalez\Dotenv\Filter\LowercaseKeyFilter',
- ]);
+ ));
$this->Loader->setFilepath($this->fixturePath . '.env');
$this->Loader->parse();
$this->Loader->filter();
- $this->assertEquals([
+ $this->assertEquals(array(
'foo' => 'bar',
'bar' => 'baz',
'spaced' => 'with spaces',
'equals' => 'pgsql:host=localhost;dbname=test',
- ], $this->Loader->toArray());
+ ), $this->Loader->toArray());
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::filter
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepath
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::setFilters
+ * @covers \josegonzalez\Dotenv\Loader::toArray
* @covers \josegonzalez\Dotenv\Filter\NullFilter::__invoke
*/
- public function testNullFilter(): void
+ public function testNullFilter()
{
- $this->Loader->setFilters([
+ $this->compatibleSetUp();
+ $this->Loader->setFilters(array(
'josegonzalez\Dotenv\Filter\NullFilter',
- ]);
+ ));
$this->Loader->setFilepath($this->fixturePath . '.env');
$this->Loader->parse();
$this->Loader->filter();
- $this->assertEquals([
+ $this->assertEquals(array(
'FOO' => 'bar',
'BAR' => 'baz',
'SPACED' => 'with spaces',
'EQUALS' => 'pgsql:host=localhost;dbname=test',
- ], $this->Loader->toArray());
+ ), $this->Loader->toArray());
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::filter
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepath
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::setFilters
+ * @covers \josegonzalez\Dotenv\Loader::toArray
* @covers \josegonzalez\Dotenv\Filter\RemapKeysFilter::__invoke
*/
- public function testRemapKeysFilter(): void
+ public function testRemapKeysFilter()
{
- $this->Loader->setFilters([
- 'josegonzalez\Dotenv\Filter\RemapKeysFilter' => [
+ $this->compatibleSetUp();
+ $this->Loader->setFilters(array(
+ 'josegonzalez\Dotenv\Filter\RemapKeysFilter' => array(
'FOO' => 'QUX'
- ],
- ]);
+ ),
+ ));
$this->Loader->setFilepath($this->fixturePath . '.env');
$this->Loader->parse();
$this->Loader->filter();
- $this->assertEquals([
+ $this->assertEquals(array(
'QUX' => 'bar',
'BAR' => 'baz',
'SPACED' => 'with spaces',
'EQUALS' => 'pgsql:host=localhost;dbname=test',
- ], $this->Loader->toArray());
+ ), $this->Loader->toArray());
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Filter\LowercaseKeyFilter::__invoke
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::filter
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepath
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::setFilters
+ * @covers \josegonzalez\Dotenv\Loader::toArray
* @covers \josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter::__invoke
*/
- public function testUppercaseFirstKeyFilter(): void
+ public function testUppercaseFirstKeyFilter()
{
- $this->Loader->setFilters([
+ $this->compatibleSetUp();
+ $this->Loader->setFilters(array(
'josegonzalez\Dotenv\Filter\LowercaseKeyFilter',
'josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter',
- ]);
+ ));
$this->Loader->setFilepath($this->fixturePath . '.env');
$this->Loader->parse();
$this->Loader->filter();
- $this->assertEquals([
+ $this->assertEquals(array(
'Foo' => 'bar',
'Bar' => 'baz',
'Spaced' => 'with spaces',
'Equals' => 'pgsql:host=localhost;dbname=test',
- ], $this->Loader->toArray());
+ ), $this->Loader->toArray());
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::filter
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepath
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::setFilters
+ * @covers \josegonzalez\Dotenv\Loader::toArray
* @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::__invoke
* @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::get
*/
- public function testUrlParseFilter(): void
+ public function testUrlParseFilter()
{
- $this->Loader->setFilters([
+ $this->compatibleSetUp();
+ $this->Loader->setFilters(array(
'josegonzalez\Dotenv\Filter\UrlParseFilter',
- ]);
+ ));
$this->Loader->setFilepath($this->fixturePath . 'url_parse_filter.env');
$this->Loader->parse();
$this->Loader->filter();
$environment = $this->Loader->toArray();
- $this->assertSame([
+ $this->assertSame(array(
'READ_DATABASE_URL' => 'mysql://user:password@localhost/database_name?encoding=utf8',
'READ_DATABASE_SCHEME' => 'mysql',
'READ_DATABASE_HOST' => 'localhost',
@@ -456,59 +612,83 @@ public function testUrlParseFilter(): void
'DATABASE_PATH' => '/database_name',
'DATABASE_QUERY' => 'encoding=utf8',
'DATABASE_FRAGMENT' => '',
- ], $environment);
+ ), $environment);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::filter
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepath
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::setFilters
+ * @covers \josegonzalez\Dotenv\Loader::toArray
* @covers \josegonzalez\Dotenv\Filter\UnderscoreArrayFilter::__invoke
*/
- public function testUnderscoreArrayFilter(): void
+ public function testUnderscoreArrayFilter()
{
- $this->Loader->setFilters([
+ $this->compatibleSetUp();
+ $this->Loader->setFilters(array(
'josegonzalez\Dotenv\Filter\UnderscoreArrayFilter',
- ]);
+ ));
$this->Loader->setFilepath($this->fixturePath . 'underscore_array_filter.env');
$this->Loader->parse();
$this->Loader->filter();
$environment = $this->Loader->toArray();
- $this->assertEquals([
- 'DATABASE' => [
+ $this->assertEquals(array(
+ 'DATABASE' => array(
'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8',
- 0 => [
+ 0 => array(
'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8',
'OTHERURL' => 'mysql://user:password@localhost/database_name?encoding=utf8',
- ],
- 1 => [
+ ),
+ 1 => array(
'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8',
'OTHERURL' => 'mysql://user:password@localhost/database_name?encoding=utf8',
- ],
- ],
- 'DATA' => [
- 'BASE' => [
+ ),
+ ),
+ 'DATA' => array(
+ 'BASE' => array(
'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8'
- ],
- ],
+ ),
+ ),
- ], $environment);
+ ), $environment);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::filter
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepath
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::setFilters
+ * @covers \josegonzalez\Dotenv\Loader::toArray
* @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::__invoke
* @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::get
* @covers \josegonzalez\Dotenv\Filter\UnderscoreArrayFilter::__invoke
*/
- public function testMultipleFilters(): void
+ public function testMultipleFilters()
{
- $this->Loader->setFilters([
+ $this->compatibleSetUp();
+ $this->Loader->setFilters(array(
'josegonzalez\Dotenv\Filter\UrlParseFilter',
'josegonzalez\Dotenv\Filter\UnderscoreArrayFilter',
- ]);
+ ));
$this->Loader->setFilepath($this->fixturePath . 'filter.env');
$this->Loader->parse();
$this->Loader->filter();
$environment = $this->Loader->toArray();
- $this->assertSame([
- 'DATABASE' => [
+ $this->assertSame(array(
+ 'DATABASE' => array(
'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8',
'SCHEME' => 'mysql',
'HOST' => 'localhost',
@@ -518,9 +698,9 @@ public function testMultipleFilters(): void
'PATH' => '/database_name',
'QUERY' => 'encoding=utf8',
'FRAGMENT' => '',
- ],
- 'DATA' => [
- 'BASE' => [
+ ),
+ 'DATA' => array(
+ 'BASE' => array(
'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8',
'SCHEME' => 'mysql',
'HOST' => 'localhost',
@@ -530,77 +710,140 @@ public function testMultipleFilters(): void
'PATH' => '/database_name',
'QUERY' => 'encoding=utf8',
'FRAGMENT' => '',
- ],
- ],
- ], $environment);
+ ),
+ ),
+ ), $environment);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Expect::__construct
+ * @covers \josegonzalez\Dotenv\Expect::__invoke
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::expect
*/
- public function testExpect(): void
+ public function testExpect()
{
+ $this->compatibleSetUp();
$this->Loader->parse();
$this->assertInstanceOf('josegonzalez\Dotenv\Loader', $this->Loader->expect('FOO'));
- $this->assertInstanceOf('josegonzalez\Dotenv\Loader', $this->Loader->expect(['FOO', 'BAR']));
+ $this->assertInstanceOf('josegonzalez\Dotenv\Loader', $this->Loader->expect(array('FOO', 'BAR')));
+ $this->compatibleTearDown();
}
/**
- * @covers \josegonzalez\Dotenv\Loader::expect With no parsing done yet.
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::expect
+ * @expectedException LogicException
+ * @expectedExceptionMessage Environment must be parsed before calling expect()
*/
- public function testExpectRequireParse(): void
+ public function testExpectRequireParse()
{
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('Environment must be parsed before calling expect()');
+ $this->compatibleSetUp();
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('Environment must be parsed before calling expect()');
+ }
$this->Loader->expect();
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Expect::__construct
+ * @covers \josegonzalez\Dotenv\Expect::__invoke
+ * @covers \josegonzalez\Dotenv\Expect::raise
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::expect
+ * @expectedException LogicException
+ * @expectedExceptionMessage No arguments were passed to expect()
*/
- public function testExpectLogicException(): void
+ public function testExpectLogicException()
{
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('No arguments were passed to expect()');
+ $this->compatibleSetUp();
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('No arguments were passed to expect()');
+ }
$this->Loader->parse();
$this->Loader->expect();
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Expect::__construct
+ * @covers \josegonzalez\Dotenv\Expect::__invoke
+ * @covers \josegonzalez\Dotenv\Expect::raise
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::expect
+ * @expectedException RuntimeException
+ * @expectedExceptionMessage Required ENV vars missing: ['INVALID']
*/
- public function testExpectRuntimeException(): void
+ public function testExpectRuntimeException()
{
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage("Required ENV vars missing: ['INVALID']");
+ $this->compatibleSetUp();
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\RuntimeException::class);
+ $this->expectExceptionMessage("Required ENV vars missing: ['INVALID']");
+ }
$this->Loader->parse();
$this->Loader->expect('INVALID');
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::apacheSetenv
*/
- public function testToApacheSetenvExceptionUnavailable(): void
+ public function testToApacheSetenvExceptionUnavailable()
{
if (version_compare(PHP_VERSION, '7.0', '<')) {
$this->markTestSkipped('Unable to mock bare php functions');
}
+ $this->compatibleSetUp();
$this->expectException(\Error::class);
$this->expectExceptionMessage('Call to undefined function josegonzalez\Dotenv\apache_getenv()');
$this->Loader->parse();
$this->Loader->apacheSetenv(false);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::apacheSetenv
*/
- public function testToApacheSetenv(): void
+ public function testToApacheSetenv()
{
if (version_compare(PHP_VERSION, '7.0', '<')) {
$this->markTestSkipped('Unable to mock bare php functions');
}
+ $this->compatibleSetUp();
$apacheGetenv = $this->getFunctionMock(__NAMESPACE__, 'apache_getenv');
$apacheGetenv->expects($this->any())->willReturnCallback(
function ($key) {
@@ -625,17 +868,26 @@ function ($key, $value) {
$this->assertEquals('baz', apache_getenv('BAR'));
$this->assertEquals('with spaces', apache_getenv('SPACED'));
$this->assertEquals('pgsql:host=localhost;dbname=test', apache_getenv('EQUALS'));
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::skipExisting
* @covers \josegonzalez\Dotenv\Loader::apacheSetenv
*/
- public function testToApacheSetenvSkip(): void
+ public function testToApacheSetenvSkip()
{
if (version_compare(PHP_VERSION, '7.0', '<')) {
$this->markTestSkipped('Unable to mock bare php functions');
}
+ $this->compatibleSetUp();
$apacheGetenv = $this->getFunctionMock(__NAMESPACE__, 'apache_getenv');
$apacheGetenv->expects($this->any())->willReturnCallback(
function ($key) {
@@ -662,17 +914,33 @@ function ($key, $value) {
$this->assertEquals('baz', apache_getenv('BAR'));
$this->assertEquals('with spaces', apache_getenv('SPACED'));
$this->assertEquals('pgsql:host=localhost;dbname=test', apache_getenv('EQUALS'));
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::apacheSetenv
+ * @expectedException LogicException
+ * @expectedExceptionMessage Key "FOO" has already been defined in apache_getenv()
*/
- public function testToApacheSetenvException(): void
+ public function testToApacheSetenvException()
{
if (version_compare(PHP_VERSION, '7.0', '<')) {
$this->markTestSkipped('Unable to mock bare php functions');
}
+ $this->compatibleSetUp();
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('Key "FOO" has already been defined in apache_getenv()');
+ }
+
$apacheGetenv = $this->getFunctionMock(__NAMESPACE__, 'apache_getenv');
$apacheGetenv->expects($this->any())->willReturnCallback(
function ($key) {
@@ -690,23 +958,31 @@ function ($key, $value) {
}
);
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('Key "FOO" has already been defined in apache_getenv()');
$this->Loader->parse();
$this->Loader->apacheSetenv(false);
$this->Loader->apacheSetenv(false);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::apacheSetenv
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::skipExisting
* @covers \josegonzalez\Dotenv\Loader::putenv
*/
- public function testToApacheSetenvPreserveZeros(): void
+ public function testToApacheSetenvPreserveZeros()
{
if (version_compare(PHP_VERSION, '7.0', '<')) {
$this->markTestSkipped('Unable to mock bare php functions');
}
+ $this->compatibleSetUp();
$apacheGetenv = $this->getFunctionMock(__NAMESPACE__, 'apache_getenv');
$apacheGetenv->expects($this->any())->willReturnCallback(
function ($key) {
@@ -737,13 +1013,21 @@ function ($key, $value) {
$this->assertEquals('', apache_getenv('Z_BOOL'));
$this->assertEquals('', apache_getenv('Z_STRING'));
$this->assertEquals('', apache_getenv('Z_NULLABLE'));
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::define
*/
- public function testDefine(): void
+ public function testDefine()
{
+ $this->compatibleSetUp();
$this->Loader->parse();
$this->Loader->define();
@@ -751,13 +1035,22 @@ public function testDefine(): void
$this->assertEquals('baz', BAR);
$this->assertEquals('with spaces', SPACED);
$this->assertEquals('pgsql:host=localhost;dbname=test', EQUALS);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::skipExisting
* @covers \josegonzalez\Dotenv\Loader::define
*/
- public function testDefineSkip(): void
+ public function testDefineSkip()
{
+ $this->compatibleSetUp();
$this->Loader->parse();
$this->Loader->skipExisting('define');
$this->Loader->define();
@@ -766,24 +1059,45 @@ public function testDefineSkip(): void
$this->assertEquals('baz', BAR);
$this->assertEquals('with spaces', SPACED);
$this->assertEquals('pgsql:host=localhost;dbname=test', EQUALS);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::define
+ * @expectedException LogicException
+ * @expectedExceptionMessage Key "FOO" has already been defined
*/
- public function testDefineException(): void
+ public function testDefineException()
{
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('Key "FOO" has already been defined');
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('Key "FOO" has already been defined');
+ }
+ $this->compatibleSetUp();
$this->Loader->parse();
$this->Loader->define();
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::putenv
*/
- public function testToPutenv(): void
+ public function testToPutenv()
{
+ $this->compatibleSetUp();
$this->Loader->parse();
$this->Loader->putenv(false);
@@ -791,13 +1105,22 @@ public function testToPutenv(): void
$this->assertEquals('baz', getenv('BAR'));
$this->assertEquals('with spaces', getenv('SPACED'));
$this->assertEquals('pgsql:host=localhost;dbname=test', getenv('EQUALS'));
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::skipExisting
* @covers \josegonzalez\Dotenv\Loader::putenv
*/
- public function testToPutenvSkip(): void
+ public function testToPutenvSkip()
{
+ $this->compatibleSetUp();
$this->Loader->parse();
$this->Loader->skipExisting('putenv');
$this->Loader->putenv(false);
@@ -807,25 +1130,47 @@ public function testToPutenvSkip(): void
$this->assertEquals('baz', getenv('BAR'));
$this->assertEquals('with spaces', getenv('SPACED'));
$this->assertEquals('pgsql:host=localhost;dbname=test', getenv('EQUALS'));
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::putenv
+ * @expectedException LogicException
+ * @expectedExceptionMessage Key "FOO" has already been defined in getenv()
*/
- public function testToPutenvException(): void
+ public function testToPutenvException()
{
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('Key "FOO" has already been defined in getenv()');
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('Key "FOO" has already been defined in getenv()');
+ }
+ $this->compatibleSetUp();
$this->Loader->parse();
$this->Loader->putenv(false);
$this->Loader->putenv(false);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::skipExisting
* @covers \josegonzalez\Dotenv\Loader::putenv
*/
- public function testToPutenvPreserveZeros(): void
+ public function testToPutenvPreserveZeros()
{
+ $this->compatibleSetUp();
$this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env');
$this->Loader->parse();
$this->Loader->putenv(false);
@@ -839,13 +1184,21 @@ public function testToPutenvPreserveZeros(): void
$this->assertEquals('', getenv('Z_BOOL'));
$this->assertEquals('', getenv('Z_STRING'));
$this->assertEquals('', getenv('Z_NULLABLE'));
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::toEnv
*/
- public function testToEnv(): void
+ public function testToEnv()
{
+ $this->compatibleSetUp();
$this->Loader->parse();
$this->Loader->toEnv(false);
@@ -853,13 +1206,22 @@ public function testToEnv(): void
$this->assertEquals('baz', $_ENV['BAR']);
$this->assertEquals('with spaces', $_ENV['SPACED']);
$this->assertEquals('pgsql:host=localhost;dbname=test', $_ENV['EQUALS']);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::skipExisting
* @covers \josegonzalez\Dotenv\Loader::toEnv
*/
- public function testToEnvSkip(): void
+ public function testToEnvSkip()
{
+ $this->compatibleSetUp();
$this->Loader->parse();
$this->Loader->skipExisting('toEnv');
$this->Loader->toEnv(false);
@@ -869,25 +1231,47 @@ public function testToEnvSkip(): void
$this->assertEquals('baz', $_ENV['BAR']);
$this->assertEquals('with spaces', $_ENV['SPACED']);
$this->assertEquals('pgsql:host=localhost;dbname=test', $_ENV['EQUALS']);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::toEnv
+ * @expectedException LogicException
+ * @expectedExceptionMessage Key "FOO" has already been defined in $_ENV
*/
- public function testToEnvException(): void
+ public function testToEnvException()
{
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('Key "FOO" has already been defined in $_ENV');
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('Key "FOO" has already been defined in $_ENV');
+ }
+ $this->compatibleSetUp();
$this->Loader->parse();
$this->Loader->toEnv(false);
$this->Loader->toEnv(false);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::skipExisting
* @covers \josegonzalez\Dotenv\Loader::toEnv
*/
- public function testToEnvPreserveZeros(): void
+ public function testToEnvPreserveZeros()
{
+ $this->compatibleSetUp();
$this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env');
$this->Loader->parse();
$this->Loader->toEnv(false);
@@ -901,13 +1285,21 @@ public function testToEnvPreserveZeros(): void
$this->assertEquals(false, $_ENV['Z_BOOL']);
$this->assertEquals('', $_ENV['Z_STRING']);
$this->assertEquals(null, $_ENV['Z_NULLABLE']);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::toServer
*/
- public function testToServer(): void
+ public function testToServer()
{
+ $this->compatibleSetUp();
$this->Loader->parse();
$this->Loader->toServer(false);
@@ -915,13 +1307,22 @@ public function testToServer(): void
$this->assertEquals('baz', $_SERVER['BAR']);
$this->assertEquals('with spaces', $_SERVER['SPACED']);
$this->assertEquals('pgsql:host=localhost;dbname=test', $_SERVER['EQUALS']);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::skipExisting
* @covers \josegonzalez\Dotenv\Loader::toServer
*/
- public function testToServerSkip(): void
+ public function testToServerSkip()
{
+ $this->compatibleSetUp();
$this->Loader->parse();
$this->Loader->skipExisting('toServer');
$this->Loader->toServer(false);
@@ -931,25 +1332,47 @@ public function testToServerSkip(): void
$this->assertEquals('baz', $_SERVER['BAR']);
$this->assertEquals('with spaces', $_SERVER['SPACED']);
$this->assertEquals('pgsql:host=localhost;dbname=test', $_SERVER['EQUALS']);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::toServer
+ * @expectedException LogicException
+ * @expectedExceptionMessage Key "FOO" has already been defined in $_SERVER
*/
- public function testToServerException(): void
+ public function testToServerException()
{
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('Key "FOO" has already been defined in $_SERVER');
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('Key "FOO" has already been defined in $_SERVER');
+ }
+ $this->compatibleSetUp();
$this->Loader->parse();
$this->Loader->toServer(false);
$this->Loader->toServer(false);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::skipExisting
* @covers \josegonzalez\Dotenv\Loader::toServer
*/
- public function testToServerPreserveZeros(): void
+ public function testToServerPreserveZeros()
{
+ $this->compatibleSetUp();
$this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env');
$this->Loader->parse();
$this->Loader->toServer(false);
@@ -963,32 +1386,40 @@ public function testToServerPreserveZeros(): void
$this->assertEquals(false, $_SERVER['Z_BOOL']);
$this->assertEquals('', $_SERVER['Z_STRING']);
$this->assertEquals(null, $_SERVER['Z_NULLABLE']);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::skipped
* @covers \josegonzalez\Dotenv\Loader::skipExisting
*/
- public function testSkipExisting(): void
+ public function testSkipExisting()
{
- $this->assertEquals([], $this->Loader->skipped());
+ $this->compatibleSetUp();
+ $this->assertEquals(array(), $this->Loader->skipped());
$this->Loader->skipExisting('toEnv');
- $this->assertEquals(['toEnv'], $this->Loader->skipped());
+ $this->assertEquals(array('toEnv'), $this->Loader->skipped());
- $this->Loader->skipExisting(['toEnv']);
- $this->assertEquals(['toEnv'], $this->Loader->skipped());
+ $this->Loader->skipExisting(array('toEnv'));
+ $this->assertEquals(array('toEnv'), $this->Loader->skipped());
$this->Loader->skipExisting();
- $this->assertEquals(['apacheSetenv', 'define', 'putenv', 'toEnv', 'toServer'], $this->Loader->skipped());
+ $this->assertEquals(array('apacheSetenv', 'define', 'putenv', 'toEnv', 'toServer'), $this->Loader->skipped());
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::prefix
* @covers \josegonzalez\Dotenv\Loader::prefixed
*/
- public function testPrefix(): void
+ public function testPrefix()
{
+ $this->compatibleSetUp();
$this->assertEquals('KEY', $this->Loader->prefixed('KEY'));
$this->Loader->prefix('PREFIX_');
@@ -996,161 +1427,238 @@ public function testPrefix(): void
$this->Loader->prefix('PREFIX_TWO_');
$this->assertEquals('PREFIX_TWO_KEY', $this->Loader->prefixed('KEY'));
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::toArray
*/
- public function testToArray(): void
+ public function testToArray()
{
+ $this->compatibleSetUp();
$this->Loader->parse();
- $this->assertEquals([
+ $this->assertEquals(array(
'FOO' => 'bar',
'BAR' => 'baz',
'SPACED' => 'with spaces',
'EQUALS' => 'pgsql:host=localhost;dbname=test',
- ], $this->Loader->toArray());
+ ), $this->Loader->toArray());
+ $this->compatibleTearDown();
}
/**
- * @covers \josegonzalez\Dotenv\Loader::toArray With no parsing done yet.
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::toArray
+ * @expectedException LogicException
+ * @expectedExceptionMessage Environment must be parsed before calling toArray()
*/
- public function testToArrayRequireParse(): void
+ public function testToArrayRequireParse()
{
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('Environment must be parsed before calling toArray()');
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('Environment must be parsed before calling toArray()');
+ }
+ $this->compatibleSetUp();
$this->Loader->toArray();
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::toArray
* @covers \josegonzalez\Dotenv\Loader::__toString
*/
- public function testToString(): void
+ public function testToString()
{
+ $this->compatibleSetUp();
$this->assertEquals('[]', $this->Loader->__toString());
$this->Loader->parse();
- // phpcs error: | WARNING | Line exceeds 120 characters; contains 153 characters
- $this->assertEquals('{"FOO":"bar","BAR":"baz","SPACED":"with spaces",' .
- '"EQUALS":"pgsql:host=localhost;dbname=test"}', $this->Loader->__toString());
+ $this->assertEquals('{"FOO":"bar","BAR":"baz","SPACED":"with spaces","EQUALS":"pgsql:host=localhost;dbname=test"}', $this->Loader->__toString());
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::requireParse
*/
- public function testRequireParse(): void
+ public function testRequireParse()
{
- $this->expectNotToPerformAssertions();
+ $this->compatibleSetUp();
$this->Loader->parse();
- $this->protectedMethodCall($this->Loader, 'requireParse', ['toEnv']);
+ $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv'));
+ $this->assertSame(true, true);
+ $this->compatibleTearDown();
}
/**
- * @covers \josegonzalez\Dotenv\Loader::requireParse With no parsing done yet.
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @expectedException LogicException
+ * @expectedExceptionMessage Environment must be parsed before calling toEnv()
*/
- public function testRequireParseException(): void
+ public function testRequireParseException()
{
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('Environment must be parsed before calling toEnv()');
- $this->protectedMethodCall($this->Loader, 'requireParse', ['toEnv']);
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('Environment must be parsed before calling toEnv()');
+ }
+ $this->compatibleSetUp();
+ $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv'));
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::raiseExceptions
*/
- public function testRequireParseNoException(): void
+ public function testRequireParseNoException()
{
- $this->expectNotToPerformAssertions();
+ $this->compatibleSetUp();
$this->Loader->raiseExceptions(false);
- $this->protectedMethodCall($this->Loader, 'requireParse', ['toEnv']);
+ $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv'));
+ $this->assertSame(true, true);
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::raise
+ * @expectedException LogicException
+ * @expectedExceptionMessage derp
*/
- public function testRaise(): void
+ public function testRaise()
{
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('derp');
- $this->protectedMethodCall($this->Loader, 'raise', ['LogicException', 'derp']);
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('derp');
+ }
+ $this->compatibleSetUp();
+ $this->protectedMethodCall($this->Loader, 'raise', array('LogicException', 'derp'));
+ $this->compatibleTearDown();
}
/**
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
* @covers \josegonzalez\Dotenv\Loader::raiseExceptions
* @covers \josegonzalez\Dotenv\Loader::raise
*/
- public function testRaiseNoException(): void
+ public function testRaiseNoException()
{
- $this->expectNotToPerformAssertions();
+ $this->compatibleSetUp();
$this->Loader->raiseExceptions(false);
- $this->protectedMethodCall($this->Loader, 'raise', ['LogicException', 'derp']);
+ $this->protectedMethodCall($this->Loader, 'raise', array('LogicException', 'derp'));
+ $this->assertSame(true, true);
+ $this->compatibleTearDown();
}
- public function testStatic(): void
+ /**
+ * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::__invoke
+ * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::get
+ * @covers \josegonzalez\Dotenv\Loader::__construct
+ * @covers \josegonzalez\Dotenv\Loader::filepaths
+ * @covers \josegonzalez\Dotenv\Loader::filter
+ * @covers \josegonzalez\Dotenv\Loader::parse
+ * @covers \josegonzalez\Dotenv\Loader::prefix
+ * @covers \josegonzalez\Dotenv\Loader::prefixed
+ * @covers \josegonzalez\Dotenv\Loader::raise
+ * @covers \josegonzalez\Dotenv\Loader::raiseExceptions
+ * @covers \josegonzalez\Dotenv\Loader::requireParse
+ * @covers \josegonzalez\Dotenv\Loader::setFilepaths
+ * @covers \josegonzalez\Dotenv\Loader::setFilters
+ * @covers \josegonzalez\Dotenv\Loader::load
+ * @covers \josegonzalez\Dotenv\Loader::toArray
+ */
+ public function testStatic()
{
- $dotenv = Loader::load([
+ $this->compatibleSetUp();
+ $dotenv = Loader::load(array(
'raiseExceptions' => false
- ]);
+ ));
$this->assertNull($dotenv->toArray());
$dotenv = Loader::load($this->fixturePath . '.env');
- $this->assertEquals([
+ $this->assertEquals(array(
'FOO' => 'bar',
'BAR' => 'baz',
'SPACED' => 'with spaces',
'EQUALS' => 'pgsql:host=localhost;dbname=test',
- ], $dotenv->toArray());
+ ), $dotenv->toArray());
- $dotenv = Loader::load([
+ $dotenv = Loader::load(array(
'filepath' => $this->fixturePath . '.env',
- ]);
- $this->assertEquals([
+ ));
+ $this->assertEquals(array(
'FOO' => 'bar',
'BAR' => 'baz',
'SPACED' => 'with spaces',
'EQUALS' => 'pgsql:host=localhost;dbname=test',
- ], $dotenv->toArray());
+ ), $dotenv->toArray());
- $dotenv = Loader::load([
- 'filepaths' => [$this->fixturePath . '.env'],
- ]);
- $this->assertEquals([
+ $dotenv = Loader::load(array(
+ 'filepaths' => array($this->fixturePath . '.env'),
+ ));
+ $this->assertEquals(array(
'FOO' => 'bar',
'BAR' => 'baz',
'SPACED' => 'with spaces',
'EQUALS' => 'pgsql:host=localhost;dbname=test',
- ], $dotenv->toArray());
+ ), $dotenv->toArray());
- $dotenv = Loader::load([
- 'raiseExceptions' => true,
- 'filepaths' => [
+ $dotenv = Loader::load(array(
+ 'filepaths' => array(
$this->fixturePath . '.env.nonexistent',
$this->fixturePath . '.env',
- ],
- ]);
- $this->assertEquals([
+ ),
+ ));
+ $this->assertEquals(array(
'FOO' => 'bar',
'BAR' => 'baz',
'SPACED' => 'with spaces',
'EQUALS' => 'pgsql:host=localhost;dbname=test',
- ], $dotenv->toArray());
+ ), $dotenv->toArray());
- $dotenv = Loader::load([
+ $dotenv = Loader::load(array(
'filepath' => $this->fixturePath . '.env',
'prefix' => 'PREFIX_'
- ]);
- $this->assertEquals([
+ ));
+ $this->assertEquals(array(
'PREFIX_FOO' => 'bar',
'PREFIX_BAR' => 'baz',
'PREFIX_SPACED' => 'with spaces',
'PREFIX_EQUALS' => 'pgsql:host=localhost;dbname=test',
- ], $dotenv->toArray());
+ ), $dotenv->toArray());
- $dotenv = Loader::load([
+ $dotenv = Loader::load(array(
'filepath' => $this->fixturePath . 'url_parse_filter.env',
- 'filters' => ['josegonzalez\Dotenv\Filter\UrlParseFilter'],
- ]);
- $this->assertSame([
+ 'filters' => array('josegonzalez\Dotenv\Filter\UrlParseFilter'),
+ ));
+ $this->assertSame(array(
'READ_DATABASE_URL' => 'mysql://user:password@localhost/database_name?encoding=utf8',
'READ_DATABASE_SCHEME' => 'mysql',
'READ_DATABASE_HOST' => 'localhost',
@@ -1169,7 +1677,8 @@ public function testStatic(): void
'DATABASE_PATH' => '/database_name',
'DATABASE_QUERY' => 'encoding=utf8',
'DATABASE_FRAGMENT' => '',
- ], $dotenv->toArray());
+ ), $dotenv->toArray());
+ $this->compatibleTearDown();
}
/**
@@ -1177,10 +1686,10 @@ public function testStatic(): void
*
* @param object $obj object
* @param string $name method to call
- * @param array $args arguments to pass to the method
+ * @param array $args arguments to pass to the method
* @return mixed
*/
- public function protectedMethodCall(object $obj, string $name, array $args = [])
+ public function protectedMethodCall($obj, $name, array $args)
{
$class = new \ReflectionClass($obj);
$method = $class->getMethod($name);
diff --git a/tmp/.gitkeep b/tmp/.gitkeep
new file mode 100644
index 0000000..e69de29