Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GenerateSearchResultsTest.php
Go to the documentation of this file.
1 <?php
7 
11 class GenerateSearchResultsTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $ioObjectMock;
17 
21  protected function setUp()
22  {
23  $this->ioObjectMock = $this->createMock(\Magento\Framework\Code\Generator\Io::class);
24  }
25 
29  public function testGenerate()
30  {
31  require_once __DIR__ . '/Sample.php';
32  $model = $this->getMockBuilder(\Magento\Framework\Api\Code\Generator\SearchResults::class)
33  ->setMethods(['_validateData'])
34  ->setConstructorArgs(
35  [\Magento\Framework\Api\Code\Generator\Sample::class,
36  null,
37  $this->ioObjectMock,
38  null,
39  null,
40  $this->createMock(\Magento\Framework\Filesystem\FileResolver::class)
41  ]
42  )
43  ->getMock();
44  $sampleSearchResultBuilderCode = file_get_contents(__DIR__ . '/_files/SampleSearchResults.txt');
45  $this->ioObjectMock->expects($this->once())
46  ->method('generateResultFileName')
47  ->with('\\' . \Magento\Framework\Api\Code\Generator\SampleSearchResults::class)
48  ->will($this->returnValue('SampleSearchResults.php'));
49  $this->ioObjectMock->expects($this->once())
50  ->method('writeResultFile')
51  ->with('SampleSearchResults.php', $sampleSearchResultBuilderCode);
52 
53  $model->expects($this->once())
54  ->method('_validateData')
55  ->will($this->returnValue(true));
56  $this->assertEquals('SampleSearchResults.php', $model->generate());
57  }
58 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60