ShowAllActiveCommandTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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\ShowAllActiveCommand;
  15. /**
  16. * @author Antoine Corcy <contact@sbin.dk>
  17. */
  18. class ShowAllActiveCommandTest 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. 'droplets' => array(
  28. (object) array(
  29. 'id' => 123,
  30. 'name' => 'foo',
  31. 'image_id' => 98,
  32. 'size_id' => 76,
  33. 'region_id' => 54,
  34. 'backups_active' => 1,
  35. 'ip_address' => '127.0.0.1',
  36. 'private_ip_address' => null,
  37. 'status' => 'active',
  38. 'locked' => false,
  39. 'created_at' => '2013-01-01T09:30:00Z',
  40. ),
  41. (object) array(
  42. 'id' => 456,
  43. 'name' => 'bar',
  44. 'image_id' => 34,
  45. 'size_id' => 56,
  46. 'region_id' => 78,
  47. 'backups_active' => 0,
  48. 'ip_address' => '127.0.0.1',
  49. 'private_ip_address' => '127.0.0.1',
  50. 'status' => 'active',
  51. 'locked' => false,
  52. 'created_at' => '2013-01-01T09:30:00Z',
  53. ),
  54. )
  55. );
  56. $ShowAllActiveCommand = $this->getMock('\DigitalOcean\CLI\Droplets\ShowAllActiveCommand', array('getDigitalOcean'));
  57. $ShowAllActiveCommand
  58. ->expects($this->any())
  59. ->method('getDigitalOcean')
  60. ->will($this->returnValue($this->getMockDigitalOcean('droplets', $this->getMockDroplets('showAllActive', $result))));
  61. $this->application->add($ShowAllActiveCommand);
  62. $this->command = $this->application->find('droplets:show-all-active');
  63. $this->commandTester = new CommandTester($this->command);
  64. }
  65. public function testExecuteFirstDroplet()
  66. {
  67. $this->commandTester->execute(array(
  68. 'command' => $this->command->getName(),
  69. ));
  70. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  71. $this->assertRegExp('/\| 123 \| foo \| 98 \| 76 \| 54 \| 1 \| 127\.0\.0\.1 \| \| active \| \| 2013\-01\-01T09\:30\:00Z \|/', $this->commandTester->getDisplay());
  72. }
  73. public function testExecuteSecondDroplet()
  74. {
  75. $this->commandTester->execute(array(
  76. 'command' => $this->command->getName(),
  77. ));
  78. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  79. $this->assertRegExp('/\| 456 \| bar \| 34 \| 56 \| 78 \| 0 \| 127\.0\.0\.1 \| 127\.0\.0\.1 \| active \| \| 2013\-01\-01T09\:30:00Z \|/', $this->commandTester->getDisplay());
  80. }
  81. public function testReturnsNoDroplets()
  82. {
  83. $result = (object) array(
  84. 'droplets' => array()
  85. );
  86. $ShowAllActiveCommand = $this->getMock('\DigitalOcean\CLI\Droplets\ShowAllActiveCommand', array('getDigitalOcean'));
  87. $ShowAllActiveCommand
  88. ->expects($this->any())
  89. ->method('getDigitalOcean')
  90. ->will($this->returnValue($this->getMockDigitalOcean('droplets', $this->getMockDroplets('showAllActive', $result))));
  91. $this->application->add($ShowAllActiveCommand);
  92. $this->command = $this->application->find('droplets:show-all-active');
  93. $this->commandTester = new CommandTester($this->command);
  94. $this->commandTester->execute(array(
  95. 'command' => $this->command->getName(),
  96. ));
  97. $expected = <<<EOT
  98. +----+------+----------+---------+-----------+----------------+------------+--------------------+--------+--------+------------+
  99. | ID | Name | Image ID | Size ID | Region ID | Backups Active | IP Address | Private IP Address | Status | Locked | Created At |
  100. +----+------+----------+---------+-----------+----------------+------------+--------------------+--------+--------+------------+
  101. EOT
  102. ;
  103. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  104. $this->assertTrue($expected === $this->commandTester->getDisplay());
  105. }
  106. }