DigitalOceanTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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;
  11. use DigitalOcean\DigitalOcean;
  12. /**
  13. * @author Antoine Corcy <contact@sbin.dk>
  14. */
  15. class DigitalOceanTest extends TestCase
  16. {
  17. public function testConstructorWithoutAdapterShouldUseCurlHttpAdapter()
  18. {
  19. $digitalOcean = new MockDigitalOcean($this->getMockCredentials($this->never()));
  20. $this->assertTrue(is_object($digitalOcean->getAdapter()));
  21. $this->assertInstanceOf('\\HttpAdapter\\CurlHttpAdapter', $digitalOcean->getAdapter());
  22. }
  23. public function testSetAdapterWithoutAdapterShouldUseCurlHttpAdapter()
  24. {
  25. $digitalOcean = new MockDigitalOcean($this->getMockCredentials($this->never()));
  26. $digitalOcean->setAdapter();
  27. $this->assertTrue(is_object($digitalOcean->getAdapter()));
  28. $this->assertInstanceOf('\\HttpAdapter\\CurlHttpAdapter', $digitalOcean->getAdapter());
  29. }
  30. public function testReturnsDropletInstance()
  31. {
  32. $digitalOcean = new DigitalOcean($this->getMockCredentials(), $this->getMockAdapter($this->never()));
  33. $droplets = $digitalOcean->droplets();
  34. $this->assertTrue(is_object($droplets));
  35. $this->assertInstanceOf('\\DigitalOcean\\Droplets\\Droplets', $droplets);
  36. }
  37. public function testReturnsRegionInstance()
  38. {
  39. $digitalOcean = new DigitalOcean($this->getMockCredentials(), $this->getMockAdapter($this->never()));
  40. $regions = $digitalOcean->regions();
  41. $this->assertTrue(is_object($regions));
  42. $this->assertInstanceOf('\\DigitalOcean\\Regions\\Regions', $regions);
  43. }
  44. public function testReturnsImageInstance()
  45. {
  46. $digitalOcean = new DigitalOcean($this->getMockCredentials(), $this->getMockAdapter($this->never()));
  47. $images = $digitalOcean->images();
  48. $this->assertTrue(is_object($images));
  49. $this->assertInstanceOf('\\DigitalOcean\\Images\\Images', $images);
  50. }
  51. public function testReturnsSizeInstance()
  52. {
  53. $digitalOcean = new DigitalOcean($this->getMockCredentials(), $this->getMockAdapter($this->never()));
  54. $sizes = $digitalOcean->sizes();
  55. $this->assertTrue(is_object($sizes));
  56. $this->assertInstanceOf('\\DigitalOcean\\Sizes\\Sizes', $sizes);
  57. }
  58. public function testReturnsSSHKeysInstance()
  59. {
  60. $digitalOcean = new DigitalOcean($this->getMockCredentials(), $this->getMockAdapter($this->never()));
  61. $sshKeys = $digitalOcean->sshKeys();
  62. $this->assertTrue(is_object($sshKeys));
  63. $this->assertInstanceOf('\\DigitalOcean\\SSHKeys\\SSHKeys', $sshKeys);
  64. }
  65. public function testReturnsDomainsInstance()
  66. {
  67. $digitalOcean = new DigitalOcean($this->getMockCredentials(), $this->getMockAdapter($this->never()));
  68. $domains = $digitalOcean->domains();
  69. $this->assertTrue(is_object($domains));
  70. $this->assertInstanceOf('\\DigitalOcean\\Domains\\Domains', $domains);
  71. }
  72. public function testReturnsEventsInstance()
  73. {
  74. $digitalOcean = new DigitalOcean($this->getMockCredentials(), $this->getMockAdapter($this->never()));
  75. $events = $digitalOcean->events();
  76. $this->assertTrue(is_object($events));
  77. $this->assertInstanceOf('\\DigitalOcean\\Events\\Events', $events);
  78. }
  79. }
  80. class MockDigitalOcean extends DigitalOcean
  81. {
  82. public function getAdapter()
  83. {
  84. return $this->adapter;
  85. }
  86. }