Deprecate check for GetDotEnv tests

This commit is contained in:
Clemens Schwaighofer
2023-03-09 16:17:52 +09:00
parent 03fbcaecfb
commit 6bec59e387

View File

@@ -77,21 +77,24 @@ final class CoreLibsGetDotEnvTest extends TestCase
'file' => 'cannot_read.env', 'file' => 'cannot_read.env',
'status' => 2, 'status' => 2,
'content' => [], 'content' => [],
'chmod' => '000', // 0000
'chmod' => '100000',
], ],
'empty file' => [ 'empty file' => [
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv', 'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
'file' => 'empty.env', 'file' => 'empty.env',
'status' => 1, 'status' => 1,
'content' => [], 'content' => [],
'chmod' => null, // 0664
'chmod' => '100664',
], ],
'override all' => [ 'override all' => [
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv', 'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
'file' => 'test.env', 'file' => 'test.env',
'status' => 0, 'status' => 0,
'content' => $dot_env_content, 'content' => $dot_env_content,
'chmod' => null, // 0664
'chmod' => '100664',
], ],
'override directory' => [ 'override directory' => [
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv', 'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
@@ -124,6 +127,16 @@ final class CoreLibsGetDotEnvTest extends TestCase
array $expected_env, array $expected_env,
?string $chmod ?string $chmod
): void { ): void {
if (
!empty($chmod) &&
$chmod == '100000' &&
getmyuid() == 0
) {
$this->markTestSkipped(
"Skip cannot read file test because run user is root"
);
return;
}
// if we have file + chmod set // if we have file + chmod set
$old_chmod = null; $old_chmod = null;
if ( if (
@@ -143,6 +156,10 @@ final class CoreLibsGetDotEnvTest extends TestCase
}, },
E_USER_DEPRECATED E_USER_DEPRECATED
); );
// tests are never run -> deprecated
if (is_file($folder . DIRECTORY_SEPARATOR . $file)) {
chmod($folder . DIRECTORY_SEPARATOR . $file, 0664);
}
$this->expectExceptionMessage($message); $this->expectExceptionMessage($message);
if ($folder !== null && $file !== null) { if ($folder !== null && $file !== null) {
$status = DotEnv::readEnvFile($folder, $file); $status = DotEnv::readEnvFile($folder, $file);
@@ -164,8 +181,9 @@ final class CoreLibsGetDotEnvTest extends TestCase
'Assert _ENV correct' 'Assert _ENV correct'
); );
// if we have file and chmod unset // if we have file and chmod unset
if ($old_chmod !== null) { print "Write mode: $old_chmod\n";
chmod($folder . DIRECTORY_SEPARATOR . $file, $old_chmod); if ($old_chmod !== null && $chmod == '100000') {
chmod($folder . DIRECTORY_SEPARATOR . $file, 0664);
} }
} }
} }