|
| 1 | +<?php |
| 2 | + |
| 3 | +use Dotenv\Environment\Adapter\EnvConstAdapter; |
| 4 | +use Dotenv\Environment\DotenvFactory; |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | + |
| 7 | +class FactoryTest extends TestCase |
| 8 | +{ |
| 9 | + private static function getAdapters($obj) |
| 10 | + { |
| 11 | + $prop = (new ReflectionClass($obj))->getProperty('adapters'); |
| 12 | + |
| 13 | + $prop->setAccessible(true); |
| 14 | + |
| 15 | + return $prop->getValue($obj); |
| 16 | + } |
| 17 | + |
| 18 | + public function testDefaults() |
| 19 | + { |
| 20 | + $f = new DotenvFactory(); |
| 21 | + |
| 22 | + $this->assertInstanceOf('Dotenv\Environment\FactoryInterface', $f); |
| 23 | + $this->assertCount(3, self::getAdapters($f->create())); |
| 24 | + $this->assertCount(3, self::getAdapters($f->createImmutable())); |
| 25 | + } |
| 26 | + |
| 27 | + public function testSingle() |
| 28 | + { |
| 29 | + $f = new DotenvFactory([new EnvConstAdapter()]); |
| 30 | + |
| 31 | + $this->assertInstanceOf('Dotenv\Environment\FactoryInterface', $f); |
| 32 | + $this->assertCount(1, self::getAdapters($f->create())); |
| 33 | + $this->assertCount(1, self::getAdapters($f->createImmutable())); |
| 34 | + } |
| 35 | + |
| 36 | + public function testNone() |
| 37 | + { |
| 38 | + $f = new DotenvFactory([]); |
| 39 | + |
| 40 | + $this->assertInstanceOf('Dotenv\Environment\FactoryInterface', $f); |
| 41 | + $this->assertCount(0, self::getAdapters($f->create())); |
| 42 | + $this->assertCount(0, self::getAdapters($f->createImmutable())); |
| 43 | + } |
| 44 | +} |
0 commit comments