diff --git a/src/Environment/DotenvFactory.php b/src/Environment/DotenvFactory.php index 0c63a64c..c71fd44a 100644 --- a/src/Environment/DotenvFactory.php +++ b/src/Environment/DotenvFactory.php @@ -31,7 +31,7 @@ class DotenvFactory implements FactoryInterface */ public function __construct(array $adapters = null) { - $this->adapters = array_filter($adapters ?: [new ApacheAdapter(), new EnvConstAdapter(), new ServerConstAdapter(), new PutenvAdapter()], function (AdapterInterface $adapter) { + $this->adapters = array_filter($adapters === null ? [new ApacheAdapter(), new EnvConstAdapter(), new ServerConstAdapter(), new PutenvAdapter()] : $adapters, function (AdapterInterface $adapter) { return $adapter->isSupported(); }); } diff --git a/tests/Dotenv/FactoryTest.php b/tests/Dotenv/FactoryTest.php new file mode 100644 index 00000000..44bac3bb --- /dev/null +++ b/tests/Dotenv/FactoryTest.php @@ -0,0 +1,44 @@ +getProperty('adapters'); + + $prop->setAccessible(true); + + return $prop->getValue($obj); + } + + public function testDefaults() + { + $f = new DotenvFactory(); + + $this->assertInstanceOf('Dotenv\Environment\FactoryInterface', $f); + $this->assertCount(3, self::getAdapters($f->create())); + $this->assertCount(3, self::getAdapters($f->createImmutable())); + } + + public function testSingle() + { + $f = new DotenvFactory([new EnvConstAdapter()]); + + $this->assertInstanceOf('Dotenv\Environment\FactoryInterface', $f); + $this->assertCount(1, self::getAdapters($f->create())); + $this->assertCount(1, self::getAdapters($f->createImmutable())); + } + + public function testNone() + { + $f = new DotenvFactory([]); + + $this->assertInstanceOf('Dotenv\Environment\FactoryInterface', $f); + $this->assertCount(0, self::getAdapters($f->create())); + $this->assertCount(0, self::getAdapters($f->createImmutable())); + } +}