Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CronRemoveCommandTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Symfony\Component\Console\Tester\CommandTester;
14 
15 class CronRemoveCommandTest extends \PHPUnit\Framework\TestCase
16 {
20  private $crontabManagerMock;
21 
25  private $commandTester;
26 
30  protected function setUp()
31  {
32  $this->crontabManagerMock = $this->getMockBuilder(CrontabManagerInterface::class)
33  ->getMockForAbstractClass();
34 
35  $this->commandTester = new CommandTester(
36  new CronRemoveCommand($this->crontabManagerMock)
37  );
38  }
39 
43  public function testExecute()
44  {
45  $this->crontabManagerMock->expects($this->once())
46  ->method('RemoveTasks');
47 
48  $this->commandTester->execute([]);
49  $this->assertEquals(
50  'Magento cron tasks have been removed' . PHP_EOL,
51  $this->commandTester->getDisplay()
52  );
53  $this->assertEquals(Cli::RETURN_SUCCESS, $this->commandTester->getStatusCode());
54  }
55 
59  public function testExecuteFailed()
60  {
61  $this->crontabManagerMock->expects($this->once())
62  ->method('RemoveTasks')
63  ->willThrowException(new LocalizedException(new Phrase('Some error')));
64 
65  $this->commandTester->execute([]);
66  $this->assertEquals(
67  'Some error' . PHP_EOL,
68  $this->commandTester->getDisplay()
69  );
70  $this->assertEquals(Cli::RETURN_FAILURE, $this->commandTester->getStatusCode());
71  }
72 }