ShowCommandTest.php 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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\SSHKeys;
  11. use Symfony\Component\Console\Application;
  12. use Symfony\Component\Console\Tester\CommandTester;
  13. use DigitalOcean\Tests\TestCase;
  14. use DigitalOcean\CLI\SSHKeys\ShowCommand;
  15. /**
  16. * @author Antoine Corcy <contact@sbin.dk>
  17. */
  18. class ShowCommandTest 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. 'ssh_key' => (object) array(
  28. 'id' => 123,
  29. 'name' => 'office-imac',
  30. 'ssh_pub_key' => 'ssh-dss AHJASDBVY6723bgBVhusadkih238723kjLKFnbkjGFklaslkhfgBAFFHGBJbju8)H3hnNGjASGFkjgZn86ZCqk02NX3BTcMV4YI2I4/sebg8VnuebDn0XUbbmVrAq4YqGiobn86ZCqk02NX3BTcMp4QGmyL4/sebg8Vnusytv93cA2PsXOxvbU0CdebDn0XUbbmVrAq4YqGiob48KzCT/NT6L6VoD5n+jSZvQAAAIAspspAelh4bW5ncO5+CedFZPZn86ZCqk02NX3BTcMV4YIaSCO43Y+ghI2of4+E1TDJ1R9Znk9XJsald/U0u0uXwtyHXP2sommNWuAGtzp4QGmyL4/sebg8Vnusytv93cA2PsXOxvbU0CdebDn0XUbbmVrAq4YqGiob48KzCT/NT6L6VoD5n+jSZflFD684gdLsW1+gjVoFBk0MZWuGSXEQyIwlBRq/8jAAAAFQDrxI/h35BewJUmVjid8Qk1NprMvQAAAIAspspAelh4bW5ncO5+CedFZPZn86ZCqk02NX3BTcMV4YI2IEzb6R2vzZkjCTuZVy6dcH3ag6JlEfju67euWT5yMnT1I0Ow== me@office-imac',
  31. )
  32. );
  33. $ShowCommand = $this->getMock('\DigitalOcean\CLI\SSHKeys\ShowCommand', array('getDigitalOcean'));
  34. $ShowCommand
  35. ->expects($this->any())
  36. ->method('getDigitalOcean')
  37. ->will($this->returnValue($this->getMockDigitalOcean('sshkeys', $this->getMockSSHKeys('show', $result))));
  38. $this->application->add($ShowCommand);
  39. $this->command = $this->application->find('ssh-keys:show');
  40. $this->commandTester = new CommandTester($this->command);
  41. }
  42. /**
  43. * @expectedException \RuntimeException
  44. * @expectedExceptionMessage Not enough arguments.
  45. */
  46. public function testExecuteNotEnoughArguments()
  47. {
  48. $this->commandTester->execute(array(
  49. 'command' => $this->command->getName(),
  50. ));
  51. }
  52. public function testExecute()
  53. {
  54. $this->commandTester->execute(array(
  55. 'command' => $this->command->getName(),
  56. 'id' => 123,
  57. ));
  58. $expected = <<<EOT
  59. +-----+-------------+----------------------------------------------------+
  60. | ID | Name | Pub Key |
  61. +-----+-------------+----------------------------------------------------+
  62. | 123 | office-imac | ssh-dss |
  63. | | | AHJASDBVY6723bgBVhusadkih238723kjLKFnbkjGFklaslkhf |
  64. | | | gBAFFHGBJbju8)H3hnNGjASGFkjgZn86ZCqk02NX3BTcMV4YI2 |
  65. | | | I4/sebg8VnuebDn0XUbbmVrAq4YqGiobn86ZCqk02NX3BTcMp4 |
  66. | | | QGmyL4/sebg8Vnusytv93cA2PsXOxvbU0CdebDn0XUbbmVrAq4 |
  67. | | | YqGiob48KzCT/NT6L6VoD5n+jSZvQAAAIAspspAelh4bW5ncO5 |
  68. | | | +CedFZPZn86ZCqk02NX3BTcMV4YIaSCO43Y+ghI2of4+E1TDJ1 |
  69. | | | R9Znk9XJsald/U0u0uXwtyHXP2sommNWuAGtzp4QGmyL4/sebg |
  70. | | | 8Vnusytv93cA2PsXOxvbU0CdebDn0XUbbmVrAq4YqGiob48KzC |
  71. | | | T/NT6L6VoD5n+jSZflFD684gdLsW1+gjVoFBk0MZWuGSXEQyIw |
  72. | | | lBRq/8jAAAAFQDrxI/h35BewJUmVjid8Qk1NprMvQAAAIAspsp |
  73. | | | Aelh4bW5ncO5+CedFZPZn86ZCqk02NX3BTcMV4YI2IEzb6R2vz |
  74. | | | ZkjCTuZVy6dcH3ag6JlEfju67euWT5yMnT1I0Ow== |
  75. | | | me@office-imac |
  76. +-----+-------------+----------------------------------------------------+
  77. EOT
  78. ;
  79. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  80. $this->assertSame($expected, $this->commandTester->getDisplay());
  81. }
  82. }