Skip to content

Commit

Permalink
refactor(test): Improve env_explode test case
Browse files Browse the repository at this point in the history
- Updated the test case for env_explode function in HeplersTest.php
- Changed the expectation for env_explode('ENV_EXPLODE_EMPTY') to an empty array
  • Loading branch information
guanguans committed May 10, 2024
1 parent fbc5b00 commit c00f1a2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
</testsuites>
<php>
<env name="APP_KEY" value="base64:e2ASw7JCNMYR6PWInGGQrzUzisuDvv8bhNl14XGbUi8="/>
<env name="ENV_EXPLODE_STRING" value="log,null"/>
<env name="ENV_EXPLODE_TRUE" value="true"/>
<env name="ENV_EXPLODE_FALSE" value="false"/>
<env name="ENV_EXPLODE_EMPTY" value="empty"/>
<env name="ENV_EXPLODE_FALSE" value="false"/>
<env name="ENV_EXPLODE_NULL" value="null"/>
<env name="ENV_EXPLODE_STRING" value="log,null"/>
<env name="ENV_EXPLODE_TRUE" value="true"/>
</php>
<!--<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener">
Expand Down
2 changes: 1 addition & 1 deletion src/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function env_explode(string $key, $default = null, string $delimiter = ',', int
$env = env($key, $default);

if (\is_string($env)) {
return explode($delimiter, $env, $limit);
return $env ? explode($delimiter, $env, $limit) : [];
}

return $env;
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/HeplersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

it('can explode env', function (): void {
expect(env_explode('ENV_EXPLODE_STRING'))->toBeArray()->toBeTruthy()
->and(env_explode('ENV_EXPLODE_EMPTY'))->toBe([''])
->and(env_explode('ENV_EXPLODE_EMPTY'))->toBe([])
->and(env_explode('ENV_EXPLODE_NOT_EXIST'))->toBeNull();
// ->and(env_explode('ENV_EXPLODE_TRUE'))->toBeTrue()
// ->and(env_explode('ENV_EXPLODE_FALSE'))->toBeFalse()
Expand Down

0 comments on commit c00f1a2

Please sign in to comment.