Skip to content

Commit

Permalink
Remove unnecessary comments
Browse files Browse the repository at this point in the history
Improve Tests
Update composer.json
  • Loading branch information
alireaza committed Mar 6, 2022
1 parent 7d7d7d8 commit ad690aa
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 46 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand All @@ -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": {
Expand Down
18 changes: 1 addition & 17 deletions src/Variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '$')) {
Expand Down Expand Up @@ -88,4 +72,4 @@ public function __invoke(string $data, array $env): string

return $data;
}
}
}
80 changes: 56 additions & 24 deletions tests/Unit/DotEnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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);
}
Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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'));
}
}
}
8 changes: 6 additions & 2 deletions tests/Unit/VariablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
}

0 comments on commit ad690aa

Please sign in to comment.