FactoryTest.php 1.2 KB

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