SnapshotCommandTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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\SnapshotCommand;
  15. /**
  16. * @author Antoine Corcy <contact@sbin.dk>
  17. */
  18. class SnapshotCommandTest 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. $SnapshotCommand = $this->getMock('\DigitalOcean\CLI\Droplets\SnapshotCommand', array('getDigitalOcean'));
  31. $SnapshotCommand
  32. ->expects($this->any())
  33. ->method('getDigitalOcean')
  34. ->will($this->returnValue($this->getMockDigitalOcean('droplets', $this->getMockDroplets('snapshot', $result))));
  35. $this->application->add($SnapshotCommand);
  36. $this->command = $this->application->find('droplets:snapshot');
  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 testExecuteWithoutNameCheckStatus()
  50. {
  51. $this->commandTester->execute(array(
  52. 'command' => $this->command->getName(),
  53. 'id' => 123,
  54. ));
  55. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  56. $this->assertRegExp('/\| OK \|/', $this->commandTester->getDisplay());
  57. }
  58. public function testExecuteWithoutNameCheckEventId()
  59. {
  60. $this->commandTester->execute(array(
  61. 'command' => $this->command->getName(),
  62. 'id' => 123,
  63. ));
  64. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  65. $this->assertRegExp('/\| 1234 \|/', $this->commandTester->getDisplay());
  66. }
  67. public function testExecuteCheckStatus()
  68. {
  69. $this->commandTester->execute(array(
  70. 'command' => $this->command->getName(),
  71. 'id' => 123,
  72. 'name' => 'foo',
  73. ));
  74. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  75. $this->assertRegExp('/\| OK \|/', $this->commandTester->getDisplay());
  76. }
  77. public function testExecuteCheckEventId()
  78. {
  79. $this->commandTester->execute(array(
  80. 'command' => $this->command->getName(),
  81. 'id' => 123,
  82. 'name' => 'foo',
  83. ));
  84. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  85. $this->assertRegExp('/\| 1234 \|/', $this->commandTester->getDisplay());
  86. }
  87. }