TransferCommandTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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\TransfertCommand;
  15. /**
  16. * @author Antoine Corcy <contact@sbin.dk>
  17. */
  18. class TransferCommandTest 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. $TransferCommand = $this->getMock('\DigitalOcean\CLI\Images\TransferCommand', array('getDigitalOcean'));
  31. $TransferCommand
  32. ->expects($this->any())
  33. ->method('getDigitalOcean')
  34. ->will($this->returnValue($this->getMockDigitalOcean('images', $this->getMockImages('transfert', $result))));
  35. $this->application->add($TransferCommand);
  36. $this->command = $this->application->find('images:transfer');
  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. /**
  50. * @expectedException \RuntimeException
  51. * @expectedExceptionMessage Not enough arguments.
  52. */
  53. public function testExecuteNotEnoughArgumentsWithoutName()
  54. {
  55. $this->commandTester->execute(array(
  56. 'command' => $this->command->getName(),
  57. 'id' => 123,
  58. ));
  59. }
  60. public function testExecuteCheckStatusConfirmed()
  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. 'region_id' => 345,
  68. ));
  69. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  70. $this->assertRegExp('/\| OK \|/', $this->commandTester->getDisplay());
  71. }
  72. public function testExecuteCheckEventIdConfirmed()
  73. {
  74. $dialog = $this->getDialogAskConfirmation(true);
  75. $this->command->getHelperSet()->set($dialog, 'dialog');
  76. $this->commandTester->execute(array(
  77. 'command' => $this->command->getName(),
  78. 'id' => 123,
  79. 'region_id' => 345,
  80. ));
  81. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  82. $this->assertRegExp('/\| 1234 \|/', $this->commandTester->getDisplay());
  83. }
  84. public function testExecuteCheckStatusNotConfirmed()
  85. {
  86. $dialog = $this->getDialogAskConfirmation(false);
  87. $this->command->getHelperSet()->set($dialog, 'dialog');
  88. $this->commandTester->execute(array(
  89. 'command' => $this->command->getName(),
  90. 'id' => 123,
  91. 'region_id' => 345,
  92. ));
  93. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  94. $this->assertRegExp('/Aborted!/', $this->commandTester->getDisplay());
  95. }
  96. public function testExecuteCheckEventIdNotConfirmed()
  97. {
  98. $dialog = $this->getDialogAskConfirmation(false);
  99. $this->command->getHelperSet()->set($dialog, 'dialog');
  100. $this->commandTester->execute(array(
  101. 'command' => $this->command->getName(),
  102. 'id' => 123,
  103. 'region_id' => 345,
  104. ));
  105. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  106. $this->assertRegExp('/Aborted!/', $this->commandTester->getDisplay());
  107. }
  108. }