AddCommandTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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\AddCommand;
  15. /**
  16. * @author Antoine Corcy <contact@sbin.dk>
  17. */
  18. class AddCommandTest 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. 'status' => 'OK',
  28. 'domain' => (object) array(
  29. 'id' => 123,
  30. 'name' => 'foo.org',
  31. ),
  32. );
  33. $AddCommand = $this->getMock('\DigitalOcean\CLI\Domains\AddCommand', array('getDigitalOcean'));
  34. $AddCommand
  35. ->expects($this->any())
  36. ->method('getDigitalOcean')
  37. ->will($this->returnValue($this->getMockDigitalOcean('domains', $this->getMockDomains('add', $result))));
  38. $this->application->add($AddCommand);
  39. $this->command = $this->application->find('domains:add');
  40. $this->commandTester = new CommandTester($this->command);
  41. }
  42. /**
  43. * @expectedException \RuntimeException
  44. * @expectedExceptionMessage Not enough arguments.
  45. */
  46. public function testExecuteNotEnoughArguments()
  47. {
  48. $this->commandTester->execute(array(
  49. 'command' => $this->command->getName(),
  50. ));
  51. }
  52. /**
  53. * @expectedException \RuntimeException
  54. * @expectedExceptionMessage Not enough arguments.
  55. */
  56. public function testExecuteNotEnoughArgumentsWithoutName()
  57. {
  58. $this->commandTester->execute(array(
  59. 'command' => $this->command->getName(),
  60. 'ip_address' => '127.0.0.1',
  61. ));
  62. }
  63. /**
  64. * @expectedException \RuntimeException
  65. * @expectedExceptionMessage Not enough arguments.
  66. */
  67. public function testExecuteNotEnoughArgumentsWithoutIpaddress()
  68. {
  69. $this->commandTester->execute(array(
  70. 'command' => $this->command->getName(),
  71. 'name' => 'foo.org',
  72. ));
  73. }
  74. public function testExecute()
  75. {
  76. $this->commandTester->execute(array(
  77. 'command' => $this->command->getName(),
  78. 'name' => 'foo.org',
  79. 'ip_address' => '127.0.0.1',
  80. ));
  81. $expected = <<<EOT
  82. +--------+-----+---------+
  83. | Status | ID | Name |
  84. +--------+-----+---------+
  85. | OK | 123 | foo.org |
  86. +--------+-----+---------+
  87. EOT
  88. ;
  89. $this->assertTrue(is_string($this->commandTester->getDisplay()));
  90. $this->assertSame($expected, $this->commandTester->getDisplay());
  91. }
  92. }