ShowCommandTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\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. 'domain' => (object) array(
  28. 'id' => 1,
  29. 'name' => 'foo.org',
  30. 'ttl' => 1800,
  31. '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',
  32. 'error' => null,
  33. 'zone_file_with_error' => null,
  34. )
  35. );
  36. $ShowCommand = $this->getMock('\DigitalOcean\CLI\Domains\ShowCommand', array('getDigitalOcean'));
  37. $ShowCommand
  38. ->expects($this->any())
  39. ->method('getDigitalOcean')
  40. ->will($this->returnValue($this->getMockDigitalOcean('domains', $this->getMockDomains('show', $result))));
  41. $this->application->add($ShowCommand);
  42. $this->command = $this->application->find('domains:show');
  43. $this->commandTester = new CommandTester($this->command);
  44. }
  45. /**
  46. * @expectedException \RuntimeException
  47. * @expectedExceptionMessage Not enough arguments.
  48. */
  49. public function testExecuteNotEnoughArguments()
  50. {
  51. $this->commandTester->execute(array(
  52. 'command' => $this->command->getName(),
  53. ));
  54. }
  55. public function testExecute()
  56. {
  57. $this->commandTester->execute(array(
  58. 'command' => $this->command->getName(),
  59. 'id' => 123,
  60. ));
  61. $expected = <<<'EOT'
  62. +----+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------+----------------------+
  63. | ID | Name | TTL | Live Zone File | Error | Zone File With Error |
  64. +----+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------+----------------------+
  65. | 1 | foo.org | 1800 | $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 | | |
  66. +----+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------+----------------------+
  67. EOT
  68. ;
  69. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  70. $this->assertSame($expected, $this->commandTester->getDisplay());
  71. }
  72. }