Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e29f9fcd88 | |||
| ae0eb1f939 | |||
| c608201de1 | |||
| 8e062ff114 | |||
| 225e3e7929 | |||
| 44bcb39e51 | |||
| 5729a0c977 | |||
| 9af7790b61 | |||
| 0579a075dc | |||
| 58a6d994ca | |||
| 233f9fbf81 | |||
| 8ae06efe4e | |||
| 4079d7c66e | |||
| dd2274f3b1 | |||
| 5742314581 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
vendor
|
||||
.phpunit.result.cache
|
||||
.phplint-cache
|
||||
composer.lock
|
||||
|
||||
16
Readme.md
16
Readme.md
@@ -60,3 +60,19 @@ ESCAPE="String \" inside \" other "
|
||||
DOUBLE="I will be used"
|
||||
DOUBLE="This will be ignored"
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
### Phan
|
||||
|
||||
`vendor/bin/phan --analyze-twice`
|
||||
|
||||
### PHPstan
|
||||
|
||||
`vendor/bin/phpstan`
|
||||
|
||||
### PHPUnit
|
||||
|
||||
Unit tests have to be run from base folder with
|
||||
|
||||
`vendor/bin/phpunit test/phpUnitTests/`
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
"license": "MIT",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"gullevek\\dotEnv\\": "src/"
|
||||
"gullevek\\dotEnv\\": "src/",
|
||||
"gullevek\\dotenv\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
@@ -25,6 +26,8 @@
|
||||
"exclude": ["/test/", "/test/*", "/phpstan.neon", "/psalm.xml", "/.phan/", "/.vscode/", "/phpunit.xml"]
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9"
|
||||
"phpunit/phpunit": "^9",
|
||||
"phpstan/phpstan": "^1.10",
|
||||
"phan/phan": "^5.4"
|
||||
}
|
||||
}
|
||||
|
||||
0
test/env/.gitignore
vendored
Normal file
0
test/env/.gitignore
vendored
Normal file
@@ -13,6 +13,36 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
final class DotEnvTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* setup the .env files before test run
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
// create .env files
|
||||
$file_content = __DIR__ . DIRECTORY_SEPARATOR
|
||||
. 'dotenv' . DIRECTORY_SEPARATOR
|
||||
. 'test.env';
|
||||
// copy to all folder levels
|
||||
$env_files = [
|
||||
__DIR__ . DIRECTORY_SEPARATOR
|
||||
. 'dotenv' . DIRECTORY_SEPARATOR
|
||||
. '.env',
|
||||
__DIR__ . DIRECTORY_SEPARATOR
|
||||
. '.env',
|
||||
__DIR__ . DIRECTORY_SEPARATOR
|
||||
. '..' . 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
|
||||
*
|
||||
@@ -76,21 +106,24 @@ final class DotEnvTest extends TestCase
|
||||
'file' => 'cannot_read.env',
|
||||
'status' => 2,
|
||||
'content' => [],
|
||||
'chmod' => '000',
|
||||
// 0000
|
||||
'chmod' => '100000',
|
||||
],
|
||||
'empty file' => [
|
||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||
'file' => 'empty.env',
|
||||
'status' => 1,
|
||||
'content' => [],
|
||||
'chmod' => null,
|
||||
// 0664
|
||||
'chmod' => '100664',
|
||||
],
|
||||
'override all' => [
|
||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||
'file' => 'test.env',
|
||||
'status' => 0,
|
||||
'content' => $dot_env_content,
|
||||
'chmod' => null,
|
||||
// 0664
|
||||
'chmod' => '100664',
|
||||
],
|
||||
'override directory' => [
|
||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||
@@ -123,8 +156,23 @@ final class DotEnvTest extends TestCase
|
||||
array $expected_env,
|
||||
?string $chmod
|
||||
): void {
|
||||
// if we have file + chmod set
|
||||
// skip if chmod is set to 10000 (000 no rights) if we are root
|
||||
// as root there is no stop reading a file
|
||||
if (
|
||||
!empty($chmod) &&
|
||||
$chmod == '100000' &&
|
||||
getmyuid() == 0
|
||||
) {
|
||||
$this->markTestSkipped(
|
||||
"Skip cannot read file test because run user is root"
|
||||
);
|
||||
return;
|
||||
}
|
||||
// reset $_ENV for clean compare
|
||||
$_ENV = [];
|
||||
// previous file perm
|
||||
$old_chmod = null;
|
||||
// if we have change permission for file
|
||||
if (
|
||||
is_file($folder . DIRECTORY_SEPARATOR . $file) &&
|
||||
!empty($chmod)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
test.env
|
||||
@@ -6,12 +6,33 @@ $loader = require '../vendor/autoload.php';
|
||||
$loader->addPsr4('gullevek\\', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src');
|
||||
use gullevek\dotEnv\DotEnv;
|
||||
|
||||
print "BASE: " . __DIR__ . "<br>";
|
||||
print "ORIG: <pre>" . file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '.env') . "</pre>";
|
||||
// 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__ . "<br>";
|
||||
print "ENV: " . $env_file . "<br>";
|
||||
print "ORIG: <pre>" . file_get_contents($env_file) . "</pre>";
|
||||
|
||||
$status = DotEnv::readEnvFile(__DIR__ . DIRECTORY_SEPARATOR . 'env');
|
||||
|
||||
print "STATUS: " . (string)$status . "<br>";
|
||||
print "ENV: <pre>" . print_r($_ENV, true) . "</pre><br>";
|
||||
|
||||
$status = gullevek\dotenv\DotEnv::readEnvFile(__DIR__ . DIRECTORY_SEPARATOR . 'env');
|
||||
print "STATUS B: " . (string)$status . "<br>";
|
||||
print "ENV B: <pre>" . print_r($_ENV, true) . "</pre><br>";
|
||||
|
||||
// __END__
|
||||
|
||||
Reference in New Issue
Block a user