Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
WriteFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\Filesystem\File\WriteFactory;
9 
13 class WriteFactoryTest extends \PHPUnit\Framework\TestCase
14 {
15  public function testCreate()
16  {
17  $driverPool = $this->createPartialMock(\Magento\Framework\Filesystem\DriverPool::class, ['getDriver']);
18  $driverPool->expects($this->never())->method('getDriver');
19  $factory = new WriteFactory($driverPool);
20  $driver = $this->getMockForAbstractClass(\Magento\Framework\Filesystem\DriverInterface::class);
21  $driver->expects($this->any())->method('isExists')->willReturn(true);
22  $result = $factory->create('path', $driver);
23  $this->assertInstanceOf(\Magento\Framework\Filesystem\File\Write::class, $result);
24  }
25 
26  public function testCreateWithDriverCode()
27  {
28  $driverPool = $this->createPartialMock(\Magento\Framework\Filesystem\DriverPool::class, ['getDriver']);
29  $driverMock = $this->getMockForAbstractClass(\Magento\Framework\Filesystem\DriverInterface::class);
30  $driverMock->expects($this->any())->method('isExists')->willReturn(true);
31  $driverPool->expects($this->once())->method('getDriver')->willReturn($driverMock);
32  $factory = new WriteFactory($driverPool);
33  $result = $factory->create('path', 'driverCode');
34  $this->assertInstanceOf(\Magento\Framework\Filesystem\File\Write::class, $result);
35  }
36 
37  public function testCreateWithMode()
38  {
39  $driverPool = $this->createPartialMock(\Magento\Framework\Filesystem\DriverPool::class, ['getDriver']);
40  $driverPool->expects($this->never())->method('getDriver');
41  $driver = $this->getMockForAbstractClass(\Magento\Framework\Filesystem\DriverInterface::class);
42  $driver->expects($this->any())->method('isExists')->willReturn(true);
43  $factory = new WriteFactory($driverPool);
44  $result = $factory->create('path', $driver, 'a+');
45  $this->assertInstanceOf(\Magento\Framework\Filesystem\File\Write::class, $result);
46  }
47 }