RebootCommandTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * This file is part of the DigitalOcean library.
  4. *
  5. * (c) Antoine Corcy <contact@sbin.dk>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace DigitalOcean\Tests\CLI\Droplets;
  11. use Symfony\Component\Console\Application;
  12. use Symfony\Component\Console\Tester\CommandTester;
  13. use DigitalOcean\Tests\TestCase;
  14. use DigitalOcean\CLI\Droplets\RebootCommand;
  15. /**
  16. * @author Antoine Corcy <contact@sbin.dk>
  17. */
  18. class RebootCommandTest extends TestCase
  19. {
  20. protected $application;
  21. protected $command;
  22. protected $commandTester;
  23. protected function setUp()
  24. {
  25. $this->application = new Application();
  26. $result = (object) array(
  27. 'status' => 'OK',
  28. 'event_id' => 1234,
  29. );
  30. $RebootCommand = $this->getMock('\DigitalOcean\CLI\Droplets\RebootCommand', array('getDigitalOcean'));
  31. $RebootCommand
  32. ->expects($this->any())
  33. ->method('getDigitalOcean')
  34. ->will($this->returnValue($this->getMockDigitalOcean('droplets', $this->getMockDroplets('reboot', $result))));
  35. $this->application->add($RebootCommand);
  36. $this->command = $this->application->find('droplets:reboot');
  37. $this->commandTester = new CommandTester($this->command);
  38. }
  39. /**
  40. * @expectedException \RuntimeException
  41. * @expectedExceptionMessage Not enough arguments.
  42. */
  43. public function testExecuteNotEnoughArguments()
  44. {
  45. $this->commandTester->execute(array(
  46. 'command' => $this->command->getName(),
  47. ));
  48. }
  49. public function testExecuteCheckStatusConfirmed()
  50. {
  51. $dialog = $this->getDialogAskConfirmation(true);
  52. $this->command->getHelperSet()->set($dialog, 'dialog');
  53. $this->commandTester->execute(array(
  54. 'command' => $this->command->getName(),
  55. 'id' => 123,
  56. ));
  57. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  58. $this->assertRegExp('/\| OK \|/', $this->commandTester->getDisplay());
  59. }
  60. public function testExecuteCheckEventIdConfirmed()
  61. {
  62. $dialog = $this->getDialogAskConfirmation(true);
  63. $this->command->getHelperSet()->set($dialog, 'dialog');
  64. $this->commandTester->execute(array(
  65. 'command' => $this->command->getName(),
  66. 'id' => 123,
  67. ));
  68. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  69. $this->assertRegExp('/\| 1234 \|/', $this->commandTester->getDisplay());
  70. }
  71. public function testExecuteCheckStatusNotConfirmed()
  72. {
  73. $dialog = $this->getDialogAskConfirmation(false);
  74. $this->command->getHelperSet()->set($dialog, 'dialog');
  75. $this->commandTester->execute(array(
  76. 'command' => $this->command->getName(),
  77. 'id' => 123,
  78. ));
  79. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  80. $this->assertRegExp('/Aborted!/', $this->commandTester->getDisplay());
  81. }
  82. public function testExecuteCheckEventIdNotConfirmed()
  83. {
  84. $dialog = $this->getDialogAskConfirmation(false);
  85. $this->command->getHelperSet()->set($dialog, 'dialog');
  86. $this->commandTester->execute(array(
  87. 'command' => $this->command->getName(),
  88. 'id' => 123,
  89. ));
  90. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  91. $this->assertRegExp('/Aborted!/', $this->commandTester->getDisplay());
  92. }
  93. }