ShowCommandTest.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\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. 'droplet' => (object) array(
  28. 'id' => 123,
  29. 'name' => 'foo',
  30. 'image_id' => 98,
  31. 'size_id' => 76,
  32. 'region_id' => 54,
  33. 'backups_active' => 1,
  34. 'ip_address' => '127.0.0.1',
  35. 'private_ip_address' => null,
  36. 'status' => 'active',
  37. 'locked' => false,
  38. 'created_at' => '2013-01-01T09:30:00Z',
  39. 'backups' => array(0, 1, 2, 3, 4, 5, 6),
  40. 'snapshots' => array(0),
  41. )
  42. );
  43. $ShowCommand = $this->getMock('\DigitalOcean\CLI\Droplets\ShowCommand', array('getDigitalOcean'));
  44. $ShowCommand
  45. ->expects($this->any())
  46. ->method('getDigitalOcean')
  47. ->will($this->returnValue($this->getMockDigitalOcean('droplets', $this->getMockDroplets('show', $result))));
  48. $this->application->add($ShowCommand);
  49. $this->command = $this->application->find('droplets:show');
  50. $this->commandTester = new CommandTester($this->command);
  51. }
  52. /**
  53. * @expectedException \RuntimeException
  54. * @expectedExceptionMessage Not enough arguments.
  55. */
  56. public function testExecuteNotEnoughArguments()
  57. {
  58. $this->commandTester->execute(array(
  59. 'command' => $this->command->getName(),
  60. ));
  61. }
  62. public function testExecute()
  63. {
  64. $this->commandTester->execute(array(
  65. 'command' => $this->command->getName(),
  66. 'id' => 123,
  67. ));
  68. $expected = <<<EOT
  69. +-----+------+----------+---------+-----------+----------------+---------+-----------+------------+--------------------+--------+--------+----------------------+
  70. | ID | Name | Image ID | Size ID | Region ID | Backups Active | Backups | Snapshots | IP Address | Private IP Address | Status | Locked | Created At |
  71. +-----+------+----------+---------+-----------+----------------+---------+-----------+------------+--------------------+--------+--------+----------------------+
  72. | 123 | foo | 98 | 76 | 54 | 1 | 7 | 1 | 127.0.0.1 | | active | | 2013-01-01T09:30:00Z |
  73. +-----+------+----------+---------+-----------+----------------+---------+-----------+------------+--------------------+--------+--------+----------------------+
  74. EOT
  75. ;
  76. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  77. $this->assertSame($expected, $this->commandTester->getDisplay());
  78. }
  79. }