GetGlobalCommandTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\GetGlobalCommand;
  15. /**
  16. * @author Antoine Corcy <contact@sbin.dk>
  17. */
  18. class GetGlobalCommandTest 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. $GetGlobalCommand = $this->getMock('\DigitalOcean\CLI\Images\GetGlobalCommand', array('getDigitalOcean'));
  33. $GetGlobalCommand
  34. ->expects($this->any())
  35. ->method('getDigitalOcean')
  36. ->will($this->returnValue($this->getMockDigitalOcean('images', $this->getMockImages('getGlobal', $result))));
  37. $this->application->add($GetGlobalCommand);
  38. $this->command = $this->application->find('images:global');
  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. }