From 4dc170b9df8672a683239fedb4f47beeb9efc3c9 Mon Sep 17 00:00:00 2001 From: Andre van Zuydam Date: Sat, 7 Aug 2021 16:17:44 +0200 Subject: [PATCH] Fixed evals for true / false --- .env.dev | 5 +++++ Tina4/Env.php | 8 +++++--- composer.json | 2 +- tests/EnvTest.php | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 .env.dev diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..2646e43 --- /dev/null +++ b/.env.dev @@ -0,0 +1,5 @@ +[TEST] +VERSION=1.0.0 +SWAGGER_TITLE = "Tina4 Project" +TINA4_DEBUG=true +TINA4_DEBUG_LEVEL=[] \ No newline at end of file diff --git a/Tina4/Env.php b/Tina4/Env.php index d74856e..7b7bded 100644 --- a/Tina4/Env.php +++ b/Tina4/Env.php @@ -47,16 +47,18 @@ private function parseLine($line): void if (isset($variables[0], $variables[1]) && !defined(trim($variables[0]))) { Debug::message("Defining {$variables[0]} = $variables[1]", TINA4_LOG_DEBUG); $variable = trim($variables[0]); - if ($variables[1][0] === "[" || $variables[1][0] === "\"") + + if (trim($variables[1]) === "false" || trim($variables[1]) === "true" || trim($variables[1])[0] === "[" || trim($variables[1])[0] === "\"" || trim($variables[1])[0] === '"' || trim($variables[1])[0] === '"') { eval("\${$variable} = {$variables[1]};"); } else { - extract([$variable => $variables[1]], EXTR_OVERWRITE); + extract([$variable => trim($variables[1])], EXTR_OVERWRITE); } define(trim($variables[0]), ${$variable}); - } + + } /** diff --git a/composer.json b/composer.json index f22822e..22e8642 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "scripts": { "start": "php -S localhost:7147 index.php", - "test": "./vendor/bin/phpunit tests --color --log-junit=tests/junit.xml", + "test": "./vendor/bin/phpunit tests -vvv --color --log-junit=tests/junit.xml", "phpmetrics": "phpmetrics --report-html=phpmetrics --junit=tests/junit.xml ./Tina4" }, "require-dev": { diff --git a/tests/EnvTest.php b/tests/EnvTest.php index 78661c0..5db5df9 100644 --- a/tests/EnvTest.php +++ b/tests/EnvTest.php @@ -12,5 +12,6 @@ function testEnvValue (): void $this->assertEquals("1.0.0", VERSION); $this->assertEquals("Tina4 Project", SWAGGER_TITLE); $this->assertIsArray( TINA4_DEBUG_LEVEL); + $this->assertEquals(true, TINA4_DEBUG); } } \ No newline at end of file