Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FileReaderTest.php
Go to the documentation of this file.
1 <?php
7 
13 use \PHPUnit_Framework_MockObject_MockObject as Mock;
14 
18 class FileReaderTest extends \PHPUnit\Framework\TestCase
19 {
23  private $model;
24 
28  private $dirListMock;
29 
33  private $driverPoolMock;
34 
38  private $configFilePool;
39 
43  private $driverMock;
44 
45  protected function setUp()
46  {
47  $this->dirListMock = $this->getMockBuilder(DirectoryList::class)
48  ->disableOriginalConstructor()
49  ->getMock();
50  $this->driverPoolMock = $this->getMockBuilder(DriverPool::class)
51  ->disableOriginalConstructor()
52  ->getMock();
53  $this->configFilePool = $this->getMockBuilder(ConfigFilePool::class)
54  ->disableOriginalConstructor()
55  ->getMock();
56  $this->driverMock = $this->getMockBuilder(DriverInterface::class)
57  ->getMockForAbstractClass();
58 
59  $this->model = new FileReader(
60  $this->dirListMock,
61  $this->driverPoolMock,
62  $this->configFilePool
63  );
64  }
65 
66  public function testLoad()
67  {
68  $fileKey = 'configKeyOne';
69 
70  $this->dirListMock->expects($this->exactly(2))
71  ->method('getPath')
72  ->with(DirectoryList::CONFIG)
73  ->willReturn(__DIR__ . '/_files');
74  $this->driverPoolMock->expects($this->exactly(2))
75  ->method('getDriver')
76  ->with(DriverPool::FILE)
77  ->willReturn($this->driverMock);
78  $this->configFilePool->expects($this->exactly(2))
79  ->method('getPath')
80  ->willReturnMap([['configKeyOne', 'config.php']]);
81  $this->driverMock->expects($this->exactly(2))
82  ->method('isExists')
83  ->willReturnOnConsecutiveCalls(true, false);
84  $this->configFilePool
85  ->expects($this->any())
86  ->method('getPath')
87  ->willReturnMap([['configKeyOne', 'config.php']]);
88 
89  $this->assertSame(['fooKey' => 'foo', 'barKey' => 'bar'], $this->model->load($fileKey));
90  $this->assertSame([], $this->model->load($fileKey));
91  }
92 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60