ShowCommandTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\Images;
  11. use Symfony\Component\Console\Application;
  12. use Symfony\Component\Console\Tester\CommandTester;
  13. use DigitalOcean\Tests\TestCase;
  14. use DigitalOcean\CLI\Images\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. 'image' => (object) array('id' => 1, 'name' => 'foo', 'distribution' => 'foobar dist')
  28. );
  29. $ShowCommand = $this->getMock('\DigitalOcean\CLI\Images\ShowCommand', array('getDigitalOcean'));
  30. $ShowCommand
  31. ->expects($this->any())
  32. ->method('getDigitalOcean')
  33. ->will($this->returnValue($this->getMockDigitalOcean('images', $this->getMockImages('show', $result))));
  34. $this->application->add($ShowCommand);
  35. $this->command = $this->application->find('images:show');
  36. $this->commandTester = new CommandTester($this->command);
  37. }
  38. /**
  39. * @expectedException \RuntimeException
  40. * @expectedExceptionMessage Not enough arguments.
  41. */
  42. public function testExecuteNotEnoughArguments()
  43. {
  44. $this->commandTester->execute(array(
  45. 'command' => $this->command->getName(),
  46. ));
  47. }
  48. public function testExecute()
  49. {
  50. $this->commandTester->execute(array(
  51. 'command' => $this->command->getName(),
  52. 'id' => 123,
  53. ));
  54. $expected = <<<EOT
  55. +----+------+--------------+
  56. | ID | Name | Distribution |
  57. +----+------+--------------+
  58. | 1 | foo | foobar dist |
  59. +----+------+--------------+
  60. EOT
  61. ;
  62. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  63. $this->assertSame($expected, $this->commandTester->getDisplay());
  64. }
  65. }