|
6 | 6 | use DevCoder\Option;
|
7 | 7 | use DevCoder\Processor\BooleanProcessor;
|
8 | 8 | use DevCoder\Processor\QuotedProcessor;
|
| 9 | +use PHPUnit\Framework\Assert; |
9 | 10 | use PHPUnit\Framework\TestCase;
|
10 | 11 |
|
11 | 12 | class DotenvTest extends TestCase
|
@@ -53,6 +54,52 @@ public function testFileNotExist() {
|
53 | 54 | (new DotEnv($this->env('.env.not-exists')))->load();
|
54 | 55 | }
|
55 | 56 |
|
| 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 | + |
56 | 103 | /**
|
57 | 104 | * @runInSeparateProcess
|
58 | 105 | */
|
|
0 commit comments