DriverPoolTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Filesystem\Test\Unit;
  7. use \Magento\Framework\Filesystem\DriverPool;
  8. class DriverPoolTest extends \PHPUnit\Framework\TestCase
  9. {
  10. public function testGetDriver()
  11. {
  12. $object = new DriverPool();
  13. foreach ([DriverPool::FILE, DriverPool::HTTP, DriverPool::HTTPS, DriverPool::ZLIB] as $code) {
  14. $this->assertInstanceOf(\Magento\Framework\Filesystem\DriverInterface::class, $object->getDriver($code));
  15. }
  16. $default = $object->getDriver('');
  17. $this->assertInstanceOf(\Magento\Framework\Filesystem\Driver\File::class, $default);
  18. $this->assertSame($default, $object->getDriver(''));
  19. }
  20. public function testCustomDriver()
  21. {
  22. $customOne = $this->getMockForAbstractClass(\Magento\Framework\Filesystem\DriverInterface::class);
  23. $customTwo = get_class($this->getMockForAbstractClass(\Magento\Framework\Filesystem\DriverInterface::class));
  24. $object = new DriverPool(['customOne' => $customOne, 'customTwo' => $customTwo]);
  25. $this->assertSame($customOne, $object->getDriver('customOne'));
  26. $this->assertInstanceOf(\Magento\Framework\Filesystem\DriverInterface::class, $object->getDriver('customOne'));
  27. $this->assertEquals($customTwo, get_class($object->getDriver('customTwo')));
  28. $this->assertInstanceOf(\Magento\Framework\Filesystem\DriverInterface::class, $object->getDriver('customTwo'));
  29. }
  30. /**
  31. * @expectedException \InvalidArgumentException
  32. * @expectedExceptionMessage The specified type 'stdClass' does not implement DriverInterface.
  33. */
  34. public function testCustomDriverException()
  35. {
  36. new DriverPool(['custom' => new \StdClass()]);
  37. }
  38. }