Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExportVarnishConfigTest.php
Go to the documentation of this file.
1 <?php
11 
13 
18 class ExportVarnishConfigTest extends \PHPUnit\Framework\TestCase
19 {
23  protected $requestMock;
24 
28  protected $responseMock;
29 
33  protected $viewMock;
34 
38  protected $action;
39 
43  protected $fileFactoryMock;
44 
48  protected $configMock;
49 
53  protected function setUp()
54  {
55  $this->fileFactoryMock = $this->getMockBuilder(
56  \Magento\Framework\App\Response\Http\FileFactory::class
57  )->disableOriginalConstructor()->getMock();
58  $this->configMock = $this->getMockBuilder(
59  \Magento\PageCache\Model\Config::class
60  )->disableOriginalConstructor()->getMock();
61  $contextMock = $this->getMockBuilder(
62  \Magento\Backend\App\Action\Context::class
63  )->disableOriginalConstructor()->getMock();
64 
65  $this->requestMock = $this->getMockBuilder(
66  \Magento\Framework\App\Request\Http::class
67  )->disableOriginalConstructor()->getMock();
68  $this->responseMock = $this->getMockBuilder(
69  \Magento\Framework\App\Response\Http::class
70  )->disableOriginalConstructor()->getMock();
71  $this->viewMock = $this->getMockBuilder(
72  \Magento\Framework\App\View::class
73  )->disableOriginalConstructor()->getMock();
74 
75  $contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock));
76  $contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock));
77  $contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->viewMock));
78 
79  $this->action = new \Magento\PageCache\Controller\Adminhtml\PageCache\ExportVarnishConfig(
80  $contextMock,
81  $this->fileFactoryMock,
82  $this->configMock
83  );
84  }
85 
87  {
88  $fileContent = 'some conetnt';
89  $filename = 'varnish.vcl';
90  $responseMock = $this->getMockBuilder(
91  \Magento\Framework\App\ResponseInterface::class
92  )->disableOriginalConstructor()->getMock();
93 
94  $this->configMock->expects($this->once())->method('getVclFile')->will($this->returnValue($fileContent));
95  $this->fileFactoryMock->expects(
96  $this->once()
97  )->method(
98  'create'
99  )->with(
100  $this->equalTo($filename),
101  $this->equalTo($fileContent),
102  $this->equalTo(DirectoryList::VAR_DIR)
103  )->will(
104  $this->returnValue($responseMock)
105  );
106 
107  $result = $this->action->execute();
108  $this->assertInstanceOf(\Magento\Framework\App\ResponseInterface::class, $result);
109  }
110 }