Moved to tabs for indent and add phpcs.xml file, update phpunit to 12 and update tests

This commit is contained in:
2026-01-13 10:36:11 +09:00
parent 979ec79fc0
commit 8d14445786
7 changed files with 344 additions and 322 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ vendor
composer.lock composer.lock
**/.env **/.env
**/.target **/.target
.phpunit.cache

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="false"
>
<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