DestroyCommandTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\Images;
  11. use Symfony\Component\Console\Application;
  12. use Symfony\Component\Console\Tester\CommandTester;
  13. use DigitalOcean\Tests\TestCase;
  14. use DigitalOcean\CLI\Images\DestroyCommand;
  15. /**
  16. * @author Antoine Corcy <contact@sbin.dk>
  17. */
  18. class DestroyCommandTest 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. );
  29. $DestroyCommand = $this->getMock('\DigitalOcean\CLI\Images\DestroyCommand', array('getDigitalOcean'));
  30. $DestroyCommand
  31. ->expects($this->any())
  32. ->method('getDigitalOcean')
  33. ->will($this->returnValue($this->getMockDigitalOcean('images', $this->getMockImages('destroy', $result))));
  34. $this->application->add($DestroyCommand);
  35. $this->command = $this->application->find('images:destroy');
  36. $this->commandTester = new CommandTester($this->command);
  37. }
  38. /**
  39. * @expectedException \RuntimeException
  40. * @expectedExceptionMessage Not enough arguments.
  41. */
  42. public function testExecuteNotEnoughArguments()
  43. {
  44. $this->commandTester->execute(array(
  45. 'command' => $this->command->getName(),
  46. ));
  47. }
  48. public function testExecuteCheckStatusConfirmed()
  49. {
  50. $dialog = $this->getDialogAskConfirmation(true);
  51. $this->command->getHelperSet()->set($dialog, 'dialog');
  52. $this->commandTester->execute(array(
  53. 'command' => $this->command->getName(),
  54. 'id' => 999,
  55. ));
  56. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  57. $this->assertRegExp('/\| OK \|/', $this->commandTester->getDisplay());
  58. }
  59. public function testExecuteCheckStatusNotConfirmed()
  60. {
  61. $dialog = $this->getDialogAskConfirmation(false);
  62. $this->command->getHelperSet()->set($dialog, 'dialog');
  63. $this->commandTester->execute(array(
  64. 'command' => $this->command->getName(),
  65. 'id' => 999,
  66. ));
  67. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  68. $this->assertRegExp('/Aborted!/', $this->commandTester->getDisplay());
  69. }
  70. }