Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()));
}
}