RegionsTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Regions;
  11. use DigitalOcean\Tests\TestCase;
  12. use DigitalOcean\Regions\Regions;
  13. /**
  14. * @author Antoine Corcy <contact@sbin.dk>
  15. */
  16. class RegionsTest extends TestCase
  17. {
  18. /**
  19. * @expectedException \RuntimeException
  20. * @expectedExceptionMEssage Impossible to process this query: https://api.digitalocean.com/droplets/?client_id=foo&api_key=bar
  21. */
  22. public function testProcessQuery()
  23. {
  24. $regions = new Regions($this->getMockCredentials(), $this->getMockAdapterReturns(null));
  25. $regions->getAll();
  26. }
  27. public function testGetAllUrl()
  28. {
  29. $regions = new Regions($this->getMockCredentials(), $this->getMockAdapter($this->never()));
  30. $method = new \ReflectionMethod(
  31. $regions, 'buildQuery'
  32. );
  33. $method->setAccessible(true);
  34. $this->assertEquals(
  35. 'https://api.digitalocean.com/regions/?client_id=foo&api_key=bar',
  36. $method->invoke($regions)
  37. );
  38. }
  39. public function testGetAll()
  40. {
  41. $response = <<<JSON
  42. {"status":"OK","regions":[{"id":1,"name":"New York 1"},{"id":2,"name":"Amsterdam 1"}]}
  43. JSON
  44. ;
  45. $regions = new Regions($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  46. $regions = $regions->getAll();
  47. $this->assertTrue(is_object($regions));
  48. $this->assertEquals('OK', $regions->status);
  49. $this->assertCount(2, $regions->regions);
  50. $region1 = $regions->regions[0];
  51. $this->assertSame(1, $region1->id);
  52. $this->assertSame('New York 1', $region1->name);
  53. $region2 = $regions->regions[1];
  54. $this->assertSame(2, $region2->id);
  55. $this->assertSame('Amsterdam 1', $region2->name);
  56. }
  57. }