From 06479cadea44ed84f8108c1659419011d5b150a1 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Wed, 8 Jun 2022 13:34:48 +0900 Subject: [PATCH] phpunit test update, update all static testers, add psalm tester Add Readme file update for install via composer psalm static checker added phan and phpstan update with ignoring vendor and test files as they are not needed in final system --- .phan/config.php | 2 ++ Readme.md | 6 +++++- phpstan.neon | 3 +++ psalm.xml | 16 ++++++++++++++++ test/phpUnitTests/DotEnvTest.php | 24 +++++++++++++++++++++++- 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 psalm.xml diff --git a/.phan/config.php b/.phan/config.php index 7a1db68..87138de 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -77,6 +77,8 @@ return [ // A list of directories holding code that we want // to parse, but not analyze "exclude_analysis_directory_list" => [ + 'vendor', + 'test' ], 'exclude_file_list' => [ ], diff --git a/Readme.md b/Readme.md index 4adecc0..1c80ca8 100644 --- a/Readme.md +++ b/Readme.md @@ -1,12 +1,16 @@ # dotenv: readEnvFile() -A single function implementation of +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. diff --git a/phpstan.neon b/phpstan.neon index cebe292..3802893 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,3 +5,6 @@ parameters: level: max paths: - %currentWorkingDirectory% + excludePaths: + - vendor + - test diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..2b10313 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/test/phpUnitTests/DotEnvTest.php b/test/phpUnitTests/DotEnvTest.php index e7bd391..f87ceb6 100644 --- a/test/phpUnitTests/DotEnvTest.php +++ b/test/phpUnitTests/DotEnvTest.php @@ -45,36 +45,42 @@ final class DotEnvTest extends TestCase // 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, ], ]; } @@ -90,14 +96,26 @@ final class DotEnvTest extends TestCase * @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 + 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) { @@ -116,6 +134,10 @@ final class DotEnvTest extends TestCase $expected_env, 'Assert _ENV correct' ); + // if we have file and chmod unset + if ($old_chmod !== null) { + chmod($folder . DIRECTORY_SEPARATOR . $file, $old_chmod); + } } }