Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SynchronizationTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class SynchronizationTest extends \PHPUnit\Framework\TestCase
11 {
12  public function testSynchronize()
13  {
14  $content = 'content';
15  $relativeFileName = 'config.xml';
16 
17  $storageFactoryMock = $this->createPartialMock(
18  \Magento\MediaStorage\Model\File\Storage\DatabaseFactory::class,
19  ['create', '_wakeup']
20  );
21  $storageMock = $this->createPartialMock(
22  \Magento\MediaStorage\Model\File\Storage\Database::class,
23  ['getContent', 'getId', 'loadByFilename', '__wakeup']
24  );
25  $storageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($storageMock));
26 
27  $storageMock->expects($this->once())->method('getContent')->will($this->returnValue($content));
28  $storageMock->expects($this->once())->method('getId')->will($this->returnValue(true));
29  $storageMock->expects($this->once())->method('loadByFilename');
30 
31  $file = $this->createPartialMock(
32  \Magento\Framework\Filesystem\File\Write::class,
33  ['lock', 'write', 'unlock', 'close']
34  );
35  $file->expects($this->once())->method('lock');
36  $file->expects($this->once())->method('write')->with($content);
37  $file->expects($this->once())->method('unlock');
38  $file->expects($this->once())->method('close');
39  $directory = $this->getMockForAbstractClass(\Magento\Framework\Filesystem\Directory\WriteInterface::class);
40  $directory->expects($this->once())
41  ->method('openFile')
42  ->with($relativeFileName)
43  ->will($this->returnValue($file));
44 
45  $objectManager = new ObjectManager($this);
46  $model = $objectManager->getObject(\Magento\MediaStorage\Model\File\Storage\Synchronization::class, [
47  'storageFactory' => $storageFactoryMock,
48  'directory' => $directory,
49  ]);
50  $model->synchronize($relativeFileName);
51  }
52 }
$objectManager
Definition: bootstrap.php:17