15 Commits

Author SHA1 Message Date
e29f9fcd88 Add another psr-4 prefix, update composer packages
Previously it was just "gullevek\dotEnv" but now also "gullevek\dotenv"
will work.

Update phan/phpstan composer dev requirement verisons
2023-03-03 09:32:02 +09:00
ae0eb1f939 Convert phan config to PSR12 2023-01-19 12:45:21 +09:00
c608201de1 Switch to standard PSR-12 with spaces instead of tab 2023-01-19 12:38:37 +09:00
8e062ff114 Add comment to unit test skip condition 2023-01-12 15:07:12 +09:00
225e3e7929 Unit test fixes with permissions
- in case the unit test is run as root, skip test for cannot read (0000)
- set read (0664) for all must read files
- write .env file int all folders for test so that __DIR__ base will
  always find one
2023-01-12 11:42:15 +09:00
44bcb39e51 Delete .gitlab-ci.yml 2023-01-11 08:53:12 +00:00
5729a0c977 Update .gitlab-ci.yml file 2023-01-11 08:49:23 +00:00
9af7790b61 Fix Readme file 2023-01-11 17:15:37 +09:00
0579a075dc Remove bitbucket pipeline, update readme with test tools 2023-01-11 17:14:47 +09:00
58a6d994ca bitbucket pipeline test 2023-01-11 17:06:24 +09:00
233f9fbf81 Dev install phpstan, phan and phplint 2023-01-11 17:00:57 +09:00
8ae06efe4e Remove symlinked .env files 2023-01-11 16:48:28 +09:00
4079d7c66e Merge bitbucket.org:egplusww/code-blocks-dotenv 2023-01-11 16:31:30 +09:00
dd2274f3b1 Auto create .env files 2023-01-11 16:30:51 +09:00
5742314581 Initial Bitbucket Pipelines configuration 2023-01-11 06:46:28 +00:00
10 changed files with 391 additions and 304 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
vendor
.phpunit.result.cache
.phplint-cache
composer.lock

View File

@@ -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/`

View File

@@ -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"
}
}

View File

@@ -1 +0,0 @@
phpUnitTests/dotenv/test.env

0
test/env/.gitignore vendored Normal file
View File

View 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)

View File

@@ -1 +0,0 @@
test.env

View File

@@ -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__