From ad690aa7f57059f7e95cb3ed86a374827fa0997b Mon Sep 17 00:00:00 2001 From: AliReaza Date: Sun, 6 Mar 2022 09:23:19 +0330 Subject: [PATCH] Remove unnecessary comments Improve Tests Update composer.json --- composer.json | 6 +-- src/Variables.php | 18 +------- tests/Unit/DotEnvTest.php | 80 +++++++++++++++++++++++++----------- tests/Unit/VariablesTest.php | 8 +++- 4 files changed, 66 insertions(+), 46 deletions(-) diff --git a/composer.json b/composer.json index 7a27b4e..ad7ca88 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "alireaza/dot-env-resolver-variables", - "version": "1.2.0", + "version": "1.3.0", "type": "library", "license": "MIT", "description": "This is Variables Resolver package for DotEnv.", @@ -27,10 +27,10 @@ ], "require": { "php": "^8.0.0", - "alireaza/dot-env": "1.2.0" + "alireaza/dot-env": "1.3.0" }, "require-dev": { - "phpunit/phpunit": "9.5.11" + "phpunit/phpunit": "^9.5.16" }, "autoload": { "psr-4": { diff --git a/src/Variables.php b/src/Variables.php index 7240271..766b0f3 100644 --- a/src/Variables.php +++ b/src/Variables.php @@ -4,31 +4,15 @@ use LogicException; -/** - * Class Variables - * - * @package AliReaza\DotEnv\Resolver - */ class Variables { protected array $variables; - /** - * Variables constructor. - * - * @param array $variables - */ public function __construct(array $variables = []) { $this->variables = $variables; } - /** - * @param string $data - * @param array $env - * - * @return string - */ public function __invoke(string $data, array $env): string { if (str_contains($data, '$')) { @@ -88,4 +72,4 @@ public function __invoke(string $data, array $env): string return $data; } -} \ No newline at end of file +} diff --git a/tests/Unit/DotEnvTest.php b/tests/Unit/DotEnvTest.php index dd392d3..57fba27 100644 --- a/tests/Unit/DotEnvTest.php +++ b/tests/Unit/DotEnvTest.php @@ -10,16 +10,18 @@ class DotEnvTest extends TestCase { - public function test_When_create_new_DotEnv_without_arguments_Expect_env_property_must_array_and_empty() + public function test_When_create_new_DotEnv_without_arguments_Expect_env_property_must_array_and_empty(): void { $env = new DotEnv(); $array = $env->toArray(); - $this->assertTrue(is_array($array) && empty($array)); + $this->assertIsArray($array); + + $this->assertEmpty($array); } - public function test_When_create_new_DotEnv_and_load_file_Expect_env_property_must_array_of_file_variables() + public function test_When_create_new_DotEnv_and_load_file_Expect_env_property_must_array_of_file_variables(): void { mkdir($tmpdir = sys_get_temp_dir() . '/dotenv'); @@ -35,10 +37,14 @@ public function test_When_create_new_DotEnv_and_load_file_Expect_env_property_mu rmdir($tmpdir); - $this->assertTrue(is_array($env->toArray()) && $env->has('FOO') && $env->get('FOO') === 'BAR'); + $this->assertIsArray($env->toArray()); + + $this->assertSame(true, $env->has('FOO')); + + $this->assertSame('BAR', $env->get('FOO')); } - public function test_When_create_new_DotEnv_with_file_argument_Expect_env_property_must_array_of_file_variables() + public function test_When_create_new_DotEnv_with_file_argument_Expect_env_property_must_array_of_file_variables(): void { mkdir($tmpdir = sys_get_temp_dir() . '/dotenv'); @@ -52,10 +58,14 @@ public function test_When_create_new_DotEnv_with_file_argument_Expect_env_proper rmdir($tmpdir); - $this->assertTrue(is_array($env->toArray()) && $env->has('FOO') && $env->get('FOO') === 'BAR'); + $this->assertIsArray($env->toArray()); + + $this->assertSame(true, $env->has('FOO')); + + $this->assertSame('BAR', $env->get('FOO')); } - public function test_When_create_new_DotEnv_with_file_and_resolvers_arguments_Expect_env_property_must_array_of_file_variables_that_must_be_converted_to_lowercase_by_resolver() + public function test_When_create_new_DotEnv_with_file_and_resolvers_arguments_Expect_env_property_must_array_of_file_variables_that_must_be_converted_to_lowercase_by_resolver(): void { mkdir($tmpdir = sys_get_temp_dir() . '/dotenv'); @@ -65,7 +75,7 @@ public function test_When_create_new_DotEnv_with_file_and_resolvers_arguments_Ex $env = new DotEnv($file, [ new class { - public function __invoke(string $data) + public function __invoke(string $data): string { return strtolower($data); } @@ -76,10 +86,14 @@ public function __invoke(string $data) rmdir($tmpdir); - $this->assertTrue(is_array($env->toArray()) && $env->has('FOO') && $env->get('FOO') === 'bar'); + $this->assertIsArray($env->toArray()); + + $this->assertSame(true, $env->has('FOO')); + + $this->assertSame('bar', $env->get('FOO')); } - public function test_When_create_new_DotEnv_with_empty_file_Expect_env_property_must_array_and_empty() + public function test_When_create_new_DotEnv_with_empty_file_Expect_env_property_must_array_and_empty(): void { mkdir($tmpdir = sys_get_temp_dir() . '/dotenv'); @@ -95,10 +109,12 @@ public function test_When_create_new_DotEnv_with_empty_file_Expect_env_property_ $array = $env->toArray(); - $this->assertTrue(is_array($array) && empty($array)); + $this->assertIsArray($array); + + $this->assertEmpty($array); } - public function test_When_create_new_DotEnv_with_missing_equal_for_variable_in_file_Expect_throw_exception() + public function test_When_create_new_DotEnv_with_missing_equal_for_variable_in_file_Expect_throw_exception(): void { mkdir($tmpdir = sys_get_temp_dir() . '/dotenv'); @@ -123,7 +139,7 @@ public function test_When_create_new_DotEnv_with_missing_equal_for_variable_in_f rmdir($tmpdir); } - public function test_When_create_new_DotEnv_with_whitespace_character_after_variable_in_file_Expect_throw_exception() + public function test_When_create_new_DotEnv_with_whitespace_character_after_variable_in_file_Expect_throw_exception(): void { mkdir($tmpdir = sys_get_temp_dir() . '/dotenv'); @@ -148,7 +164,7 @@ public function test_When_create_new_DotEnv_with_whitespace_character_after_vari rmdir($tmpdir); } - public function test_When_create_new_DotEnv_with_export_before_variable_in_file_Expect_env_property_must_array_of_file_variables() + public function test_When_create_new_DotEnv_with_export_before_variable_in_file_Expect_env_property_must_array_of_file_variables(): void { mkdir($tmpdir = sys_get_temp_dir() . '/dotenv'); @@ -162,10 +178,14 @@ public function test_When_create_new_DotEnv_with_export_before_variable_in_file_ rmdir($tmpdir); - $this->assertTrue(is_array($env->toArray()) && $env->has('FOO') && $env->get('FOO') === 'BAR'); + $this->assertIsArray($env->toArray()); + + $this->assertSame(true, $env->has('FOO')); + + $this->assertSame('BAR', $env->get('FOO')); } - public function test_When_create_new_DotEnv_with_whitespace_character_inside_variable_in_file_Expect_throw_exception() + public function test_When_create_new_DotEnv_with_whitespace_character_inside_variable_in_file_Expect_throw_exception(): void { mkdir($tmpdir = sys_get_temp_dir() . '/dotenv'); @@ -190,7 +210,7 @@ public function test_When_create_new_DotEnv_with_whitespace_character_inside_var rmdir($tmpdir); } - public function test_When_create_new_DotEnv_with_whitespace_character_before_value_in_file_Expect_throw_exception() + public function test_When_create_new_DotEnv_with_whitespace_character_before_value_in_file_Expect_throw_exception(): void { mkdir($tmpdir = sys_get_temp_dir() . '/dotenv'); @@ -215,7 +235,7 @@ public function test_When_create_new_DotEnv_with_whitespace_character_before_val rmdir($tmpdir); } - public function test_When_create_new_DotEnv_with_whitespace_character_inside_value_in_file_Expect_env_property_must_array_of_file_variables() + public function test_When_create_new_DotEnv_with_whitespace_character_inside_value_in_file_Expect_env_property_must_array_of_file_variables(): void { mkdir($tmpdir = sys_get_temp_dir() . '/dotenv'); @@ -229,10 +249,14 @@ public function test_When_create_new_DotEnv_with_whitespace_character_inside_val rmdir($tmpdir); - $this->assertTrue(is_array($env->toArray()) && $env->has('FOO') && $env->get('FOO') === 'BAR BAZ'); + $this->assertIsArray($env->toArray()); + + $this->assertSame(true, $env->has('FOO')); + + $this->assertSame('BAR BAZ', $env->get('FOO')); } - public function test_When_create_new_DotEnv_with_value_with_single_quotes_in_file_Expect_env_property_must_array_of_file_variables_without_quotes() + public function test_When_create_new_DotEnv_with_value_with_single_quotes_in_file_Expect_env_property_must_array_of_file_variables_without_quotes(): void { mkdir($tmpdir = sys_get_temp_dir() . '/dotenv'); @@ -246,10 +270,14 @@ public function test_When_create_new_DotEnv_with_value_with_single_quotes_in_fil rmdir($tmpdir); - $this->assertTrue(is_array($env->toArray()) && $env->has('FOO') && $env->get('FOO') === 'BAR BAZ'); + $this->assertIsArray($env->toArray()); + + $this->assertSame(true, $env->has('FOO')); + + $this->assertSame('BAR BAZ', $env->get('FOO')); } - public function test_When_create_new_DotEnv_with_value_with_double_quotes_in_file_Expect_env_property_must_array_of_file_variables_without_quotes() + public function test_When_create_new_DotEnv_with_value_with_double_quotes_in_file_Expect_env_property_must_array_of_file_variables_without_quotes(): void { mkdir($tmpdir = sys_get_temp_dir() . '/dotenv'); @@ -263,6 +291,10 @@ public function test_When_create_new_DotEnv_with_value_with_double_quotes_in_fil rmdir($tmpdir); - $this->assertTrue(is_array($env->toArray()) && $env->has('FOO') && $env->get('FOO') === 'BAR BAZ'); + $this->assertIsArray($env->toArray()); + + $this->assertSame(true, $env->has('FOO')); + + $this->assertSame('BAR BAZ', $env->get('FOO')); } -} \ No newline at end of file +} diff --git a/tests/Unit/VariablesTest.php b/tests/Unit/VariablesTest.php index 10a1963..ed9d437 100644 --- a/tests/Unit/VariablesTest.php +++ b/tests/Unit/VariablesTest.php @@ -26,6 +26,10 @@ public function test_When_use_Variables_Resolver_Expect_env_property_must_array_ rmdir($tmpdir); - $this->assertTrue(is_array($env->toArray()) && $env->has('BAZ') && $env->get('BAZ') === 'BAR'); + $this->assertIsArray($env->toArray()); + + $this->assertSame(true, $env->has('BAZ')); + + $this->assertSame('BAR', $env->get('BAZ')); } -} \ No newline at end of file +}