6 Commits

10 changed files with 416 additions and 380 deletions

4
.gitignore vendored
View File

@@ -2,3 +2,7 @@ vendor
.phpunit.result.cache .phpunit.result.cache
.phplint-cache .phplint-cache
composer.lock composer.lock
**/.env
**/.target
.phpunit.cache
tools/

View File

@@ -26,6 +26,8 @@
// use Phan\Config; // use Phan\Config;
return [ return [
// turn color on (-C)
"color_issue_messages_if_supported" => true,
// If true, missing properties will be created when // If true, missing properties will be created when
// they are first seen. If false, we'll report an // they are first seen. If false, we'll report an
// error message. // error message.

9
.phive/phars.xml Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpcs" version="^4.0.1" installed="4.0.1" location="./tools/phpcs" copy="false"/>
<phar name="phpcbf" version="^4.0.1" installed="4.0.1" location="./tools/phpcbf" copy="false"/>
<phar name="phan" version="^5.5.2" installed="5.5.2" location="./tools/phan" copy="false"/>
<phar name="psalm" version="^5.26.1" installed="5.26.1" location="./tools/psalm" copy="false"/>
<phar name="phpstan" version="^2.1.33" installed="2.1.33" location="./tools/phpstan" copy="false"/>
<phar name="phpunit" version="^12.5.4" installed="12.5.4" location="./tools/phpunit" copy="false"/>
</phive>

View File

@@ -26,10 +26,10 @@
"exclude": ["/test/", "/test/*", "/phpstan.neon", "/psalm.xml", "/.phan/", "/.vscode/", "/phpunit.xml"] "exclude": ["/test/", "/test/*", "/phpstan.neon", "/psalm.xml", "/.phan/", "/.vscode/", "/phpunit.xml"]
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9",
"phan/phan": "^5.4", "phan/phan": "^5.4",
"phpstan/phpstan": "^2.0",
"phpstan/phpdoc-parser": "^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
View 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>

View File

@@ -1,7 +1,5 @@
<phpunit <?xml version="1.0"?>
colors="true" <phpunit colors="true" cacheDirectory=".phpunit.cache">
verbose="true"
>
<testsuites> <testsuites>
<testsuite name="unit"> <testsuite name="unit">
<directory>test/phpUnitTests/</directory> <directory>test/phpUnitTests/</directory>

View File

@@ -5,12 +5,18 @@ declare(strict_types=1);
namespace tests; namespace tests;
use PHPUnit\Framework\TestCase; 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 * 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 final class DotEnvTest extends TestCase
{ {
/** /**
@@ -48,7 +54,7 @@ final class DotEnvTest extends TestCase
* *
* @return array * @return array
*/ */
public function envFileProvider(): array public static function envFileProvider(): array
{ {
$dot_env_content = [ $dot_env_content = [
'SOMETHING' => 'A', 'SOMETHING' => 'A',
@@ -101,39 +107,39 @@ final class DotEnvTest extends TestCase
'default' => [ 'default' => [
'folder' => null, 'folder' => null,
'file' => null, 'file' => null,
'status' => 3, 'expected_status' => 3,
'content' => [], 'expected_env' => [],
'chmod' => null, 'chmod' => null,
], ],
'cannot open file' => [ 'cannot open file' => [
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv', 'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
'file' => 'cannot_read.env', 'file' => 'cannot_read.env',
'status' => 2, 'expected_status' => 2,
'content' => [], 'expected_env' => [],
// 0000 // 0000
'chmod' => '100000', 'chmod' => '100000',
], ],
'empty file' => [ 'empty file' => [
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv', 'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
'file' => 'empty.env', 'file' => 'empty.env',
'status' => 1, 'expected_status' => 1,
'content' => [], 'expected_env' => [],
// 0664 // 0664
'chmod' => '100664', 'chmod' => '100664',
], ],
'override all' => [ 'override all' => [
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv', 'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
'file' => 'test.env', 'file' => 'test.env',
'status' => 0, 'expected_status' => 0,
'content' => $dot_env_content, 'expected_env' => $dot_env_content,
// 0664 // 0664
'chmod' => '100664', 'chmod' => '100664',
], ],
'override directory' => [ 'override directory' => [
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv', 'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
'file' => null, 'file' => null,
'status' => 0, 'expected_status' => 0,
'content' => $dot_env_content, 'expected_env' => $dot_env_content,
'chmod' => null, 'chmod' => null,
], ],
]; ];
@@ -142,10 +148,6 @@ final class DotEnvTest extends TestCase
/** /**
* test read .env file * 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 $folder
* @param string|null $file * @param string|null $file
* @param int $expected_status * @param int $expected_status
@@ -153,6 +155,9 @@ final class DotEnvTest extends TestCase
* @param string|null $chmod * @param string|null $chmod
* @return void * @return void
*/ */
#[Test]
#[TestDox('Read _ENV file from $folder / $file with expected status: $expected_status [$_dataName]')]
#[DataProvider('envFileProvider')]
public function testReadEnvFile( public function testReadEnvFile(
?string $folder, ?string $folder,
?string $file, ?string $file,
@@ -193,14 +198,14 @@ final class DotEnvTest extends TestCase
$status = \gullevek\dotEnv\DotEnv::readEnvFile(); $status = \gullevek\dotEnv\DotEnv::readEnvFile();
} }
$this->assertEquals( $this->assertEquals(
$status,
$expected_status, $expected_status,
$status,
'Assert returned status equal' 'Assert returned status equal'
); );
// now assert read data // now assert read data
$this->assertEquals( $this->assertEquals(
$_ENV,
$expected_env, $expected_env,
$_ENV,
'Assert _ENV correct' 'Assert _ENV correct'
); );
// if we have file and chmod unset // if we have file and chmod unset