Skip to content

Commit 13be13d

Browse files
Allow DotenvFactory to accept an empty array of adapters (#320)
1 parent 805c05a commit 13be13d

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/Environment/DotenvFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class DotenvFactory implements FactoryInterface
3131
*/
3232
public function __construct(array $adapters = null)
3333
{
34-
$this->adapters = array_filter($adapters ?: [new ApacheAdapter(), new EnvConstAdapter(), new ServerConstAdapter(), new PutenvAdapter()], function (AdapterInterface $adapter) {
34+
$this->adapters = array_filter($adapters === null ? [new ApacheAdapter(), new EnvConstAdapter(), new ServerConstAdapter(), new PutenvAdapter()] : $adapters, function (AdapterInterface $adapter) {
3535
return $adapter->isSupported();
3636
});
3737
}

tests/Dotenv/FactoryTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

Comments
 (0)