Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InvalidateLoggerTest.php
Go to the documentation of this file.
1 <?php
11 
12 class InvalidateLoggerTest extends \PHPUnit\Framework\TestCase
13 {
15  protected $requestMock;
16 
18  protected $loggerMock;
19 
21  protected $invalidateLogger;
22 
24  protected $method = 'GET';
25 
27  protected $url = 'http://website.com/home';
28 
30  protected $params = ['param1', 'param2'];
31 
32  protected function setUp()
33  {
34  $this->requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
35  $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
36  $this->invalidateLogger = new \Magento\Framework\Cache\InvalidateLogger(
37  $this->requestMock,
38  $this->loggerMock
39  );
40  $this->requestMock->expects($this->once())
41  ->method('getMethod')
42  ->willReturn($this->method);
43  $this->requestMock->expects($this->once())
44  ->method('getUriString')
45  ->willReturn($this->url);
46  }
47 
48  public function testCritical()
49  {
50  $this->loggerMock->expects($this->once())
51  ->method('critical')
52  ->with('message', ['method' => $this->method, 'url' => $this->url, 'invalidateInfo' => $this->params]);
53  $this->invalidateLogger->critical('message', $this->params);
54  }
55 
56  public function testExecute()
57  {
58  $this->loggerMock->expects($this->once())
59  ->method('debug')
60  ->with(
61  'cache_invalidate: ',
62  ['method' => $this->method, 'url' => $this->url, 'invalidateInfo' => $this->params]
63  );
64  $this->invalidateLogger->execute($this->params);
65  }
66 
67  public function testMakeParams()
68  {
69  $expected = ['method' => $this->method, 'url' => $this->url, 'invalidateInfo' => $this->params];
70  $method = new \ReflectionMethod($this->invalidateLogger, 'makeParams');
71  $method->setAccessible(true);
72  $this->assertEquals(
73  $expected,
74  $method->invoke($this->invalidateLogger, $this->params)
75  );
76  }
77 
78  protected function tearDown()
79  {
80  unset($this->requestMock);
81  unset($this->loggerMock);
82  }
83 }