ShowCommandTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\Events;
  11. use Symfony\Component\Console\Application;
  12. use Symfony\Component\Console\Tester\CommandTester;
  13. use DigitalOcean\Tests\TestCase;
  14. use DigitalOcean\CLI\Events\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. 'status' => 'OK',
  28. 'event' => (object) array(
  29. 'id' => 1,
  30. 'action_status' => 'done',
  31. 'droplet_id' => 100824,
  32. 'event_type_id' => 1,
  33. 'percentage' => '100',
  34. )
  35. );
  36. $ShowCommand = $this->getMock('\DigitalOcean\CLI\Events\ShowCommand', array('getDigitalOcean'));
  37. $ShowCommand
  38. ->expects($this->any())
  39. ->method('getDigitalOcean')
  40. ->will($this->returnValue($this->getMockDigitalOcean('events', $this->getMockDomains('show', $result))));
  41. $this->application->add($ShowCommand);
  42. $this->command = $this->application->find('events:show');
  43. $this->commandTester = new CommandTester($this->command);
  44. }
  45. /**
  46. * @expectedException \RuntimeException
  47. * @expectedExceptionMessage Not enough arguments.
  48. */
  49. public function testExecuteNotEnoughArguments()
  50. {
  51. $this->commandTester->execute(array(
  52. 'command' => $this->command->getName(),
  53. ));
  54. }
  55. public function testExecute()
  56. {
  57. $this->commandTester->execute(array(
  58. 'command' => $this->command->getName(),
  59. 'id' => 123,
  60. ));
  61. $expected = <<<'EOT'
  62. +----+--------+------------+---------------+------------+
  63. | ID | Status | Droplet ID | Event Type ID | Percentage |
  64. +----+--------+------------+---------------+------------+
  65. | 1 | done | 100824 | 1 | 100 |
  66. +----+--------+------------+---------------+------------+
  67. EOT
  68. ;
  69. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  70. $this->assertSame($expected, $this->commandTester->getDisplay());
  71. }
  72. }