EventsTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\Events;
  11. use DigitalOcean\Tests\TestCase;
  12. use DigitalOcean\Events\Events;
  13. /**
  14. * @author Antoine Corcy <contact@sbin.dk>
  15. */
  16. class EventsTest extends TestCase
  17. {
  18. protected $eventId;
  19. protected function setUp()
  20. {
  21. $this->eventId = 123;
  22. }
  23. /**
  24. * @expectedException \RuntimeException
  25. * @expectedExceptionMEssage Impossible to process this query: https://api.digitalocean.com/events/123/?client_id=foo&api_key=bar
  26. */
  27. public function testProcessQuery()
  28. {
  29. $events = new Events($this->getMockCredentials(), $this->getMockAdapterReturns(null));
  30. $events->show($this->eventId);
  31. }
  32. public function testShowUrl()
  33. {
  34. $events = new Events($this->getMockCredentials(), $this->getMockAdapter($this->never()));
  35. $method = new \ReflectionMethod(
  36. $events, 'buildQuery'
  37. );
  38. $method->setAccessible(true);
  39. $this->assertEquals(
  40. 'https://api.digitalocean.com/events/123/?client_id=foo&api_key=bar',
  41. $method->invoke($events, $this->eventId)
  42. );
  43. }
  44. public function testShow()
  45. {
  46. $response = <<<JSON
  47. {
  48. "status": "OK",
  49. "event": {
  50. "id": 123,
  51. "action_status": "done",
  52. "droplet_id": 100824,
  53. "event_type_id": 1,
  54. "percentage": "100"
  55. }
  56. }
  57. JSON
  58. ;
  59. $events = new Events($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  60. $events = $events->show($this->eventId);
  61. $this->assertTrue(is_object($events));
  62. $this->assertEquals('OK', $events->status);
  63. $this->assertTrue(is_object($events->event));
  64. $this->assertSame($this->eventId, $events->event->id);
  65. $this->assertSame('done', $events->event->action_status);
  66. $this->assertSame(100824, $events->event->droplet_id);
  67. $this->assertSame(1, $events->event->event_type_id);
  68. $this->assertSame('100', $events->event->percentage);
  69. }
  70. }