From a51f4df53e1cb0d60b465cdea1ee1befc920b354 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 9 Jun 2022 09:25:08 +0900 Subject: [PATCH] Update core git config files, vendor installs for unit testing Update .gitattributes with more files to ignore Add .gitignore for php unit test cache Install dotenv file parser for unit testing Update current test pages with dotenv file parser (replaces function call) Documentation PHPdoc update for checkMe method call --- .gitattributes | 3 +- .gitignore | 1 + composer.json | 3 +- composer.lock | 58 ++++++- psalm.xml | 2 +- src/AmazonIncentives.php | 4 + test/aws_gift_card_tests.php | 10 +- test/aws_read_env_tests.php | 23 +++ test/read_env_file.php | 84 ---------- vendor/composer/autoload_psr4.php | 1 + vendor/composer/autoload_static.php | 5 + vendor/composer/installed.json | 56 +++++++ vendor/composer/installed.php | 15 +- vendor/gullevek/dotenv/.gitignore | 3 + vendor/gullevek/dotenv/.phan/config.php | 97 ++++++++++++ vendor/gullevek/dotenv/Readme.md | 50 ++++++ vendor/gullevek/dotenv/composer.json | 30 ++++ vendor/gullevek/dotenv/phpstan.neon | 10 ++ vendor/gullevek/dotenv/phpunit.xml | 5 + vendor/gullevek/dotenv/psalm.xml | 16 ++ vendor/gullevek/dotenv/src/DotEnv.php | 99 ++++++++++++ vendor/gullevek/dotenv/test/.env.example | 4 + .../dotenv/test/phpUnitTests/DotEnvTest.php | 144 ++++++++++++++++++ .../test/phpUnitTests/dotenv/cannot_read.env | 0 .../dotenv/test/phpUnitTests/dotenv/empty.env | 0 .../dotenv/test/phpUnitTests/dotenv/test.env | 28 ++++ vendor/gullevek/dotenv/test/read_env_file.php | 17 +++ 27 files changed, 672 insertions(+), 96 deletions(-) create mode 100644 .gitignore create mode 100644 test/aws_read_env_tests.php delete mode 100644 test/read_env_file.php create mode 100644 vendor/gullevek/dotenv/.gitignore create mode 100644 vendor/gullevek/dotenv/.phan/config.php create mode 100644 vendor/gullevek/dotenv/Readme.md create mode 100644 vendor/gullevek/dotenv/composer.json create mode 100644 vendor/gullevek/dotenv/phpstan.neon create mode 100644 vendor/gullevek/dotenv/phpunit.xml create mode 100644 vendor/gullevek/dotenv/psalm.xml create mode 100644 vendor/gullevek/dotenv/src/DotEnv.php create mode 100644 vendor/gullevek/dotenv/test/.env.example create mode 100644 vendor/gullevek/dotenv/test/phpUnitTests/DotEnvTest.php create mode 100644 vendor/gullevek/dotenv/test/phpUnitTests/dotenv/cannot_read.env create mode 100644 vendor/gullevek/dotenv/test/phpUnitTests/dotenv/empty.env create mode 100644 vendor/gullevek/dotenv/test/phpUnitTests/dotenv/test.env create mode 100644 vendor/gullevek/dotenv/test/read_env_file.php diff --git a/.gitattributes b/.gitattributes index f6bac5e..bde73f2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ test/ export-ignore -.gitattributes export-ignore phpstan.neon export-ignore +phpunit.xml export-ignore psalm.xml export-ignore .phan/ export-ignore +.* export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..165765a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.phpunit.result.cache diff --git a/composer.json b/composer.json index 84f02b1..f394442 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "exclude": ["/test/", "/test/*", "/phpstan.neon", "/psalm.xml", "/.phan/", "/.vscode/", "/phpunit.xml"] }, "require-dev": { - "phpunit/phpunit": "^9" + "phpunit/phpunit": "^9", + "gullevek/dotenv": "dev-master" } } diff --git a/composer.lock b/composer.lock index 6fec28b..6e9b29e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "575af90859cb670cec82630ae7426112", + "content-hash": "412ca7fe7d62707c222169f4a7deeaec", "packages": [], "packages-dev": [ { @@ -77,6 +77,58 @@ ], "time": "2022-03-03T08:28:38+00:00" }, + { + "name": "gullevek/dotenv", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/gullevek/dotEnv.git", + "reference": "2c7931b7a57f992f9010fc7d9c58af8951f1dc24" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/gullevek/dotEnv/zipball/2c7931b7a57f992f9010fc7d9c58af8951f1dc24", + "reference": "2c7931b7a57f992f9010fc7d9c58af8951f1dc24", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^9" + }, + "default-branch": true, + "type": "library", + "autoload": { + "psr-4": { + "gullevek\\dotEnv\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Clemens Schwaighofer", + "email": "gullevek@gullevek.org", + "homepage": "http://gullevek.org" + } + ], + "description": "Simple .env file processing and storing in _ENV array", + "homepage": "https://github.com/gullevek/dotEnv", + "keywords": [ + ".env", + "_ENV", + "dotenv", + "environment variables" + ], + "support": { + "issues": "https://github.com/gullevek/dotEnv/issues", + "source": "https://github.com/gullevek/dotEnv/tree/v2.0.1" + }, + "time": "2022-06-08T05:12:35+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.x-dev", @@ -2037,7 +2089,9 @@ ], "aliases": [], "minimum-stability": "dev", - "stability-flags": [], + "stability-flags": { + "gullevek/dotenv": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/psalm.xml b/psalm.xml index 2b10313..83bb767 100644 --- a/psalm.xml +++ b/psalm.xml @@ -7,7 +7,7 @@ xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" > - + diff --git a/src/AmazonIncentives.php b/src/AmazonIncentives.php index 4cf19f1..692aa5d 100644 --- a/src/AmazonIncentives.php +++ b/src/AmazonIncentives.php @@ -137,6 +137,10 @@ final class AmazonIncentives // ********************************************************************* /** + * Prints out ENV, CONFIG and KEY data + * This is for debug only, this will print out secrets. + * Use with care + * * @return array */ public function checkMe(): array diff --git a/test/aws_gift_card_tests.php b/test/aws_gift_card_tests.php index f3ebe60..921dedc 100644 --- a/test/aws_gift_card_tests.php +++ b/test/aws_gift_card_tests.php @@ -57,13 +57,12 @@ $loader = require '../vendor/autoload.php'; // need to add this or it will not load here $loader->addPsr4('gullevek\\', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src'); // print "LOADER:
" . print_r($loader, true) . "
"; -// env file loader (simple) -require 'read_env_file.php'; use gullevek\AmazonIncentives\AmazonIncentives; +use gullevek\dotEnv\DotEnv; // load env data with dotenv -__readEnvFile(__DIR__); +DotEnv::readEnvFile(__DIR__); print "

Amazon Gift Card Incentives


"; @@ -102,8 +101,9 @@ $mock_wait = 2; if ($run_info_test === true) { $aws = new AmazonIncentives(); - print "checkMe:
" . print_r($aws->checkMe(), true) . "
"; - fwrite($fp, writeLog($aws->checkMe())); + $aws_check_me = $aws->checkMe(); + print "checkMe:
" . print_r($aws_check_me, true) . "
"; + fwrite($fp, writeLog($aws_check_me)); print "
"; } diff --git a/test/aws_read_env_tests.php b/test/aws_read_env_tests.php new file mode 100644 index 0000000..756b1b3 --- /dev/null +++ b/test/aws_read_env_tests.php @@ -0,0 +1,23 @@ +addPsr4('gullevek\\', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src'); +// print "LOADER:
" . print_r($loader, true) . "
"; + +use gullevek\AmazonIncentives\AmazonIncentives; +use gullevek\dotEnv\DotEnv; + +// load env data with dotenv +DotEnv::readEnvFile(__DIR__); + +print "_ENV:
" . print_r($_ENV, true) . "
"; + +$aws = new AmazonIncentives(); +print "checkMe:
" . print_r($aws->checkMe(), true) . "
"; + +// __END__ diff --git a/test/read_env_file.php b/test/read_env_file.php deleted file mode 100644 index b6b2715..0000000 --- a/test/read_env_file.php +++ /dev/null @@ -1,84 +0,0 @@ - abort - if (!is_file($env_file_target)) { - $status = 3; - return $status; - } - // cannot open file -> abort - if (($fp = fopen($env_file_target, 'r')) === false) { - $status = 2; - return $status; - } - // set to readable but not yet any data loaded - $status = 1; - $block = false; - $var = ''; - while ($line = fgets($fp)) { - // main match for variable = value part - if (preg_match("/^\s*([\w_.]+)\s*=\s*((\"?).*)/", $line, $matches)) { - $var = $matches[1]; - $value = $matches[2]; - $quotes = $matches[3]; - // wirte only if env is not set yet, and write only the first time - if (empty($_ENV[$var])) { - if (!empty($quotes)) { - // match greedy for first to last so we move any " if there are - if (preg_match('/^"(.*[^\\\])"/U', $value, $matches)) { - $value = $matches[1]; - } else { - // this is a multi line - $block = true; - // first " in string remove - // add removed new line back because this is a multi line - $value = ltrim($value, '"') . PHP_EOL; - } - } - // if block is set, we strip line of slashes - $_ENV[$var] = $block === true ? stripslashes($value) : $value; - // set successful load - $status = 0; - } - } elseif ($block === true) { - // read line until there is a unescaped " - // this also strips everything after the last " - if (preg_match("/(.*[^\\\])\"/", $line, $matches)) { - $block = false; - // strip ending " and EVERYTHING that follows after that - $line = $matches[1]; - } - // strip line of slashes - $_ENV[$var] .= stripslashes($line); - } - } - fclose($fp); - return $status; -} - -// __END__ diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index 2593e17..5f135ec 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -7,6 +7,7 @@ $baseDir = dirname($vendorDir); return array( 'phpDocumentor\\Reflection\\' => array($vendorDir . '/phpdocumentor/reflection-common/src', $vendorDir . '/phpdocumentor/reflection-docblock/src', $vendorDir . '/phpdocumentor/type-resolver/src'), + 'gullevek\\dotEnv\\' => array($vendorDir . '/gullevek/dotenv/src'), 'gullevek\\AmazonIncentives\\' => array($baseDir . '/src'), 'Webmozart\\Assert\\' => array($vendorDir . '/webmozart/assert/src'), 'Prophecy\\' => array($vendorDir . '/phpspec/prophecy/src/Prophecy'), diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index ae16e8c..5211bf2 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -18,6 +18,7 @@ class ComposerStaticInit0c8f6bec90a6d60040a922f19a1f0e64 ), 'g' => array ( + 'gullevek\\dotEnv\\' => 16, 'gullevek\\AmazonIncentives\\' => 26, ), 'W' => @@ -43,6 +44,10 @@ class ComposerStaticInit0c8f6bec90a6d60040a922f19a1f0e64 1 => __DIR__ . '/..' . '/phpdocumentor/reflection-docblock/src', 2 => __DIR__ . '/..' . '/phpdocumentor/type-resolver/src', ), + 'gullevek\\dotEnv\\' => + array ( + 0 => __DIR__ . '/..' . '/gullevek/dotenv/src', + ), 'gullevek\\AmazonIncentives\\' => array ( 0 => __DIR__ . '/../..' . '/src', diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 86cee4f..e286566 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -73,6 +73,61 @@ ], "install-path": "../doctrine/instantiator" }, + { + "name": "gullevek/dotenv", + "version": "dev-master", + "version_normalized": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/gullevek/dotEnv.git", + "reference": "2c7931b7a57f992f9010fc7d9c58af8951f1dc24" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/gullevek/dotEnv/zipball/2c7931b7a57f992f9010fc7d9c58af8951f1dc24", + "reference": "2c7931b7a57f992f9010fc7d9c58af8951f1dc24", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^9" + }, + "time": "2022-06-08T05:12:35+00:00", + "default-branch": true, + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "gullevek\\dotEnv\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Clemens Schwaighofer", + "email": "gullevek@gullevek.org", + "homepage": "http://gullevek.org" + } + ], + "description": "Simple .env file processing and storing in _ENV array", + "homepage": "https://github.com/gullevek/dotEnv", + "keywords": [ + ".env", + "_ENV", + "dotenv", + "environment variables" + ], + "support": { + "issues": "https://github.com/gullevek/dotEnv/issues", + "source": "https://github.com/gullevek/dotEnv/tree/v2.0.1" + }, + "install-path": "../gullevek/dotenv" + }, { "name": "myclabs/deep-copy", "version": "1.x-dev", @@ -2130,6 +2185,7 @@ "dev": true, "dev-package-names": [ "doctrine/instantiator", + "gullevek/dotenv", "myclabs/deep-copy", "nikic/php-parser", "phar-io/manifest", diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index fef5a0f..6c0a3e5 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -5,7 +5,7 @@ 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), - 'reference' => '5b99da616b048dd9f0d9bd0672992d27b882a36c', + 'reference' => '1e836e9a2bd6e41c4555cf917fe645b453cb5b79', 'name' => 'gullevek/amazon-incentives', 'dev' => true, ), @@ -25,9 +25,20 @@ 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), - 'reference' => '5b99da616b048dd9f0d9bd0672992d27b882a36c', + 'reference' => '1e836e9a2bd6e41c4555cf917fe645b453cb5b79', 'dev_requirement' => false, ), + 'gullevek/dotenv' => array( + 'pretty_version' => 'dev-master', + 'version' => 'dev-master', + 'type' => 'library', + 'install_path' => __DIR__ . '/../gullevek/dotenv', + 'aliases' => array( + 0 => '9999999-dev', + ), + 'reference' => '2c7931b7a57f992f9010fc7d9c58af8951f1dc24', + 'dev_requirement' => true, + ), 'myclabs/deep-copy' => array( 'pretty_version' => '1.x-dev', 'version' => '1.9999999.9999999.9999999-dev', diff --git a/vendor/gullevek/dotenv/.gitignore b/vendor/gullevek/dotenv/.gitignore new file mode 100644 index 0000000..d769eb5 --- /dev/null +++ b/vendor/gullevek/dotenv/.gitignore @@ -0,0 +1,3 @@ +vendor +.phpunit.result.cache +composer.lock diff --git a/vendor/gullevek/dotenv/.phan/config.php b/vendor/gullevek/dotenv/.phan/config.php new file mode 100644 index 0000000..87138de --- /dev/null +++ b/vendor/gullevek/dotenv/.phan/config.php @@ -0,0 +1,97 @@ + false, + + // Allow null to be cast as any type and for any + // type to be cast to null. + "null_casts_as_any_type" => false, + + // Backwards Compatibility Checking + 'backward_compatibility_checks' => true, + + // Run a quick version of checks that takes less + // time + "quick_mode" => false, + + // Only emit critical issues to start with + // (0 is low severity, 5 is normal severity, 10 is critical) + "minimum_severity" => 10, + + // default false for include path check + "enable_include_path_checks" => true, + "include_paths" => [ + ], + 'ignore_undeclared_variables_in_global_scope' => true, + + "file_list" => [ + ], + + // A list of directories that should be parsed for class and + // method information. After excluding the directories + // defined in exclude_analysis_directory_list, the remaining + // files will be statically analyzed for errors. + // + // Thus, both first-party and third-party code being used by + // your application should be included in this list. + 'directory_list' => [ + // Change this to include the folders you wish to analyze + // (and the folders of their dependencies) + '.' + // 'www', + // To speed up analysis, we recommend going back later and + // limiting this to only the vendor/ subdirectories your + // project depends on. + // `phan --init` will generate a list of folders for you + ], + + + // A list of directories holding code that we want + // to parse, but not analyze + "exclude_analysis_directory_list" => [ + 'vendor', + 'test' + ], + 'exclude_file_list' => [ + ], + + // what not to show as problem + 'suppress_issue_types' => [ + // 'PhanUndeclaredMethod', + 'PhanEmptyFile', + ], + + // Override to hardcode existence and types of (non-builtin) globals in the global scope. + // Class names should be prefixed with `\`. + // + // (E.g. `['_FOO' => '\FooClass', 'page' => '\PageClass', 'userId' => 'int']`) + 'globals_type_map' => [], +]; diff --git a/vendor/gullevek/dotenv/Readme.md b/vendor/gullevek/dotenv/Readme.md new file mode 100644 index 0000000..1c80ca8 --- /dev/null +++ b/vendor/gullevek/dotenv/Readme.md @@ -0,0 +1,50 @@ +# dotenv: readEnvFile() + +A simple implementation of + +This is not a functional replacement, but a very simple implementation of the basic functions. + +It is recommended to create a `.env.example` example file that is checked into the +repository. The `.env` should *NEVER* be checked into anything + +## How to install + +`comoser require gullevek/dotEnv` + +## How it works + +Put the function where it is needed or put it in a file and load it. + +if not parameter is given it will use `__DIR__` as base path. +Second parameter is file name override. Default is `.env` + +Data is loaded into _ENV only. + +If there is already an entry in _ENV then it will not be overwritten. + +## .env file example + +A valid entry has to start with an alphanumeric string, underscores are allowed and +then have an equal sign (=). After the equal sign the data block starts. Data can be +quoted with double quotes (") and if this is done can stretch over multiple lines. +The openeing double quote must be on the same lign as the requal sign (=). If double +quoted (") charcters are used it will read each line until another double quote (") +character is found. Everything after that is ignored. + +Any spaces before the variable or before and after the equal sign (=) are ignored. + +Line is read until `PHP_EOL`. So any trailing spaces are read too. + +Any line that is not valid is ignored. + +```ini +# this line is ignored +SOMETHING=A +OTHER="A B C" +MULTI_LINE="1 2 3 +4 5 6 +7 8 9" ; and this is ignored +ESCAPE="String \" inside \" other " +DOUBLE="I will be used" +DOUBLE="This will be ignored" +``` diff --git a/vendor/gullevek/dotenv/composer.json b/vendor/gullevek/dotenv/composer.json new file mode 100644 index 0000000..89378f8 --- /dev/null +++ b/vendor/gullevek/dotenv/composer.json @@ -0,0 +1,30 @@ +{ + "name": "gullevek/dotenv", + "description": "Simple .env file processing and storing in _ENV array", + "keywords": [".env", "dotenv", "_ENV", "environment variables"], + "type": "library", + "license": "MIT", + "autoload": { + "psr-4": { + "gullevek\\dotEnv\\": "src/" + } + }, + "authors": [ + { + "name": "Clemens Schwaighofer", + "email": "gullevek@gullevek.org", + "homepage": "http://gullevek.org" + } + ], + "homepage": "https://github.com/gullevek/dotEnv", + "minimum-stability": "dev", + "require": { + "php": ">=7.4.0" + }, + "archive": { + "exclude": ["/test/", "/test/*", "/phpstan.neon", "/psalm.xml", "/.phan/", "/.vscode/", "/phpunit.xml"] + }, + "require-dev": { + "phpunit/phpunit": "^9" + } +} diff --git a/vendor/gullevek/dotenv/phpstan.neon b/vendor/gullevek/dotenv/phpstan.neon new file mode 100644 index 0000000..3802893 --- /dev/null +++ b/vendor/gullevek/dotenv/phpstan.neon @@ -0,0 +1,10 @@ +# PHP Stan Config + +parameters: + tmpDir: /tmp/phpstan-codeblocks-dotenv + level: max + paths: + - %currentWorkingDirectory% + excludePaths: + - vendor + - test diff --git a/vendor/gullevek/dotenv/phpunit.xml b/vendor/gullevek/dotenv/phpunit.xml new file mode 100644 index 0000000..c333bf5 --- /dev/null +++ b/vendor/gullevek/dotenv/phpunit.xml @@ -0,0 +1,5 @@ + + diff --git a/vendor/gullevek/dotenv/psalm.xml b/vendor/gullevek/dotenv/psalm.xml new file mode 100644 index 0000000..5cde799 --- /dev/null +++ b/vendor/gullevek/dotenv/psalm.xml @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/vendor/gullevek/dotenv/src/DotEnv.php b/vendor/gullevek/dotenv/src/DotEnv.php new file mode 100644 index 0000000..bdfa44a --- /dev/null +++ b/vendor/gullevek/dotenv/src/DotEnv.php @@ -0,0 +1,99 @@ + abort + if (!is_file($env_file_target)) { + $status = 3; + return $status; + } + // cannot open file -> abort + if (!is_readable($env_file_target)) { + $status = 2; + return $status; + } + // open file + if (($fp = fopen($env_file_target, 'r')) === false) { + $status = 2; + return $status; + } + // set to readable but not yet any data loaded + $status = 1; + $block = false; + $var = ''; + while ($line = fgets($fp)) { + // main match for variable = value part + if (preg_match("/^\s*([\w_.]+)\s*=\s*((\"?).*)/", $line, $matches)) { + $var = $matches[1]; + $value = $matches[2]; + $quotes = $matches[3]; + // write only if env is not set yet, and write only the first time + if (empty($_ENV[$var])) { + if (!empty($quotes)) { + // match greedy for first to last so we move any " if there are + if (preg_match('/^"(.*[^\\\])"/U', $value, $matches)) { + $value = $matches[1]; + } else { + // this is a multi line + $block = true; + // first " in string remove + // add removed new line back because this is a multi line + $value = ltrim($value, '"') . PHP_EOL; + } + } + // if block is set, we strip line of slashes + $_ENV[$var] = $block === true ? stripslashes($value) : $value; + // set successful load + $status = 0; + } + } elseif ($block === true) { + // read line until there is a unescaped " + // this also strips everything after the last " + if (preg_match("/(.*[^\\\])\"/", $line, $matches)) { + $block = false; + // strip ending " and EVERYTHING that follows after that + $line = $matches[1]; + } + // strip line of slashes + $_ENV[$var] .= stripslashes($line); + } + } + fclose($fp); + return $status; + } +} + + +// __END__ diff --git a/vendor/gullevek/dotenv/test/.env.example b/vendor/gullevek/dotenv/test/.env.example new file mode 100644 index 0000000..95c9b02 --- /dev/null +++ b/vendor/gullevek/dotenv/test/.env.example @@ -0,0 +1,4 @@ +# example enviroment file +SOMETHING= +OTHER= +Complex= diff --git a/vendor/gullevek/dotenv/test/phpUnitTests/DotEnvTest.php b/vendor/gullevek/dotenv/test/phpUnitTests/DotEnvTest.php new file mode 100644 index 0000000..f87ceb6 --- /dev/null +++ b/vendor/gullevek/dotenv/test/phpUnitTests/DotEnvTest.php @@ -0,0 +1,144 @@ + 'A', + 'OTHER' => 'B IS B', + 'Complex' => 'A B \"D is F', + 'HAS_SPACE' => 'ABC', + 'FAILURE' => 'ABC', + 'SIMPLEBOX' => 'A B C', + 'TITLE' => '1', + 'FOO' => '1.2', + 'SOME.TEST' => 'Test Var', + 'SOME.LIVE' => 'Live Var', + 'Test' => 'A', + 'TEST' => 'B', + 'LINE' => "ABC\nDEF", + 'OTHERLINE' => "ABC\nAF\"ASFASDF\nMORESHIT", + 'SUPERLINE' => '', + '__FOO_BAR_1' => 'b', + '__FOOFOO' => 'f ', + 123123 => 'number', + 'EMPTY' => '', + ]; + // 0: folder relative to test folder, if unset __DIR__ + // 1: file, if unset .env + // 2: status to be returned + // 3: _ENV file content to be set + // 4: override chmod as octect in string + return [ + 'default' => [ + 'folder' => null, + 'file' => null, + 'status' => 3, + 'content' => [], + 'chmod' => null, + ], + 'cannot open file' => [ + 'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv', + 'file' => 'cannot_read.env', + 'status' => 2, + 'content' => [], + 'chmod' => '000', + ], + 'empty file' => [ + 'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv', + 'file' => 'empty.env', + 'status' => 1, + 'content' => [], + 'chmod' => null, + ], + 'override all' => [ + 'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv', + 'file' => 'test.env', + 'status' => 0, + 'content' => $dot_env_content, + 'chmod' => null, + ], + 'override directory' => [ + 'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv', + 'file' => null, + 'status' => 0, + 'content' => $dot_env_content, + 'chmod' => null, + ], + ]; + } + + /** + * test read .env file + * + * @covers ::readEnvFile + * @dataProvider envFileProvider + * @testdox Read _ENV file from $folder / $file with expected status: $expected_status [$_dataName] + * + * @param string|null $folder + * @param string|null $file + * @param int $expected_status + * @param array $expected_env + * @param string|null $chmod + * @return void + */ + public function testReadEnvFile( + ?string $folder, + ?string $file, + int $expected_status, + array $expected_env, + ?string $chmod + ): void { + // if we have file + chmod set + $old_chmod = null; + if ( + is_file($folder . DIRECTORY_SEPARATOR . $file) && + !empty($chmod) + ) { + // get the old permissions + $old_chmod = fileperms($folder . DIRECTORY_SEPARATOR . $file); + chmod($folder . DIRECTORY_SEPARATOR . $file, octdec($chmod)); + } + if ($folder !== null && $file !== null) { + $status = \gullevek\dotEnv\DotEnv::readEnvFile($folder, $file); + } elseif ($folder !== null) { + $status = \gullevek\dotEnv\DotEnv::readEnvFile($folder); + } else { + $status = \gullevek\dotEnv\DotEnv::readEnvFile(); + } + $this->assertEquals( + $status, + $expected_status, + 'Assert returned status equal' + ); + // now assert read data + $this->assertEquals( + $_ENV, + $expected_env, + 'Assert _ENV correct' + ); + // if we have file and chmod unset + if ($old_chmod !== null) { + chmod($folder . DIRECTORY_SEPARATOR . $file, $old_chmod); + } + } +} + +// __END__ diff --git a/vendor/gullevek/dotenv/test/phpUnitTests/dotenv/cannot_read.env b/vendor/gullevek/dotenv/test/phpUnitTests/dotenv/cannot_read.env new file mode 100644 index 0000000..e69de29 diff --git a/vendor/gullevek/dotenv/test/phpUnitTests/dotenv/empty.env b/vendor/gullevek/dotenv/test/phpUnitTests/dotenv/empty.env new file mode 100644 index 0000000..e69de29 diff --git a/vendor/gullevek/dotenv/test/phpUnitTests/dotenv/test.env b/vendor/gullevek/dotenv/test/phpUnitTests/dotenv/test.env new file mode 100644 index 0000000..43f8e33 --- /dev/null +++ b/vendor/gullevek/dotenv/test/phpUnitTests/dotenv/test.env @@ -0,0 +1,28 @@ +# enviroment file +SOMETHING=A +OTHER="B IS B" +Complex="A B \"D is F" +# COMMENT +HAS_SPACE= "ABC"; +FAILURE = ABC +SIMPLEBOX= A B C +TITLE=1 +FOO=1.2 +SOME.TEST=Test Var +SOME.LIVE=Live Var +Test="A" +TEST="B" +TEST="D" +LINE="ABC +DEF" +OTHERLINE="ABC +AF\"ASFASDF +MORESHIT" +SUPERLINE= +"asfasfasf" + __FOO_BAR_1 = b + __FOOFOO = f +123123=number +EMPTY= += flase +asfasdf diff --git a/vendor/gullevek/dotenv/test/read_env_file.php b/vendor/gullevek/dotenv/test/read_env_file.php new file mode 100644 index 0000000..fb85909 --- /dev/null +++ b/vendor/gullevek/dotenv/test/read_env_file.php @@ -0,0 +1,17 @@ +addPsr4('gullevek\\', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src'); +use gullevek\dotEnv\DotEnv; + +print "BASE: " . __DIR__ . "
"; +print "ORIG:
" . file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '.env') . "
"; + +$status = DotEnv::readEnvFile(__DIR__); + +print "STATUS: " . (string)$status . "
"; +print "ENV:
" . print_r($_ENV, true) . "

"; + +// __END__