PowerCycleCommandTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\PowerCycleCommand;
  15. /**
  16. * @author Antoine Corcy <contact@sbin.dk>
  17. */
  18. class PowerCycleCommandTest 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. $PowerCycleCommand = $this->getMock('\DigitalOcean\CLI\Droplets\PowerCycleCommand', array('getDigitalOcean'));
  31. $PowerCycleCommand
  32. ->expects($this->any())
  33. ->method('getDigitalOcean')
  34. ->will($this->returnValue($this->getMockDigitalOcean('droplets', $this->getMockDroplets('powerCycle', $result))));
  35. $this->application->add($PowerCycleCommand);
  36. $this->command = $this->application->find('droplets:power-cycle');
  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 testExecuteCheckStatus()
  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 testExecuteCheckEventId()
  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. }