GetAllCommandTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Regions;
  11. use Symfony\Component\Console\Application;
  12. use Symfony\Component\Console\Tester\CommandTester;
  13. use DigitalOcean\Tests\TestCase;
  14. use DigitalOcean\CLI\Regions\GetAllCommand;
  15. /**
  16. * @author Antoine Corcy <contact@sbin.dk>
  17. */
  18. class GetAllCommandTest 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. 'regions' => array(
  28. (object) array('id' => 1, 'name' => 'foo 1'),
  29. (object) array('id' => 2, 'name' => 'bar 2'),
  30. )
  31. );
  32. $GetAllCommand = $this->getMock('\DigitalOcean\CLI\Regions\GetAllCommand', array('getDigitalOcean'));
  33. $GetAllCommand
  34. ->expects($this->once())
  35. ->method('getDigitalOcean')
  36. ->will($this->returnValue($this->getMockDigitalOcean('regions', $this->getMockRegions($result))));
  37. $this->application->add($GetAllCommand);
  38. $this->command = $this->application->find('regions:all');
  39. $this->commandTester = new CommandTester($this->command);
  40. }
  41. public function testExecute()
  42. {
  43. $this->commandTester->execute(array(
  44. 'command' => $this->command->getName(),
  45. ));
  46. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  47. $this->assertRegExp('/\| 2 \| bar 2 \|/', $this->commandTester->getDisplay());
  48. }
  49. }