GetAllCommandTest.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\Domains;
  11. use Symfony\Component\Console\Application;
  12. use Symfony\Component\Console\Tester\CommandTester;
  13. use DigitalOcean\Tests\TestCase;
  14. use DigitalOcean\CLI\Domains\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. 'domains' => array(
  28. (object) array(
  29. 'id' => 1,
  30. 'name' => 'foo.org',
  31. 'ttl' => 1800,
  32. 'live_zone_file' => '$TTL\\t600\\n@\\t\\tIN\\tSOA\\tNS1.DIGITALOCEAN.COM.\\thostmaster.foo.org. (\\n\\t\\t\\t1369261882 ; last update: 2013-05-22 22:31:22 UTC\\n\\t\\t\\t3600 ; refresh\\n\\t\\t\\t900 ; retry\\n\\t\\t\\t1209600 ; expire\\n\\t\\t\\t10800 ; 3 hours ttl\\n\\t\\t\\t)\\n IN NS NS1.DIGITALOCEAN.COM.\\n @\\tIN A\\t8.8.8.8\\n',
  33. 'error' => null,
  34. 'zone_file_with_error' => null,
  35. ),
  36. (object) array(
  37. 'id' => 2,
  38. 'name' => 'bar.org',
  39. 'ttl' => 1800,
  40. 'live_zone_file' => '$TTL\\t600\\n@\\t\\tIN\\tSOA\\tNS1.DIGITALOCEAN.COM.\\thostmaster.bar.org. (\\n\\t\\t\\t1369261882 ; last update: 2013-05-22 22:31:22 UTC\\n\\t\\t\\t3600 ; refresh\\n\\t\\t\\t900 ; retry\\n\\t\\t\\t1209600 ; expire\\n\\t\\t\\t10800 ; 3 hours ttl\\n\\t\\t\\t)\\n IN NS NS1.DIGITALOCEAN.COM.\\n @\\tIN A\\t8.8.8.8\\n',
  41. 'error' => null,
  42. 'zone_file_with_error' => null,
  43. ),
  44. )
  45. );
  46. $GetAllCommand = $this->getMock('\DigitalOcean\CLI\Domains\GetAllCommand', array('getDigitalOcean'));
  47. $GetAllCommand
  48. ->expects($this->once())
  49. ->method('getDigitalOcean')
  50. ->will($this->returnValue($this->getMockDigitalOcean('domains', $this->getMockDomains('getAll', $result))));
  51. $this->application->add($GetAllCommand);
  52. $this->command = $this->application->find('domains:all');
  53. $this->commandTester = new CommandTester($this->command);
  54. }
  55. public function testExecute()
  56. {
  57. $this->commandTester->execute(array(
  58. 'command' => $this->command->getName(),
  59. ));
  60. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  61. $this->assertRegExp('/\| 1 \| foo\.org \|/', $this->commandTester->getDisplay());
  62. $this->assertRegExp('/\| 2 \| bar\.org \|/', $this->commandTester->getDisplay());
  63. }
  64. }