LogRotateTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Test\Cron;
  7. use Vertex\Tax\Cron\LogRotate;
  8. use Vertex\Tax\Model\Config;
  9. use Vertex\Tax\Model\LogEntryRotator;
  10. use Vertex\Tax\Model\LogEntryRotatorFactory;
  11. use Vertex\Tax\Test\Unit\TestCase;
  12. /**
  13. * Test that LogRotate may be run under expected conditions.
  14. */
  15. class LogRotateTest extends TestCase
  16. {
  17. /** @var \PHPUnit_Framework_MockObject_MockObject|Config */
  18. private $configMock;
  19. /** @var LogRotate */
  20. private $logRotate;
  21. /** @var \PHPUnit_Framework_MockObject_MockObject|LogEntryRotatorFactory */
  22. private $logEntryRotatorFactoryMock;
  23. /**
  24. * Perform test setup.
  25. */
  26. protected function setUp()
  27. {
  28. parent::setUp();
  29. $this->configMock = $this->createMock(Config::class);
  30. $this->logEntryRotatorFactoryMock = $this->createMock(LogEntryRotatorFactory::class);
  31. $this->logRotate = $this->getObject(
  32. LogRotate::class,
  33. [
  34. 'logEntryRotatorFactory' => $this->logEntryRotatorFactoryMock,
  35. 'config' => $this->configMock,
  36. ]
  37. );
  38. }
  39. /**
  40. * Test that rotation may proceed when the feature is enabled.
  41. *
  42. * @covers \Vertex\Tax\Cron\LogRotate::execute()
  43. */
  44. public function testRunRotateWhenEnabled()
  45. {
  46. $this->configMock->method('isLogRotationEnabled')
  47. ->willReturn(true);
  48. $this->logEntryRotatorFactoryMock->expects($this->once())
  49. ->method('create')
  50. ->willReturn(
  51. $this->createMock(LogEntryRotator::class)
  52. );
  53. $this->logRotate->execute();
  54. }
  55. /**
  56. * Test that rotating does not run when the feature is disabled.
  57. *
  58. * @covers \Vertex\Tax\Cron\LogRotate::execute()
  59. */
  60. public function testSkipRotateWhenDisabled()
  61. {
  62. $this->configMock->method('isLogRotationEnabled')
  63. ->willReturn(false);
  64. $this->logEntryRotatorFactoryMock->expects($this->never())
  65. ->method('create')
  66. ->willReturn(
  67. $this->createMock(LogEntryRotator::class)
  68. );
  69. $this->logRotate->execute();
  70. }
  71. }