Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractWriterTest.php
Go to the documentation of this file.
1 <?php
7 
8 class AbstractWriterTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $writer;
14 
18  protected $csvMock;
19 
20  protected function setUp()
21  {
22  $this->csvMock = $this->createMock(\Magento\Framework\File\Csv::class);
23 
24  $this->writer = $this->getMockForAbstractClass(
25  \Magento\Setup\Module\Dependency\Report\Writer\Csv\AbstractWriter::class,
26  ['writer' => $this->csvMock]
27  );
28  }
29 
30  public function testWrite()
31  {
32  $options = ['report_filename' => 'some_filename'];
33  $configMock = $this->createMock(\Magento\Setup\Module\Dependency\Report\Data\ConfigInterface::class);
34  $preparedData = ['foo', 'baz', 'bar'];
35 
36  $this->writer->expects(
37  $this->once()
38  )->method(
39  'prepareData'
40  )->with(
41  $configMock
42  )->will(
43  $this->returnValue($preparedData)
44  );
45  $this->csvMock->expects($this->once())->method('saveData')->with($options['report_filename'], $preparedData);
46 
47  $this->writer->write($options, $configMock);
48  }
49 
57  {
58  $configMock = $this->createMock(\Magento\Setup\Module\Dependency\Report\Data\ConfigInterface::class);
59 
60  $this->writer->write($options, $configMock);
61  }
62 
67  {
68  return [
69  [['report_filename' => '']],
70  [['there_are_no_report_filename' => 'some_name']]
71  ];
72  }
73 }