CreateCommandTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\CreateCommand;
  15. /**
  16. * @author Antoine Corcy <contact@sbin.dk>
  17. */
  18. class CreateCommandTest 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. 'droplet' => (object) array (
  29. 'id' => 100824,
  30. 'name' => 'foo',
  31. 'image_id' => 9876,
  32. 'size_id' => 32,
  33. 'event_id' => 1234,
  34. ),
  35. );
  36. $CreateCommand = $this->getMock('\DigitalOcean\CLI\Droplets\CreateCommand', array('getDigitalOcean'));
  37. $CreateCommand
  38. ->expects($this->any())
  39. ->method('getDigitalOcean')
  40. ->will($this->returnValue($this->getMockDigitalOcean('droplets', $this->getMockDroplets('create', $result))));
  41. $this->application->add($CreateCommand);
  42. $this->command = $this->application->find('droplets:create');
  43. $this->commandTester = new CommandTester($this->command);
  44. }
  45. /**
  46. * @expectedException \RuntimeException
  47. * @expectedExceptionMessage Not enough arguments.
  48. */
  49. public function testExecuteNotEnoughArguments()
  50. {
  51. $this->commandTester->execute(array(
  52. 'command' => $this->command->getName(),
  53. ));
  54. }
  55. public function testExecuteCheckStatus()
  56. {
  57. $this->commandTester->execute(array(
  58. 'command' => $this->command->getName(),
  59. 'name' => 'foo',
  60. 'size_id' => 123,
  61. 'image_id' => 456,
  62. 'region_id' => 789,
  63. ));
  64. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  65. $this->assertRegExp('/\| OK \|/', $this->commandTester->getDisplay());
  66. }
  67. public function testExecuteCheckEventId()
  68. {
  69. $this->commandTester->execute(array(
  70. 'command' => $this->command->getName(),
  71. 'name' => 'foo',
  72. 'size_id' => 123,
  73. 'image_id' => 456,
  74. 'region_id' => 789,
  75. ));
  76. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  77. $this->assertRegExp('/\| 1234 \|/', $this->commandTester->getDisplay());
  78. }
  79. public function testExecuteWithSSHKeysCheckStatus()
  80. {
  81. $this->commandTester->execute(array(
  82. 'command' => $this->command->getName(),
  83. 'name' => 'foo',
  84. 'size_id' => 123,
  85. 'image_id' => 456,
  86. 'region_id' => 789,
  87. 'ssh_key_ids' => '1,2,3',
  88. ));
  89. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  90. $this->assertRegExp('/\| OK \|/', $this->commandTester->getDisplay());
  91. }
  92. public function testExecuteWithSSHKeysCheckEventId()
  93. {
  94. $this->commandTester->execute(array(
  95. 'command' => $this->command->getName(),
  96. 'name' => 'foo',
  97. 'size_id' => 123,
  98. 'image_id' => 456,
  99. 'region_id' => 789,
  100. 'ssh_key_ids' => '1,2,3',
  101. ));
  102. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  103. $this->assertRegExp('/\| 1234 \|/', $this->commandTester->getDisplay());
  104. }
  105. }