diff --git a/Readme.md b/Readme.md
index 3dac56c..b735f53 100644
--- a/Readme.md
+++ b/Readme.md
@@ -60,3 +60,9 @@ ESCAPE="String \" inside \" other "
DOUBLE="I will be used"
DOUBLE="This will be ignored"
```
+
+## Development
+
+Unit tests have to be run from base folder with
+
+`vendor/bin/phpunit test/phpUnitTests/`
diff --git a/test/.env b/test/.env
deleted file mode 120000
index 8bc5673..0000000
--- a/test/.env
+++ /dev/null
@@ -1 +0,0 @@
-phpUnitTests/dotenv/test.env
\ No newline at end of file
diff --git a/test/env/.gitignore b/test/env/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/test/phpUnitTests/DotEnvTest.php b/test/phpUnitTests/DotEnvTest.php
index 11296fd..00e5910 100644
--- a/test/phpUnitTests/DotEnvTest.php
+++ b/test/phpUnitTests/DotEnvTest.php
@@ -13,6 +13,32 @@ use PHPUnit\Framework\TestCase;
*/
final class DotEnvTest extends TestCase
{
+ /**
+ * setup the .env files before test run
+ *
+ * @return void
+ */
+ protected function setUp(): void
+ {
+ // create .env files
+ $file_content = __DIR__ . DIRECTORY_SEPARATOR
+ . 'dotenv' . DIRECTORY_SEPARATOR
+ . 'test.env';
+ $env_files = [
+ __DIR__ . DIRECTORY_SEPARATOR
+ . 'dotenv' . DIRECTORY_SEPARATOR
+ . '.env',
+ __DIR__ . DIRECTORY_SEPARATOR
+ . '.env',
+ ];
+ // if not found, skip -> all will fail
+ if (is_file($file_content)) {
+ foreach ($env_files as $env_file) {
+ copy($file_content, $env_file);
+ }
+ }
+ }
+
/**
* Undocumented function
*
diff --git a/test/phpUnitTests/dotenv/.env b/test/phpUnitTests/dotenv/.env
deleted file mode 120000
index a67af1f..0000000
--- a/test/phpUnitTests/dotenv/.env
+++ /dev/null
@@ -1 +0,0 @@
-test.env
\ No newline at end of file
diff --git a/test/phpUnitTests/dotenv/.env b/test/phpUnitTests/dotenv/.env
new file mode 100644
index 0000000..46d3456
--- /dev/null
+++ b/test/phpUnitTests/dotenv/.env
@@ -0,0 +1,49 @@
+# enviroment file
+SOMETHING=A
+OTHER="B IS B"
+Complex="A B \"D is F"
+# COMMENT
+HAS_SPACE= "ABC";
+# COMMENT AT END
+HAS_COMMENT_QUOTES_SPACE="Comment at end with quotes and space" # Comment QE
+HAS_COMMENT_QUOTES_NO_SPACE="Comment at end with quotes no space"# Comment QES
+HAS_COMMENT_NO_QUOTES_SPACE=Comment at end no quotes and space # Comment NQE
+HAS_COMMENT_NO_QUOTES_NO_SPACE=Comment at end no quotes no space# Comment NQES
+COMMENT_IN_TEXT_QUOTES="Foo bar # comment in here"
+FAILURE = ABC
+SIMPLEBOX= A B C
+TITLE=1
+FOO=1.2
+SOME.TEST=Test Var
+SOME.LIVE=Live Var
+# VAR TESTS -
+A_TEST1 = foo
+A_TEST2 = ${TEST1:-bar} # TEST1 is set so the value of TEST2 = foo
+A_TEST3 = ${TEST4:-bar} # TEST4 is not set so the value of TEST3 = bar
+A_TEST5 = null
+A_TEST6 = ${TEST5-bar} # TEST5 is set but empty so the value of TEST6 = null
+A_TEST7 = ${TEST6:-bar} # TEST5 is set and empty so the value of TEST7 = bar
+# VAR TESTS =
+B_TEST1 = foo
+B_TEST2 = ${TEST1:=bar} # TEST1 is set so the value of TEST2 = foo
+B_TEST3 = ${TEST4:=bar} # TEST4 is not set so the value of TEST3 = bar and TEST4 = bar
+B_TEST5 = null
+B_TEST6 = ${TEST5=bar} # TEST5 is set but emtpy so the value of TEST6 = null
+B_TEST7 = ${TEST6=bar} # TEST5 is set and empty so the value of TEST7 = bar and TEST5 = bar
+# VAR TEST END
+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/test/read_env_file.php b/test/read_env_file.php
index fb85909..97b511d 100644
--- a/test/read_env_file.php
+++ b/test/read_env_file.php
@@ -6,10 +6,27 @@ $loader = require '../vendor/autoload.php';
$loader->addPsr4('gullevek\\', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src');
use gullevek\dotEnv\DotEnv;
-print "BASE: " . __DIR__ . "
";
-print "ORIG:
" . file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '.env') . ""; +// copy test file to .env file in env folder +$file_content = __DIR__ . DIRECTORY_SEPARATOR + . 'phpUnitTests' . DIRECTORY_SEPARATOR + . 'dotenv' . DIRECTORY_SEPARATOR + . 'test.env'; +// env folder +$env_file = __DIR__ . DIRECTORY_SEPARATOR + . 'env' . DIRECTORY_SEPARATOR + . '.env'; +if (!is_file($file_content)) { + die("Cannot read $file_content"); +} +if (copy($file_content, $env_file) === false) { + die("Cannot copy $file_content to $env_file"); +} -$status = DotEnv::readEnvFile(__DIR__); +print "BASE: " . __DIR__ . "
" . file_get_contents($env_file) . ""; + +$status = DotEnv::readEnvFile(__DIR__ . DIRECTORY_SEPARATOR . 'env'); print "STATUS: " . (string)$status . "
" . print_r($_ENV, true) . "