Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
VarnishPluginTest.php
Go to the documentation of this file.
1 <?php
7 
16 
20 class VarnishPluginTest extends \PHPUnit\Framework\TestCase
21 {
25  private $plugin;
26 
30  private $objectManagerHelper;
31 
35  private $configMock;
36 
40  private $versionMock;
41 
45  private $appStateMock;
46 
50  private $registryMock;
51 
55  private $resultMock;
56 
60  private $responseMock;
61 
62  protected function setUp()
63  {
64  $this->configMock = $this->getMockBuilder(Config::class)
65  ->disableOriginalConstructor()
66  ->getMock();
67  $this->versionMock = $this->getMockBuilder(Version::class)
68  ->disableOriginalConstructor()
69  ->getMock();
70  $this->appStateMock = $this->getMockBuilder(AppState::class)
71  ->disableOriginalConstructor()
72  ->getMock();
73  $this->registryMock = $this->getMockBuilder(Registry::class)
74  ->disableOriginalConstructor()
75  ->getMock();
76  $this->resultMock = $this->getMockBuilder(ResultInterface::class)
77  ->getMockForAbstractClass();
78  $this->responseMock = $this->getMockBuilder(ResponseHttp::class)
79  ->disableOriginalConstructor()
80  ->getMock();
81 
82  $this->objectManagerHelper = new ObjectManagerHelper($this);
83  $this->plugin = $this->objectManagerHelper->getObject(
84  VarnishPlugin::class,
85  [
86  'registry' => $this->registryMock,
87  'config' => $this->configMock,
88  'state' => $this->appStateMock,
89  'version' => $this->versionMock
90  ]
91  );
92  }
93 
102  public function testAfterRenderResult($usePlugin, $setCacheDebugHeaderCount, $getModeCount, $processCount)
103  {
104  $this->responseMock->expects(static::exactly($setCacheDebugHeaderCount))
105  ->method('setHeader')
106  ->with('X-Magento-Debug', 1);
107  $this->registryMock->expects(static::once())
108  ->method('registry')
109  ->with('use_page_cache_plugin')
110  ->willReturn($usePlugin);
111  $this->configMock->expects(static::once())
112  ->method('isEnabled')
113  ->willReturn(true);
114  $this->configMock->expects(static::once())
115  ->method('getType')
116  ->willReturn(Config::VARNISH);
117  $this->appStateMock->expects(static::exactly($getModeCount))
118  ->method('getMode')
119  ->willReturn(AppState::MODE_DEVELOPER);
120  $this->versionMock->expects(static::exactly($processCount))
121  ->method('process');
122 
123  $this->assertSame(
124  $this->resultMock,
125  $this->plugin->afterRenderResult($this->resultMock, $this->resultMock, $this->responseMock)
126  );
127  }
128 
133  {
134  return [
135  [true, 1, 1, 1],
136  [false, 0, 0, 0]
137  ];
138  }
139 }
testAfterRenderResult($usePlugin, $setCacheDebugHeaderCount, $getModeCount, $processCount)