DropletsTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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\Droplets;
  11. use DigitalOcean\Tests\TestCase;
  12. use DigitalOcean\Droplets\Droplets;
  13. use DigitalOcean\Droplets\DropletsActions;
  14. /**
  15. * @author Antoine Corcy <contact@sbin.dk>
  16. */
  17. class DropletsTest extends TestCase
  18. {
  19. protected $dropletId;
  20. protected $droplets;
  21. protected $dropletBuildQueryMethod;
  22. protected function setUp()
  23. {
  24. $this->dropletId = 123;
  25. $this->droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapter($this->never()));
  26. $this->dropletBuildQueryMethod = new \ReflectionMethod(
  27. $this->droplets, 'buildQuery'
  28. );
  29. $this->dropletBuildQueryMethod->setAccessible(true);
  30. }
  31. /**
  32. * @expectedException \RuntimeException
  33. * @expectedExceptionMEssage Impossible to process this query: https://api.digitalocean.com/droplets/?client_id=foo&api_key=bar
  34. */
  35. public function testProcessQuery()
  36. {
  37. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns(null));
  38. $droplets->showAllActive();
  39. }
  40. public function testShowAllActiveUrl()
  41. {
  42. $this->assertEquals(
  43. 'https://api.digitalocean.com/droplets/?client_id=foo&api_key=bar',
  44. $this->dropletBuildQueryMethod->invoke($this->droplets)
  45. );
  46. }
  47. public function testShowAllActive()
  48. {
  49. $response = <<<JSON
  50. {"status":"OK","droplets":[{"backups_active":null,"id":123,"image_id":420,"name":"test123","region_id":1,"size_id":33,"status":"active","ip_address":"127.0.0.1","locked":false,"created_at":"2013-01-01T09:30:00Z"},{"backups_active":1,"id":456,"image_id":420,"name":"test456","region_id":1,"size_id":33,"status":"active","ip_address":"127.0.0.1","locked":false,"created_at":"2013-01-01T09:30:00Z"}]}
  51. JSON
  52. ;
  53. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  54. $droplets = $droplets->showAllActive();
  55. $this->assertTrue(is_object($droplets));
  56. $this->assertEquals('OK', $droplets->status);
  57. $this->assertCount(2, $droplets->droplets);
  58. $droplet1 = $droplets->droplets[0];
  59. $this->assertNull($droplet1->backups_active);
  60. $this->assertSame(123, $droplet1->id);
  61. $this->assertSame(420, $droplet1->image_id);
  62. $this->assertSame('test123', $droplet1->name);
  63. $this->assertSame(1, $droplet1->region_id);
  64. $this->assertSame(33, $droplet1->size_id);
  65. $this->assertSame('active', $droplet1->status);
  66. $this->assertSame('127.0.0.1', $droplet1->ip_address);
  67. $this->assertSame(false, $droplet1->locked);
  68. $this->assertSame('2013-01-01T09:30:00Z', $droplet1->created_at);
  69. $droplet1 = $droplets->droplets[1];
  70. $this->assertSame(1, $droplet1->backups_active);
  71. $this->assertSame(456, $droplet1->id);
  72. $this->assertSame(420, $droplet1->image_id);
  73. $this->assertSame('test456', $droplet1->name);
  74. $this->assertSame(1, $droplet1->region_id);
  75. $this->assertSame(33, $droplet1->size_id);
  76. $this->assertSame('active', $droplet1->status);
  77. $this->assertSame('127.0.0.1', $droplet1->ip_address);
  78. $this->assertSame(false, $droplet1->locked);
  79. $this->assertSame('2013-01-01T09:30:00Z', $droplet1->created_at);
  80. }
  81. public function testShowAllActiveWithCredentials()
  82. {
  83. if (!isset($_SERVER['CLIENT_ID']) || !isset($_SERVER['API_KEY'])) {
  84. $this->markTestSkipped('You need to configure the CLIENT_ID and API_KEY values in phpunit.xml');
  85. }
  86. $droplets = new Droplets(
  87. new \DigitalOcean\Credentials($_SERVER['CLIENT_ID'], $_SERVER['API_KEY']),
  88. new \HttpAdapter\CurlHttpAdapter()
  89. );
  90. $droplets = $droplets->showAllActive();
  91. $this->assertTrue(is_object($droplets));
  92. $this->assertEquals('OK', $droplets->status);
  93. $this->assertCount(count($droplets->droplets), $droplets->droplets);
  94. $firstDroplet = $droplets->droplets[0];
  95. $this->assertObjectHasAttribute('id', $firstDroplet);
  96. $this->assertObjectHasAttribute('name', $firstDroplet);
  97. $this->assertObjectHasAttribute('image_id', $firstDroplet);
  98. $this->assertObjectHasAttribute('size_id', $firstDroplet);
  99. $this->assertObjectHasAttribute('region_id', $firstDroplet);
  100. $this->assertObjectHasAttribute('backups_active', $firstDroplet);
  101. $this->assertObjectHasAttribute('ip_address', $firstDroplet);
  102. $this->assertObjectHasAttribute('status', $firstDroplet);
  103. }
  104. public function testShowUrl()
  105. {
  106. $this->assertEquals(
  107. 'https://api.digitalocean.com/droplets/123/?client_id=foo&api_key=bar',
  108. $this->dropletBuildQueryMethod->invoke($this->droplets, $this->dropletId)
  109. );
  110. }
  111. public function testShow()
  112. {
  113. $response = <<<JSON
  114. {"status":"OK","droplets":[{"backups_active":1,"id":123,"image_id":420,"name":"test123","region_id":1,"size_id":33,"status":"active","ip_address":"127.0.0.1"}]}
  115. JSON
  116. ;
  117. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  118. $droplet = $droplets->show($this->dropletId)->droplets[0];
  119. $this->assertSame(1, $droplet->backups_active);
  120. $this->assertSame($this->dropletId, $droplet->id);
  121. $this->assertSame(420, $droplet->image_id);
  122. $this->assertSame('test123', $droplet->name);
  123. $this->assertSame(1, $droplet->region_id);
  124. $this->assertSame(33, $droplet->size_id);
  125. $this->assertSame('active', $droplet->status);
  126. $this->assertSame('127.0.0.1', $droplet->ip_address);
  127. }
  128. /**
  129. * @expectedException \RuntimeException
  130. * @expectedExceptionMessage Not Found: https://api.digitalocean.com/droplets/123/?client_id=foo&api_key=bar
  131. */
  132. public function testShowThrowsRuntimeException()
  133. {
  134. $response = <<<JSON
  135. {"status":"ERROR","message":"Not Found"}
  136. JSON
  137. ;
  138. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  139. $droplets->show($this->dropletId);
  140. }
  141. /**
  142. * @expectedException \RuntimeException
  143. * @expectedExceptionMessage Not Droplets Found: https://api.digitalocean.com/droplets/123/?client_id=foo&api_key=bar
  144. */
  145. public function testShowThrowsRuntimeExceptionWithOldErrorResponse()
  146. {
  147. $response = <<<JSON
  148. {"status":"ERROR","error_message":"Not Droplets Found"}
  149. JSON
  150. ;
  151. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  152. $droplets->show($this->dropletId);
  153. }
  154. public function testCreateUrl()
  155. {
  156. $newDroplet = array(
  157. 'name' => 'MyNewDroplet',
  158. 'size_id' => 111,
  159. 'image_id' => 222,
  160. 'region_id' => 333,
  161. 'ssh_key_ids' => 'MySshKeyId1,MySshKeyId2',
  162. );
  163. $this->assertEquals(
  164. 'https://api.digitalocean.com/droplets/new/?name=MyNewDroplet&size_id=111&image_id=222&region_id=333&ssh_key_ids=MySshKeyId1%2CMySshKeyId2&client_id=foo&api_key=bar',
  165. $this->dropletBuildQueryMethod->invoke($this->droplets, null, DropletsActions::ACTION_NEW, $newDroplet)
  166. );
  167. }
  168. /**
  169. * @expectedException \InvalidArgumentException
  170. * @expectedExceptionMessage A new droplet must have a string "name".
  171. */
  172. public function testCreateThrowsNameInvalidArgumentException()
  173. {
  174. $this->droplets->create(array());
  175. }
  176. /**
  177. * @expectedException \InvalidArgumentException
  178. * @expectedExceptionMessage A new droplet must have an integer "size_id".
  179. */
  180. public function testCreateThrowsSizeIdInvalidArgumentException()
  181. {
  182. $this->droplets->create(array(
  183. 'name' => 'MyNewDroplet',
  184. ));
  185. }
  186. /**
  187. * @expectedException \InvalidArgumentException
  188. * @expectedExceptionMessage A new droplet must have an integer "image_id".
  189. */
  190. public function testCreateThrowsImageIdInvalidArgumentException()
  191. {
  192. $this->droplets->create(array(
  193. 'name' => 'MyNewDroplet',
  194. 'size_id' => 123,
  195. ));
  196. }
  197. /**
  198. * @expectedException \InvalidArgumentException
  199. * @expectedExceptionMessage A new droplet must have an integer "region_id".
  200. */
  201. public function testCreateThrowsRegionIdInvalidArgumentException()
  202. {
  203. $this->droplets->create(array(
  204. 'name' => 'MyNewDroplet',
  205. 'size_id' => 123,
  206. 'image_id' => 456,
  207. ));
  208. }
  209. /**
  210. * @expectedException \InvalidArgumentException
  211. * @expectedExceptionMessage You need to provide an list of "ssh_key_ids" comma separeted.
  212. */
  213. public function testCreateThrowsSshKeyIdsInvalidArgumentException()
  214. {
  215. $this->droplets->create(array(
  216. 'name' => 'MyNewDroplet',
  217. 'size_id' => 123,
  218. 'image_id' => 456,
  219. 'region_id' => 789,
  220. 'ssh_key_ids' => array(),
  221. ));
  222. }
  223. public function testCreate()
  224. {
  225. $response = <<<JSON
  226. {"status":"OK","droplet":{"id":100824,"name":"MyNewDroplet","image_id":222,"size_id":111,"region_id":333,"event_id":7499}}
  227. JSON
  228. ;
  229. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  230. $createdDroplet = $droplets->create(array(
  231. 'name' => 'MyNewDroplet',
  232. 'size_id' => 111,
  233. 'image_id' => 222,
  234. 'region_id' => 333,
  235. ));
  236. $this->assertTrue(is_object($createdDroplet));
  237. $this->assertEquals('OK', $createdDroplet->status);
  238. $createdDroplet = $createdDroplet->droplet;
  239. $this->assertSame(100824, $createdDroplet->id);
  240. $this->assertSame('MyNewDroplet', $createdDroplet->name);
  241. $this->assertSame(111, $createdDroplet->size_id);
  242. $this->assertSame(222, $createdDroplet->image_id);
  243. $this->assertSame(333, $createdDroplet->region_id);
  244. $this->assertSame(7499, $createdDroplet->event_id);
  245. }
  246. public function testRebootUrl()
  247. {
  248. $this->assertEquals(
  249. 'https://api.digitalocean.com/droplets/123/reboot/?client_id=foo&api_key=bar',
  250. $this->dropletBuildQueryMethod->invoke(
  251. $this->droplets, $this->dropletId, DropletsActions::ACTION_REBOOT
  252. )
  253. );
  254. }
  255. public function testReboot()
  256. {
  257. $response = <<<JSON
  258. {"status":"OK","event_id":7501}
  259. JSON
  260. ;
  261. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  262. $droplet = $droplets->reboot($this->dropletId);
  263. $this->assertTrue(is_object($droplet));
  264. $this->assertEquals('OK', $droplet->status);
  265. $this->assertSame(7501, $droplet->event_id);
  266. }
  267. public function testPowerCycleUrl()
  268. {
  269. $this->assertEquals(
  270. 'https://api.digitalocean.com/droplets/123/power_cycle/?client_id=foo&api_key=bar',
  271. $this->dropletBuildQueryMethod->invoke(
  272. $this->droplets, $this->dropletId, DropletsActions::ACTION_POWER_CYCLE
  273. )
  274. );
  275. }
  276. public function testPowerCycle()
  277. {
  278. $response = <<<JSON
  279. {"status":"OK","event_id":7501}
  280. JSON
  281. ;
  282. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  283. $droplet = $droplets->powerCycle($this->dropletId);
  284. $this->assertTrue(is_object($droplet));
  285. $this->assertEquals('OK', $droplet->status);
  286. $this->assertSame(7501, $droplet->event_id);
  287. }
  288. public function testShutdownUrl()
  289. {
  290. $this->assertEquals(
  291. 'https://api.digitalocean.com/droplets/123/shutdown/?client_id=foo&api_key=bar',
  292. $this->dropletBuildQueryMethod->invoke(
  293. $this->droplets, $this->dropletId, DropletsActions::ACTION_SHUTDOWN
  294. )
  295. );
  296. }
  297. public function testShutdown()
  298. {
  299. $response = <<<JSON
  300. {"status":"OK","event_id":7501}
  301. JSON
  302. ;
  303. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  304. $droplet = $droplets->shutdown($this->dropletId);
  305. $this->assertTrue(is_object($droplet));
  306. $this->assertEquals('OK', $droplet->status);
  307. $this->assertSame(7501, $droplet->event_id);
  308. }
  309. public function testPowerOnUrl()
  310. {
  311. $this->assertEquals(
  312. 'https://api.digitalocean.com/droplets/123/power_on/?client_id=foo&api_key=bar',
  313. $this->dropletBuildQueryMethod->invoke(
  314. $this->droplets, $this->dropletId, DropletsActions::ACTION_POWER_ON
  315. )
  316. );
  317. }
  318. public function testPowerOn()
  319. {
  320. $response = <<<JSON
  321. {"status":"OK","event_id":7501}
  322. JSON
  323. ;
  324. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  325. $droplet = $droplets->powerOn($this->dropletId);
  326. $this->assertTrue(is_object($droplet));
  327. $this->assertEquals('OK', $droplet->status);
  328. $this->assertSame(7501, $droplet->event_id);
  329. }
  330. public function testPowerOffUrl()
  331. {
  332. $this->assertEquals(
  333. 'https://api.digitalocean.com/droplets/123/power_off/?client_id=foo&api_key=bar',
  334. $this->dropletBuildQueryMethod->invoke(
  335. $this->droplets, $this->dropletId, DropletsActions::ACTION_POWER_OFF
  336. )
  337. );
  338. }
  339. public function testPowerOff()
  340. {
  341. $response = <<<JSON
  342. {"status":"OK","event_id":7501}
  343. JSON
  344. ;
  345. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  346. $droplet = $droplets->powerOff($this->dropletId);
  347. $this->assertTrue(is_object($droplet));
  348. $this->assertEquals('OK', $droplet->status);
  349. $this->assertSame(7501, $droplet->event_id);
  350. }
  351. public function testResetRootPasswordUrl()
  352. {
  353. $this->assertEquals(
  354. 'https://api.digitalocean.com/droplets/123/password_reset/?client_id=foo&api_key=bar',
  355. $this->dropletBuildQueryMethod->invoke(
  356. $this->droplets, $this->dropletId, DropletsActions::ACTION_RESET_ROOT_PASSWORD
  357. )
  358. );
  359. }
  360. public function testResetRootPassword()
  361. {
  362. $response = <<<JSON
  363. {"status":"OK","event_id":7501}
  364. JSON
  365. ;
  366. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  367. $droplet = $droplets->resetRootPassword($this->dropletId);
  368. $this->assertTrue(is_object($droplet));
  369. $this->assertEquals('OK', $droplet->status);
  370. $this->assertSame(7501, $droplet->event_id);
  371. }
  372. public function testResizeUrl()
  373. {
  374. $newSize = array(
  375. 'size_id' => 111,
  376. );
  377. $this->assertEquals(
  378. 'https://api.digitalocean.com/droplets/123/resize/?size_id=111&client_id=foo&api_key=bar',
  379. $this->dropletBuildQueryMethod->invoke(
  380. $this->droplets, $this->dropletId, DropletsActions::ACTION_RESIZE, $newSize
  381. )
  382. );
  383. }
  384. /**
  385. * @expectedException \InvalidArgumentException
  386. * @expectedExceptionMessage You need to provide an integer "size_id".
  387. */
  388. public function testResizeThrowsSizeIdInvalidArgumentException()
  389. {
  390. $this->droplets->resize($this->dropletId, array());
  391. }
  392. public function testResize()
  393. {
  394. $response = <<<JSON
  395. {"status":"OK","event_id":7501}
  396. JSON
  397. ;
  398. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  399. $droplet = $droplets->resize($this->dropletId, array('size_id' => 123));
  400. $this->assertTrue(is_object($droplet));
  401. $this->assertEquals('OK', $droplet->status);
  402. $this->assertSame(7501, $droplet->event_id);
  403. }
  404. public function testSnapshotUrlWithoutName()
  405. {
  406. $this->assertEquals(
  407. 'https://api.digitalocean.com/droplets/123/snapshot/?client_id=foo&api_key=bar',
  408. $this->dropletBuildQueryMethod->invoke(
  409. $this->droplets, $this->dropletId, DropletsActions::ACTION_SNAPSHOT
  410. )
  411. );
  412. }
  413. public function testSnapshotUrlWithName()
  414. {
  415. $newSnapshot = array(
  416. 'name' => 'MySnapshotName'
  417. );
  418. $this->assertEquals(
  419. 'https://api.digitalocean.com/droplets/123/snapshot/?name=MySnapshotName&client_id=foo&api_key=bar',
  420. $this->dropletBuildQueryMethod->invoke(
  421. $this->droplets, $this->dropletId, DropletsActions::ACTION_SNAPSHOT, $newSnapshot
  422. )
  423. );
  424. }
  425. public function testSnapshot()
  426. {
  427. $response = <<<JSON
  428. {"status":"OK","event_id":7501}
  429. JSON
  430. ;
  431. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  432. $droplet = $droplets->snapshot($this->dropletId);
  433. $this->assertTrue(is_object($droplet));
  434. $this->assertEquals('OK', $droplet->status);
  435. $this->assertSame(7501, $droplet->event_id);
  436. }
  437. public function testRestoreUrl()
  438. {
  439. $imageToRestore = array(
  440. 'image_id' => 1111,
  441. );
  442. $this->assertEquals(
  443. 'https://api.digitalocean.com/droplets/123/restore/?image_id=1111&client_id=foo&api_key=bar',
  444. $this->dropletBuildQueryMethod->invoke(
  445. $this->droplets, $this->dropletId, DropletsActions::ACTION_RESTORE, $imageToRestore
  446. )
  447. );
  448. }
  449. /**
  450. * @expectedException \InvalidArgumentException
  451. * @expectedExceptionMessage You need to provide the "image_id" to restore.
  452. */
  453. public function testRestoreUrlThrowsSizeIdInvalidArgumentException()
  454. {
  455. $this->droplets->restore($this->dropletId, array());
  456. }
  457. public function testRestore()
  458. {
  459. $response = <<<JSON
  460. {"status":"OK","event_id":7501}
  461. JSON
  462. ;
  463. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  464. $droplet = $droplets->restore($this->dropletId, array('image_id' => 1111));
  465. $this->assertTrue(is_object($droplet));
  466. $this->assertEquals('OK', $droplet->status);
  467. $this->assertSame(7501, $droplet->event_id);
  468. }
  469. public function testRebuildUrl()
  470. {
  471. $imageToRebuild = array(
  472. 'image_id' => 1111,
  473. );
  474. $this->assertEquals(
  475. 'https://api.digitalocean.com/droplets/123/rebuild/?image_id=1111&client_id=foo&api_key=bar',
  476. $this->dropletBuildQueryMethod->invoke(
  477. $this->droplets, $this->dropletId, DropletsActions::ACTION_REBUILD, $imageToRebuild
  478. )
  479. );
  480. }
  481. /**
  482. * @expectedException \InvalidArgumentException
  483. * @expectedExceptionMessage You need to provide the "image_id" to rebuild.
  484. */
  485. public function testRebuildThrowsSizeIdInvalidArgumentException()
  486. {
  487. $this->droplets->rebuild($this->dropletId, array());
  488. }
  489. public function testRebuild()
  490. {
  491. $response = <<<JSON
  492. {"status":"OK","event_id":7501}
  493. JSON
  494. ;
  495. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  496. $droplet = $droplets->rebuild($this->dropletId, array('image_id' => 1111));
  497. $this->assertTrue(is_object($droplet));
  498. $this->assertEquals('OK', $droplet->status);
  499. $this->assertSame(7501, $droplet->event_id);
  500. }
  501. public function testRenameUrl()
  502. {
  503. $newName = array(
  504. 'name' => 'foobar',
  505. );
  506. $this->assertEquals(
  507. 'https://api.digitalocean.com/droplets/123/rename/?name=foobar&client_id=foo&api_key=bar',
  508. $this->dropletBuildQueryMethod->invoke(
  509. $this->droplets, $this->dropletId, DropletsActions::ACTION_RENAME, $newName
  510. )
  511. );
  512. }
  513. /**
  514. * @expectedException \InvalidArgumentException
  515. * @expectedExceptionMessage You need to provide a string "name".
  516. */
  517. public function testRenameThrowsNameInvalidArgumentException()
  518. {
  519. $this->droplets->rename($this->dropletId, array());
  520. }
  521. public function testRename()
  522. {
  523. $response = <<<JSON
  524. {"status":"OK","event_id":4435823}
  525. JSON
  526. ;
  527. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  528. $droplet = $droplets->rename($this->dropletId, array('name' => 'foobar'));
  529. $this->assertTrue(is_object($droplet));
  530. $this->assertEquals('OK', $droplet->status);
  531. $this->assertSame(4435823, $droplet->event_id);
  532. }
  533. public function testDestroyUrl()
  534. {
  535. $this->assertEquals(
  536. 'https://api.digitalocean.com/droplets/123/destroy/?client_id=foo&api_key=bar',
  537. $this->dropletBuildQueryMethod->invoke(
  538. $this->droplets, $this->dropletId, DropletsActions::ACTION_DESTROY
  539. )
  540. );
  541. }
  542. public function testDestroy()
  543. {
  544. $response = <<<JSON
  545. {"status":"OK","event_id":7501}
  546. JSON
  547. ;
  548. $droplets = new Droplets($this->getMockCredentials(), $this->getMockAdapterReturns($response));
  549. $droplet = $droplets->destroy($this->dropletId);
  550. $this->assertTrue(is_object($droplet));
  551. $this->assertEquals('OK', $droplet->status);
  552. $this->assertSame(7501, $droplet->event_id);
  553. }
  554. }