CronRemoveCommandTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Cron\Test\Unit\Console\Command;
  7. use Symfony\Component\Console\Tester\CommandTester;
  8. use Magento\Cron\Console\Command\CronRemoveCommand;
  9. use Magento\Framework\Crontab\CrontabManagerInterface;
  10. use Magento\Framework\Console\Cli;
  11. use Magento\Framework\Exception\LocalizedException;
  12. use Magento\Framework\Phrase;
  13. class CronRemoveCommandTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var CrontabManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  17. */
  18. private $crontabManagerMock;
  19. /**
  20. * @var CommandTester
  21. */
  22. private $commandTester;
  23. /**
  24. * @return void
  25. */
  26. protected function setUp()
  27. {
  28. $this->crontabManagerMock = $this->getMockBuilder(CrontabManagerInterface::class)
  29. ->getMockForAbstractClass();
  30. $this->commandTester = new CommandTester(
  31. new CronRemoveCommand($this->crontabManagerMock)
  32. );
  33. }
  34. /**
  35. * @return void
  36. */
  37. public function testExecute()
  38. {
  39. $this->crontabManagerMock->expects($this->once())
  40. ->method('RemoveTasks');
  41. $this->commandTester->execute([]);
  42. $this->assertEquals(
  43. 'Magento cron tasks have been removed' . PHP_EOL,
  44. $this->commandTester->getDisplay()
  45. );
  46. $this->assertEquals(Cli::RETURN_SUCCESS, $this->commandTester->getStatusCode());
  47. }
  48. /**
  49. * @return void
  50. */
  51. public function testExecuteFailed()
  52. {
  53. $this->crontabManagerMock->expects($this->once())
  54. ->method('RemoveTasks')
  55. ->willThrowException(new LocalizedException(new Phrase('Some error')));
  56. $this->commandTester->execute([]);
  57. $this->assertEquals(
  58. 'Some error' . PHP_EOL,
  59. $this->commandTester->getDisplay()
  60. );
  61. $this->assertEquals(Cli::RETURN_FAILURE, $this->commandTester->getStatusCode());
  62. }
  63. }