Skip to content

Commit

Permalink
Allow DotenvFactory to accept an empty array of adapters (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell authored Jan 23, 2019
1 parent 805c05a commit 13be13d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Environment/DotenvFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
44 changes: 44 additions & 0 deletions tests/Dotenv/FactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

use Dotenv\Environment\Adapter\EnvConstAdapter;
use Dotenv\Environment\DotenvFactory;
use PHPUnit\Framework\TestCase;

class FactoryTest extends TestCase
{
private static function getAdapters($obj)
{
$prop = (new ReflectionClass($obj))->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()));
}
}

0 comments on commit 13be13d

Please sign in to comment.