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
This commit is contained in:
2022-06-08 13:34:48 +09:00
parent b73a24b447
commit 06479cadea
5 changed files with 49 additions and 2 deletions

View File

@@ -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' => [
],

View File

@@ -1,12 +1,16 @@
# dotenv: readEnvFile()
A single function implementation of <https://github.com/vlucas/phpdotenv>
A simple implementation of <https://github.com/vlucas/phpdotenv>
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.

View File

@@ -5,3 +5,6 @@ parameters:
level: max
paths:
- %currentWorkingDirectory%
excludePaths:
- vendor
- test

16
psalm.xml Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<psalm
errorLevel="3"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
<directory name="test" />
</ignoreFiles>
</projectFiles>
</psalm>

View File

@@ -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);
}
}
}