InvalidateLoggerTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * \Magento\Framework\Cache\InvalidateLogger test case
  8. */
  9. namespace Magento\Framework\Cache\Test\Unit;
  10. class InvalidateLoggerTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\Request\Http */
  13. protected $requestMock;
  14. /** @var \PHPUnit_Framework_MockObject_MockObject | \Psr\Log\LoggerInterface */
  15. protected $loggerMock;
  16. /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Cache\InvalidateLogger */
  17. protected $invalidateLogger;
  18. /** @var string */
  19. protected $method = 'GET';
  20. /** @var string */
  21. protected $url = 'http://website.com/home';
  22. /** @var array */
  23. protected $params = ['param1', 'param2'];
  24. protected function setUp()
  25. {
  26. $this->requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
  27. $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
  28. $this->invalidateLogger = new \Magento\Framework\Cache\InvalidateLogger(
  29. $this->requestMock,
  30. $this->loggerMock
  31. );
  32. $this->requestMock->expects($this->once())
  33. ->method('getMethod')
  34. ->willReturn($this->method);
  35. $this->requestMock->expects($this->once())
  36. ->method('getUriString')
  37. ->willReturn($this->url);
  38. }
  39. public function testCritical()
  40. {
  41. $this->loggerMock->expects($this->once())
  42. ->method('critical')
  43. ->with('message', ['method' => $this->method, 'url' => $this->url, 'invalidateInfo' => $this->params]);
  44. $this->invalidateLogger->critical('message', $this->params);
  45. }
  46. public function testExecute()
  47. {
  48. $this->loggerMock->expects($this->once())
  49. ->method('debug')
  50. ->with(
  51. 'cache_invalidate: ',
  52. ['method' => $this->method, 'url' => $this->url, 'invalidateInfo' => $this->params]
  53. );
  54. $this->invalidateLogger->execute($this->params);
  55. }
  56. public function testMakeParams()
  57. {
  58. $expected = ['method' => $this->method, 'url' => $this->url, 'invalidateInfo' => $this->params];
  59. $method = new \ReflectionMethod($this->invalidateLogger, 'makeParams');
  60. $method->setAccessible(true);
  61. $this->assertEquals(
  62. $expected,
  63. $method->invoke($this->invalidateLogger, $this->params)
  64. );
  65. }
  66. protected function tearDown()
  67. {
  68. unset($this->requestMock);
  69. unset($this->loggerMock);
  70. }
  71. }