PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Twilio/Integration/Studio/V2/FlowTest.php

http://github.com/twilio/twilio-php
PHP | 263 lines | 222 code | 35 blank | 6 comment | 0 complexity | 4b852c4ffa120e7774a879da371d7501 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /**
  3. * This code was generated by
  4. * \ / _ _ _| _ _
  5. * | (_)\/(_)(_|\/| |(/_ v1.0.0
  6. * / /
  7. */
  8. namespace Twilio\Tests\Integration\Studio\V2;
  9. use Twilio\Exceptions\DeserializeException;
  10. use Twilio\Exceptions\TwilioException;
  11. use Twilio\Http\Response;
  12. use Twilio\Serialize;
  13. use Twilio\Tests\HolodeckTestCase;
  14. use Twilio\Tests\Request;
  15. class FlowTest extends HolodeckTestCase {
  16. public function testCreateRequest(): void {
  17. $this->holodeck->mock(new Response(500, ''));
  18. try {
  19. $this->twilio->studio->v2->flows->create("friendly_name", "draft", []);
  20. } catch (DeserializeException $e) {}
  21. catch (TwilioException $e) {}
  22. $values = [
  23. 'FriendlyName' => "friendly_name",
  24. 'Status' => "draft",
  25. 'Definition' => Serialize::jsonObject([]),
  26. ];
  27. $this->assertRequest(new Request(
  28. 'post',
  29. 'https://studio.twilio.com/v2/Flows',
  30. null,
  31. $values
  32. ));
  33. }
  34. public function testCreateResponse(): void {
  35. $this->holodeck->mock(new Response(
  36. 201,
  37. '
  38. {
  39. "sid": "FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  40. "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  41. "definition": {
  42. "initial_state": "Trigger"
  43. },
  44. "friendly_name": "Test Flow",
  45. "status": "published",
  46. "revision": 1,
  47. "commit_message": null,
  48. "valid": true,
  49. "errors": [],
  50. "warnings": [],
  51. "webhook_url": "http://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  52. "date_created": "2017-11-06T12:00:00Z",
  53. "date_updated": null,
  54. "url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  55. "links": {
  56. "test_users": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers",
  57. "revisions": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions",
  58. "executions": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions"
  59. }
  60. }
  61. '
  62. ));
  63. $actual = $this->twilio->studio->v2->flows->create("friendly_name", "draft", []);
  64. $this->assertNotNull($actual);
  65. }
  66. public function testUpdateRequest(): void {
  67. $this->holodeck->mock(new Response(500, ''));
  68. try {
  69. $this->twilio->studio->v2->flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")->update("draft");
  70. } catch (DeserializeException $e) {}
  71. catch (TwilioException $e) {}
  72. $values = ['Status' => "draft", ];
  73. $this->assertRequest(new Request(
  74. 'post',
  75. 'https://studio.twilio.com/v2/Flows/FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  76. null,
  77. $values
  78. ));
  79. }
  80. public function testUpdateResponse(): void {
  81. $this->holodeck->mock(new Response(
  82. 200,
  83. '
  84. {
  85. "sid": "FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  86. "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  87. "definition": {
  88. "initial_state": "Trigger"
  89. },
  90. "friendly_name": "Test Flow",
  91. "status": "published",
  92. "revision": 1,
  93. "commit_message": null,
  94. "valid": true,
  95. "errors": [],
  96. "warnings": [],
  97. "webhook_url": "http://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  98. "date_created": "2017-11-06T12:00:00Z",
  99. "date_updated": "2017-11-06T12:00:00Z",
  100. "url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  101. "links": {
  102. "test_users": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers",
  103. "revisions": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions",
  104. "executions": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions"
  105. }
  106. }
  107. '
  108. ));
  109. $actual = $this->twilio->studio->v2->flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")->update("draft");
  110. $this->assertNotNull($actual);
  111. }
  112. public function testReadRequest(): void {
  113. $this->holodeck->mock(new Response(500, ''));
  114. try {
  115. $this->twilio->studio->v2->flows->read();
  116. } catch (DeserializeException $e) {}
  117. catch (TwilioException $e) {}
  118. $this->assertRequest(new Request(
  119. 'get',
  120. 'https://studio.twilio.com/v2/Flows'
  121. ));
  122. }
  123. public function testReadEmptyResponse(): void {
  124. $this->holodeck->mock(new Response(
  125. 200,
  126. '
  127. {
  128. "meta": {
  129. "previous_page_url": null,
  130. "next_page_url": null,
  131. "url": "https://studio.twilio.com/v2/Flows?PageSize=50&Page=0",
  132. "page": 0,
  133. "first_page_url": "https://studio.twilio.com/v2/Flows?PageSize=50&Page=0",
  134. "page_size": 50,
  135. "key": "flows"
  136. },
  137. "flows": [
  138. {
  139. "sid": "FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  140. "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  141. "friendly_name": "Test Flow",
  142. "status": "published",
  143. "revision": 1,
  144. "definition": null,
  145. "commit_message": null,
  146. "valid": null,
  147. "errors": null,
  148. "warnings": null,
  149. "webhook_url": "http://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  150. "date_created": "2017-11-06T12:00:00Z",
  151. "date_updated": "2017-11-06T12:00:00Z",
  152. "url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  153. "links": {
  154. "test_users": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers",
  155. "revisions": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions",
  156. "executions": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions"
  157. }
  158. }
  159. ]
  160. }
  161. '
  162. ));
  163. $actual = $this->twilio->studio->v2->flows->read();
  164. $this->assertNotNull($actual);
  165. }
  166. public function testFetchRequest(): void {
  167. $this->holodeck->mock(new Response(500, ''));
  168. try {
  169. $this->twilio->studio->v2->flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")->fetch();
  170. } catch (DeserializeException $e) {}
  171. catch (TwilioException $e) {}
  172. $this->assertRequest(new Request(
  173. 'get',
  174. 'https://studio.twilio.com/v2/Flows/FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
  175. ));
  176. }
  177. public function testFetchResponse(): void {
  178. $this->holodeck->mock(new Response(
  179. 200,
  180. '
  181. {
  182. "sid": "FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  183. "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  184. "friendly_name": "Test Flow",
  185. "definition": {
  186. "initial_state": "Trigger"
  187. },
  188. "status": "published",
  189. "revision": 1,
  190. "commit_message": "commit",
  191. "valid": true,
  192. "errors": [],
  193. "warnings": [],
  194. "webhook_url": "http://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  195. "date_created": "2017-11-06T12:00:00Z",
  196. "date_updated": null,
  197. "url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  198. "links": {
  199. "test_users": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers",
  200. "revisions": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions",
  201. "executions": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions"
  202. }
  203. }
  204. '
  205. ));
  206. $actual = $this->twilio->studio->v2->flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")->fetch();
  207. $this->assertNotNull($actual);
  208. }
  209. public function testDeleteRequest(): void {
  210. $this->holodeck->mock(new Response(500, ''));
  211. try {
  212. $this->twilio->studio->v2->flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")->delete();
  213. } catch (DeserializeException $e) {}
  214. catch (TwilioException $e) {}
  215. $this->assertRequest(new Request(
  216. 'delete',
  217. 'https://studio.twilio.com/v2/Flows/FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
  218. ));
  219. }
  220. public function testDeleteResponse(): void {
  221. $this->holodeck->mock(new Response(
  222. 204,
  223. null
  224. ));
  225. $actual = $this->twilio->studio->v2->flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")->delete();
  226. $this->assertTrue($actual);
  227. }
  228. }