Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d14445786 | |||
| 979ec79fc0 | |||
| dfe8607934 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,3 +2,6 @@ vendor
|
||||
.phpunit.result.cache
|
||||
.phplint-cache
|
||||
composer.lock
|
||||
**/.env
|
||||
**/.target
|
||||
.phpunit.cache
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
"exclude": ["/test/", "/test/*", "/phpstan.neon", "/psalm.xml", "/.phan/", "/.vscode/", "/phpunit.xml"]
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9",
|
||||
"phan/phan": "^5.4",
|
||||
"phpstan/phpstan": "^2.0",
|
||||
"phpstan/phpdoc-parser": "^2.0",
|
||||
"phpstan/phpstan-deprecation-rules": "^2.0"
|
||||
"phpstan/phpstan-deprecation-rules": "^2.0",
|
||||
"phpstan/phpstan": "2.1.x-dev",
|
||||
"phpunit/phpunit": "^12"
|
||||
}
|
||||
}
|
||||
|
||||
18
phpcs.xml
Normal file
18
phpcs.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="MyStandard">
|
||||
<description>PSR12 override rules (strict, standard). Switch spaces indent to tab.</description>
|
||||
<arg name="tab-width" value="4"/>
|
||||
<rule ref="PSR1"/>
|
||||
<rule ref="PSR12">
|
||||
<!-- turn off white space check for tab -->
|
||||
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
|
||||
</rule>
|
||||
<!-- no space indent, must be tab, 4 is tab iwdth -->
|
||||
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
|
||||
<rule ref="Generic.WhiteSpace.ScopeIndent">
|
||||
<properties>
|
||||
<property name="indent" value="4"/>
|
||||
<property name="tabIndent" value="true"/>
|
||||
</properties>
|
||||
</rule>
|
||||
</ruleset>
|
||||
@@ -1,7 +1,5 @@
|
||||
<phpunit
|
||||
colors="true"
|
||||
verbose="true"
|
||||
>
|
||||
<?xml version="1.0"?>
|
||||
<phpunit colors="true" cacheDirectory=".phpunit.cache">
|
||||
<testsuites>
|
||||
<testsuite name="unit">
|
||||
<directory>test/phpUnitTests/</directory>
|
||||
|
||||
@@ -5,12 +5,18 @@ declare(strict_types=1);
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\TestDox;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\CoversMethod;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
|
||||
/**
|
||||
* Test class for DotEnv
|
||||
* @coversDefaultClass \gullevek\DotEnv
|
||||
* @testdox \gullevek\DotEnv method tests
|
||||
*/
|
||||
#[TestDox("\gullevek\DotEnv method tests")]
|
||||
#[CoversClass(\gullevek\dotEnv\DotEnv::class)]
|
||||
#[CoversMethod(\gullevek\dotEnv\DotEnv::class, 'readEnvFile')]
|
||||
final class DotEnvTest extends TestCase
|
||||
{
|
||||
/**
|
||||
@@ -48,7 +54,7 @@ final class DotEnvTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function envFileProvider(): array
|
||||
public static function envFileProvider(): array
|
||||
{
|
||||
$dot_env_content = [
|
||||
'SOMETHING' => 'A',
|
||||
@@ -101,39 +107,39 @@ final class DotEnvTest extends TestCase
|
||||
'default' => [
|
||||
'folder' => null,
|
||||
'file' => null,
|
||||
'status' => 3,
|
||||
'content' => [],
|
||||
'expected_status' => 3,
|
||||
'expected_env' => [],
|
||||
'chmod' => null,
|
||||
],
|
||||
'cannot open file' => [
|
||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||
'file' => 'cannot_read.env',
|
||||
'status' => 2,
|
||||
'content' => [],
|
||||
'expected_status' => 2,
|
||||
'expected_env' => [],
|
||||
// 0000
|
||||
'chmod' => '100000',
|
||||
],
|
||||
'empty file' => [
|
||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||
'file' => 'empty.env',
|
||||
'status' => 1,
|
||||
'content' => [],
|
||||
'expected_status' => 1,
|
||||
'expected_env' => [],
|
||||
// 0664
|
||||
'chmod' => '100664',
|
||||
],
|
||||
'override all' => [
|
||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||
'file' => 'test.env',
|
||||
'status' => 0,
|
||||
'content' => $dot_env_content,
|
||||
'expected_status' => 0,
|
||||
'expected_env' => $dot_env_content,
|
||||
// 0664
|
||||
'chmod' => '100664',
|
||||
],
|
||||
'override directory' => [
|
||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||
'file' => null,
|
||||
'status' => 0,
|
||||
'content' => $dot_env_content,
|
||||
'expected_status' => 0,
|
||||
'expected_env' => $dot_env_content,
|
||||
'chmod' => null,
|
||||
],
|
||||
];
|
||||
@@ -142,10 +148,6 @@ final class DotEnvTest extends TestCase
|
||||
/**
|
||||
* test read .env file
|
||||
*
|
||||
* @covers ::readEnvFile
|
||||
* @dataProvider envFileProvider
|
||||
* @testdox Read _ENV file from $folder / $file with expected status: $expected_status [$_dataName]
|
||||
*
|
||||
* @param string|null $folder
|
||||
* @param string|null $file
|
||||
* @param int $expected_status
|
||||
@@ -153,6 +155,9 @@ final class DotEnvTest extends TestCase
|
||||
* @param string|null $chmod
|
||||
* @return void
|
||||
*/
|
||||
#[Test]
|
||||
#[TestDox('Read _ENV file from $folder / $file with expected status: $expected_status [$_dataName]')]
|
||||
#[DataProvider('envFileProvider')]
|
||||
public function testReadEnvFile(
|
||||
?string $folder,
|
||||
?string $file,
|
||||
@@ -193,14 +198,14 @@ final class DotEnvTest extends TestCase
|
||||
$status = \gullevek\dotEnv\DotEnv::readEnvFile();
|
||||
}
|
||||
$this->assertEquals(
|
||||
$status,
|
||||
$expected_status,
|
||||
$status,
|
||||
'Assert returned status equal'
|
||||
);
|
||||
// now assert read data
|
||||
$this->assertEquals(
|
||||
$_ENV,
|
||||
$expected_env,
|
||||
$_ENV,
|
||||
'Assert _ENV correct'
|
||||
);
|
||||
// if we have file and chmod unset
|
||||
|
||||
Reference in New Issue
Block a user