Skip to content

Commit 1c906db

Browse files
committed
Add test and refactor
1 parent 8305ce9 commit 1c906db

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/DotEnv.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private function setProcessors(array $processors = null) : DotEnv
3838
/**
3939
* Fill with default processors
4040
*/
41-
if ($processors === null){
41+
if ($processors === null) {
4242
$this->processors = [
4343
BooleanProcessor::class,
4444
QuotedProcessor::class

src/Processor/QuotedProcessor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function execute()
2424
return substr($this->value, 1, -1);
2525
}
2626

27-
public function isWrappedByChar(string $value, string $char) : bool
27+
private function isWrappedByChar(string $value, string $char) : bool
2828
{
2929
return $value[0] === $char && $value[-1] === $char;
3030
}

tests/DotenvTest.php

+47
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use DevCoder\Option;
77
use DevCoder\Processor\BooleanProcessor;
88
use DevCoder\Processor\QuotedProcessor;
9+
use PHPUnit\Framework\Assert;
910
use PHPUnit\Framework\TestCase;
1011

1112
class DotenvTest extends TestCase
@@ -53,6 +54,52 @@ public function testFileNotExist() {
5354
(new DotEnv($this->env('.env.not-exists')))->load();
5455
}
5556

57+
public function testUncompatibleProcessors() {
58+
$this->assertProcessors(
59+
[],
60+
[]
61+
);
62+
63+
$this->assertProcessors(
64+
null,
65+
[BooleanProcessor::class, QuotedProcessor::class]
66+
);
67+
68+
$this->assertProcessors(
69+
[null],
70+
[]
71+
);
72+
73+
$this->assertProcessors(
74+
[new \stdClass()],
75+
[]
76+
);
77+
78+
$this->assertProcessors(
79+
[QuotedProcessor::class, null],
80+
[QuotedProcessor::class]
81+
);
82+
}
83+
84+
private function assertProcessors(array $processorsToUse = null, array $expectedProcessors = [])
85+
{
86+
$dotEnv = new DotEnv($this->env('.env.default'), $processorsToUse);
87+
$dotEnv->load();
88+
89+
$this->assertEquals(
90+
$expectedProcessors,
91+
$this->getProtectedProperty($dotEnv, 'processors')
92+
);
93+
}
94+
95+
private function getProtectedProperty(object $object, string $property) {
96+
$reflection = new \ReflectionClass($object);
97+
$reflectionProperty = $reflection->getProperty($property);
98+
$reflectionProperty->setAccessible(true);
99+
100+
return $reflectionProperty->getValue($object);
101+
}
102+
56103
/**
57104
* @runInSeparateProcess
58105
*/

0 commit comments

Comments
 (0)