GetMyImagesCommandTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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\GetMyImagesCommand;
  15. /**
  16. * @author Antoine Corcy <contact@sbin.dk>
  17. */
  18. class GetMyImagesCommandTest 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. 'images' => array(
  28. (object) array('id' => 1, 'name' => 'foo', 'distribution' => 'foobar dist'),
  29. (object) array('id' => 2, 'name' => 'bar', 'distribution' => 'barqmx dist'),
  30. )
  31. );
  32. $GetMyImagesCommand = $this->getMock('\DigitalOcean\CLI\Images\GetMyImagesCommand', array('getDigitalOcean'));
  33. $GetMyImagesCommand
  34. ->expects($this->any())
  35. ->method('getDigitalOcean')
  36. ->will($this->returnValue($this->getMockDigitalOcean('images', $this->getMockImages('getMyImages', $result))));
  37. $this->application->add($GetMyImagesCommand);
  38. $this->command = $this->application->find('images:mines');
  39. $this->commandTester = new CommandTester($this->command);
  40. }
  41. public function testExecuteFirstImage()
  42. {
  43. $this->commandTester->execute(array(
  44. 'command' => $this->command->getName(),
  45. ));
  46. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  47. $this->assertRegExp('/\| 1 \| foo \| foobar dist \|/', $this->commandTester->getDisplay());
  48. }
  49. public function testExecuteSecondImage()
  50. {
  51. $this->commandTester->execute(array(
  52. 'command' => $this->command->getName(),
  53. ));
  54. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  55. $this->assertRegExp('/\| 2 \| bar \| barqmx dist \|/', $this->commandTester->getDisplay());
  56. }
  57. public function testReturnsNoImages()
  58. {
  59. $result = (object) array(
  60. 'images' => array()
  61. );
  62. $GetMyImagesCommand = $this->getMock('\DigitalOcean\CLI\Images\GetMyImagesCommand', array('getDigitalOcean'));
  63. $GetMyImagesCommand
  64. ->expects($this->any())
  65. ->method('getDigitalOcean')
  66. ->will($this->returnValue($this->getMockDigitalOcean('images', $this->getMockImages('getMyImages', $result))));
  67. $this->application->add($GetMyImagesCommand);
  68. $this->command = $this->application->find('images:mines');
  69. $this->commandTester = new CommandTester($this->command);
  70. $this->commandTester->execute(array(
  71. 'command' => $this->command->getName(),
  72. ));
  73. $expected = <<<EOT
  74. +----+------+--------------+
  75. | ID | Name | Distribution |
  76. +----+------+--------------+
  77. EOT
  78. ;
  79. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  80. $this->assertTrue($expected === $this->commandTester->getDisplay());
  81. }
  82. }