Constant Contact Forms - Version 1.2.1

Version Description

  • Fixed: Re-show sections of "Publish" metabox incorrectly hidden for post types outside Constant Contact Forms.
  • Fixed: Issues with transparent background on frontend forms when input is valid.
  • Fixed: Fatal errors on deactivation if user is on PHP 5.3 or lower.
  • Fixed: PHP Warnings regarding missing parameters for maybe_log_mail_status().
  • Updated: Bumped Guzzle to 5.3.1 for PHP7.1 compatibility.
Download this release

Release Info

Developer constantcontact
Plugin Icon 128x128 Constant Contact Forms
Version 1.2.1
Comparing to
See all releases

Code changes from version 1.2.0 to 1.2.1

Files changed (150) hide show
  1. assets/css/admin-forms.css +1 -1
  2. assets/css/style.css +4 -4
  3. assets/css/style.min.css +1 -1
  4. assets/sass/_inputs.scss +3 -3
  5. assets/sass/admin-forms.scss +1 -1
  6. constant-contact-forms.php +10 -8
  7. includes/class-mail.php +10 -3
  8. readme.txt +8 -1
  9. vendor/constantcontact/guzzlehttp/guzzle/CHANGELOG.md +7 -0
  10. vendor/constantcontact/guzzlehttp/guzzle/LICENSE +1 -1
  11. vendor/constantcontact/guzzlehttp/guzzle/README.md +0 -0
  12. vendor/constantcontact/guzzlehttp/guzzle/UPGRADING.md +0 -0
  13. vendor/constantcontact/guzzlehttp/guzzle/composer.json +5 -6
  14. vendor/constantcontact/guzzlehttp/guzzle/docs/Makefile +0 -153
  15. vendor/constantcontact/guzzlehttp/guzzle/docs/_static/guzzle-icon.png +0 -0
  16. vendor/constantcontact/guzzlehttp/guzzle/docs/_static/logo.png +0 -0
  17. vendor/constantcontact/guzzlehttp/guzzle/docs/_templates/nav_links.html +0 -3
  18. vendor/constantcontact/guzzlehttp/guzzle/docs/clients.rst +0 -1326
  19. vendor/constantcontact/guzzlehttp/guzzle/docs/conf.py +0 -28
  20. vendor/constantcontact/guzzlehttp/guzzle/docs/events.rst +0 -516
  21. vendor/constantcontact/guzzlehttp/guzzle/docs/faq.rst +0 -199
  22. vendor/constantcontact/guzzlehttp/guzzle/docs/handlers.rst +0 -43
  23. vendor/constantcontact/guzzlehttp/guzzle/docs/http-messages.rst +0 -483
  24. vendor/constantcontact/guzzlehttp/guzzle/docs/index.rst +0 -98
  25. vendor/constantcontact/guzzlehttp/guzzle/docs/overview.rst +0 -150
  26. vendor/constantcontact/guzzlehttp/guzzle/docs/quickstart.rst +0 -448
  27. vendor/constantcontact/guzzlehttp/guzzle/docs/requirements.txt +0 -2
  28. vendor/constantcontact/guzzlehttp/guzzle/docs/streams.rst +0 -213
  29. vendor/constantcontact/guzzlehttp/guzzle/docs/testing.rst +0 -232
  30. vendor/constantcontact/guzzlehttp/guzzle/src/BatchResults.php +0 -0
  31. vendor/constantcontact/guzzlehttp/guzzle/src/Client.php +6 -3
  32. vendor/constantcontact/guzzlehttp/guzzle/src/ClientInterface.php +1 -1
  33. vendor/constantcontact/guzzlehttp/guzzle/src/Collection.php +0 -0
  34. vendor/constantcontact/guzzlehttp/guzzle/src/Cookie/CookieJar.php +0 -0
  35. vendor/constantcontact/guzzlehttp/guzzle/src/Cookie/CookieJarInterface.php +0 -0
  36. vendor/constantcontact/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php +0 -0
  37. vendor/constantcontact/guzzlehttp/guzzle/src/Cookie/SessionCookieJar.php +0 -0
  38. vendor/constantcontact/guzzlehttp/guzzle/src/Cookie/SetCookie.php +0 -0
  39. vendor/constantcontact/guzzlehttp/guzzle/src/Event/AbstractEvent.php +0 -0
  40. vendor/constantcontact/guzzlehttp/guzzle/src/Event/AbstractRequestEvent.php +0 -0
  41. vendor/constantcontact/guzzlehttp/guzzle/src/Event/AbstractRetryableEvent.php +0 -0
  42. vendor/constantcontact/guzzlehttp/guzzle/src/Event/AbstractTransferEvent.php +0 -0
  43. vendor/constantcontact/guzzlehttp/guzzle/src/Event/BeforeEvent.php +0 -0
  44. vendor/constantcontact/guzzlehttp/guzzle/src/Event/CompleteEvent.php +0 -0
  45. vendor/constantcontact/guzzlehttp/guzzle/src/Event/Emitter.php +1 -2
  46. vendor/constantcontact/guzzlehttp/guzzle/src/Event/EmitterInterface.php +0 -0
  47. vendor/constantcontact/guzzlehttp/guzzle/src/Event/EndEvent.php +0 -0
  48. vendor/constantcontact/guzzlehttp/guzzle/src/Event/ErrorEvent.php +0 -0
  49. vendor/constantcontact/guzzlehttp/guzzle/src/Event/EventInterface.php +0 -0
  50. vendor/constantcontact/guzzlehttp/guzzle/src/Event/HasEmitterInterface.php +0 -0
  51. vendor/constantcontact/guzzlehttp/guzzle/src/Event/HasEmitterTrait.php +0 -0
  52. vendor/constantcontact/guzzlehttp/guzzle/src/Event/ListenerAttacherTrait.php +0 -0
  53. vendor/constantcontact/guzzlehttp/guzzle/src/Event/ProgressEvent.php +0 -0
  54. vendor/constantcontact/guzzlehttp/guzzle/src/Event/RequestEvents.php +0 -0
  55. vendor/constantcontact/guzzlehttp/guzzle/src/Event/SubscriberInterface.php +0 -0
  56. vendor/constantcontact/guzzlehttp/guzzle/src/Exception/BadResponseException.php +0 -0
  57. vendor/constantcontact/guzzlehttp/guzzle/src/Exception/ClientException.php +0 -0
  58. vendor/constantcontact/guzzlehttp/guzzle/src/Exception/ConnectException.php +0 -0
  59. vendor/constantcontact/guzzlehttp/guzzle/src/Exception/CouldNotRewindStreamException.php +0 -0
  60. vendor/constantcontact/guzzlehttp/guzzle/src/Exception/ParseException.php +0 -0
  61. vendor/constantcontact/guzzlehttp/guzzle/src/Exception/RequestException.php +0 -0
  62. vendor/constantcontact/guzzlehttp/guzzle/src/Exception/ServerException.php +0 -0
  63. vendor/constantcontact/guzzlehttp/guzzle/src/Exception/StateException.php +0 -0
  64. vendor/constantcontact/guzzlehttp/guzzle/src/Exception/TooManyRedirectsException.php +0 -0
  65. vendor/constantcontact/guzzlehttp/guzzle/src/Exception/TransferException.php +0 -0
  66. vendor/constantcontact/guzzlehttp/guzzle/src/Exception/XmlParseException.php +0 -0
  67. vendor/constantcontact/guzzlehttp/guzzle/src/HasDataTrait.php +0 -0
  68. vendor/constantcontact/guzzlehttp/guzzle/src/Message/AbstractMessage.php +1 -1
  69. vendor/constantcontact/guzzlehttp/guzzle/src/Message/AppliesHeadersInterface.php +0 -0
  70. vendor/constantcontact/guzzlehttp/guzzle/src/Message/FutureResponse.php +0 -0
  71. vendor/constantcontact/guzzlehttp/guzzle/src/Message/MessageFactory.php +1 -1
  72. vendor/constantcontact/guzzlehttp/guzzle/src/Message/MessageFactoryInterface.php +0 -0
  73. vendor/constantcontact/guzzlehttp/guzzle/src/Message/MessageInterface.php +0 -0
  74. vendor/constantcontact/guzzlehttp/guzzle/src/Message/MessageParser.php +0 -0
  75. vendor/constantcontact/guzzlehttp/guzzle/src/Message/Request.php +0 -0
  76. vendor/constantcontact/guzzlehttp/guzzle/src/Message/RequestInterface.php +0 -0
  77. vendor/constantcontact/guzzlehttp/guzzle/src/Message/Response.php +0 -0
  78. vendor/constantcontact/guzzlehttp/guzzle/src/Message/ResponseInterface.php +0 -0
  79. vendor/constantcontact/guzzlehttp/guzzle/src/Mimetypes.php +0 -0
  80. vendor/constantcontact/guzzlehttp/guzzle/src/Pool.php +0 -0
  81. vendor/constantcontact/guzzlehttp/guzzle/src/Post/MultipartBody.php +0 -0
  82. vendor/constantcontact/guzzlehttp/guzzle/src/Post/PostBody.php +0 -0
  83. vendor/constantcontact/guzzlehttp/guzzle/src/Post/PostBodyInterface.php +0 -0
  84. vendor/constantcontact/guzzlehttp/guzzle/src/Post/PostFile.php +0 -0
  85. vendor/constantcontact/guzzlehttp/guzzle/src/Post/PostFileInterface.php +0 -0
  86. vendor/constantcontact/guzzlehttp/guzzle/src/Query.php +0 -0
  87. vendor/constantcontact/guzzlehttp/guzzle/src/QueryParser.php +0 -0
  88. vendor/constantcontact/guzzlehttp/guzzle/src/RequestFsm.php +0 -0
  89. vendor/constantcontact/guzzlehttp/guzzle/src/RingBridge.php +0 -0
  90. vendor/constantcontact/guzzlehttp/guzzle/src/Subscriber/Cookie.php +0 -0
  91. vendor/constantcontact/guzzlehttp/guzzle/src/Subscriber/History.php +0 -0
  92. vendor/constantcontact/guzzlehttp/guzzle/src/Subscriber/HttpError.php +0 -0
  93. vendor/constantcontact/guzzlehttp/guzzle/src/Subscriber/Mock.php +0 -0
  94. vendor/constantcontact/guzzlehttp/guzzle/src/Subscriber/Prepare.php +0 -0
  95. vendor/constantcontact/guzzlehttp/guzzle/src/Subscriber/Redirect.php +0 -0
  96. vendor/constantcontact/guzzlehttp/guzzle/src/ToArrayInterface.php +0 -0
  97. vendor/constantcontact/guzzlehttp/guzzle/src/Transaction.php +0 -0
  98. vendor/constantcontact/guzzlehttp/guzzle/src/UriTemplate.php +0 -0
  99. vendor/constantcontact/guzzlehttp/guzzle/src/Url.php +0 -0
  100. vendor/constantcontact/guzzlehttp/guzzle/src/Utils.php +0 -0
  101. vendor/constantcontact/guzzlehttp/guzzle/tests/BatchResultsTest.php +0 -58
  102. vendor/constantcontact/guzzlehttp/guzzle/tests/ClientTest.php +0 -647
  103. vendor/constantcontact/guzzlehttp/guzzle/tests/CollectionTest.php +0 -416
  104. vendor/constantcontact/guzzlehttp/guzzle/tests/Cookie/CookieJarTest.php +0 -339
  105. vendor/constantcontact/guzzlehttp/guzzle/tests/Cookie/FileCookieJarTest.php +0 -71
  106. vendor/constantcontact/guzzlehttp/guzzle/tests/Cookie/SessionCookieJarTest.php +0 -76
  107. vendor/constantcontact/guzzlehttp/guzzle/tests/Cookie/SetCookieTest.php +0 -364
  108. vendor/constantcontact/guzzlehttp/guzzle/tests/Event/AbstractEventTest.php +0 -14
  109. vendor/constantcontact/guzzlehttp/guzzle/tests/Event/AbstractRequestEventTest.php +0 -33
  110. vendor/constantcontact/guzzlehttp/guzzle/tests/Event/AbstractRetryableEventTest.php +0 -37
  111. vendor/constantcontact/guzzlehttp/guzzle/tests/Event/AbstractTransferEventTest.php +0 -59
  112. vendor/constantcontact/guzzlehttp/guzzle/tests/Event/BeforeEventTest.php +0 -26
  113. vendor/constantcontact/guzzlehttp/guzzle/tests/Event/EmitterTest.php +0 -363
  114. vendor/constantcontact/guzzlehttp/guzzle/tests/Event/ErrorEventTest.php +0 -23
  115. vendor/constantcontact/guzzlehttp/guzzle/tests/Event/HasEmitterTraitTest.php +0 -27
  116. vendor/constantcontact/guzzlehttp/guzzle/tests/Event/ListenerAttacherTraitTest.php +0 -92
  117. vendor/constantcontact/guzzlehttp/guzzle/tests/Event/ProgressEventTest.php +0 -25
  118. vendor/constantcontact/guzzlehttp/guzzle/tests/Event/RequestEventsTest.php +0 -74
  119. vendor/constantcontact/guzzlehttp/guzzle/tests/Exception/ParseExceptionTest.php +0 -20
  120. vendor/constantcontact/guzzlehttp/guzzle/tests/Exception/RequestExceptionTest.php +0 -83
  121. vendor/constantcontact/guzzlehttp/guzzle/tests/Exception/XmlParseExceptionTest.php +0 -19
  122. vendor/constantcontact/guzzlehttp/guzzle/tests/IntegrationTest.php +0 -123
  123. vendor/constantcontact/guzzlehttp/guzzle/tests/Message/AbstractMessageTest.php +0 -269
  124. vendor/constantcontact/guzzlehttp/guzzle/tests/Message/FutureResponseTest.php +0 -160
  125. vendor/constantcontact/guzzlehttp/guzzle/tests/Message/MessageFactoryTest.php +0 -601
  126. vendor/constantcontact/guzzlehttp/guzzle/tests/Message/MessageParserTest.php +0 -276
  127. vendor/constantcontact/guzzlehttp/guzzle/tests/Message/RequestTest.php +0 -144
  128. vendor/constantcontact/guzzlehttp/guzzle/tests/Message/ResponseTest.php +0 -120
  129. vendor/constantcontact/guzzlehttp/guzzle/tests/MimetypesTest.php +0 -31
  130. vendor/constantcontact/guzzlehttp/guzzle/tests/PoolTest.php +0 -319
  131. vendor/constantcontact/guzzlehttp/guzzle/tests/Post/MultipartBodyTest.php +0 -120
  132. vendor/constantcontact/guzzlehttp/guzzle/tests/Post/PostBodyTest.php +0 -255
  133. vendor/constantcontact/guzzlehttp/guzzle/tests/Post/PostFileTest.php +0 -61
  134. vendor/constantcontact/guzzlehttp/guzzle/tests/QueryParserTest.php +0 -80
  135. vendor/constantcontact/guzzlehttp/guzzle/tests/QueryTest.php +0 -171
  136. vendor/constantcontact/guzzlehttp/guzzle/tests/RequestFsmTest.php +0 -187
  137. vendor/constantcontact/guzzlehttp/guzzle/tests/RingBridgeTest.php +0 -195
  138. vendor/constantcontact/guzzlehttp/guzzle/tests/Server.php +0 -107
  139. vendor/constantcontact/guzzlehttp/guzzle/tests/Subscriber/CookieTest.php +0 -74
  140. vendor/constantcontact/guzzlehttp/guzzle/tests/Subscriber/HistoryTest.php +0 -140
  141. vendor/constantcontact/guzzlehttp/guzzle/tests/Subscriber/HttpErrorTest.php +0 -60
  142. vendor/constantcontact/guzzlehttp/guzzle/tests/Subscriber/MockTest.php +0 -225
  143. vendor/constantcontact/guzzlehttp/guzzle/tests/Subscriber/PrepareTest.php +0 -213
  144. vendor/constantcontact/guzzlehttp/guzzle/tests/Subscriber/RedirectTest.php +0 -302
  145. vendor/constantcontact/guzzlehttp/guzzle/tests/TransactionTest.php +0 -22
  146. vendor/constantcontact/guzzlehttp/guzzle/tests/UriTemplateTest.php +0 -202
  147. vendor/constantcontact/guzzlehttp/guzzle/tests/UrlTest.php +0 -364
  148. vendor/constantcontact/guzzlehttp/guzzle/tests/UtilsTest.php +0 -40
  149. vendor/constantcontact/guzzlehttp/guzzle/tests/bootstrap.php +0 -11
  150. vendor/constantcontact/guzzlehttp/guzzle/tests/perf.php +0 -61
assets/css/admin-forms.css CHANGED
@@ -299,7 +299,7 @@
299
  background-color: #005990;
300
  }
301
 
302
- .misc-pub-section.misc-pub-visibility, .misc-pub-section.misc-pub-curtime {
303
  display: none;
304
  }
305
 
299
  background-color: #005990;
300
  }
301
 
302
+ .post-type-ctct_forms .misc-pub-section.misc-pub-visibility, .post-type-ctct_forms .misc-pub-section.misc-pub-curtime {
303
  display: none;
304
  }
305
 
assets/css/style.css CHANGED
@@ -28,7 +28,7 @@
28
  }
29
 
30
  .ctct-form-wrapper input[type="text"]:required:valid, .ctct-form-wrapper input[type="email"]:required:valid, .ctct-form-wrapper input[type="password"]:required:valid, .ctct-form-wrapper input[type="tel"]:required:valid, .ctct-form-wrapper input[type="number"]:required:valid {
31
- background: url("../images/check_circle.svg") no-repeat;
32
  background-position: 8px 50%;
33
  background-size: 24px;
34
  border-color: #2ECC40;
@@ -36,7 +36,7 @@
36
  }
37
 
38
  .ctct-form-wrapper input[type="text"]:required.ctct-invalid, .ctct-form-wrapper input[type="text"].ctct-invalid, .ctct-form-wrapper input[type="email"]:required.ctct-invalid, .ctct-form-wrapper input[type="email"].ctct-invalid, .ctct-form-wrapper input[type="password"]:required.ctct-invalid, .ctct-form-wrapper input[type="password"].ctct-invalid, .ctct-form-wrapper input[type="tel"]:required.ctct-invalid, .ctct-form-wrapper input[type="tel"].ctct-invalid, .ctct-form-wrapper input[type="number"]:required.ctct-invalid, .ctct-form-wrapper input[type="number"].ctct-invalid {
39
- background: url("../images/error.svg") no-repeat;
40
  background-color: rgba(255, 65, 54, 0.02);
41
  background-position: 8px 50%;
42
  background-size: 24px;
@@ -50,7 +50,7 @@
50
  }
51
 
52
  .ctct-form-wrapper input.ctct-invalid {
53
- background: url("../images/error.svg") no-repeat;
54
  background-color: rgba(255, 65, 54, 0.02);
55
  background-position: 8px 50%;
56
  background-size: 24px;
@@ -116,4 +116,4 @@
116
  }
117
  }
118
 
119
- /*# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0eWxlLmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtFQUNFLGlCQUFpQjtDQUNsQjs7QUFFRDtFQUNFLGtCQUFrQjtFQUNsQixhQUFhO0NBQ2Q7O0FBRUQ7RUFDRSwwQ0FBMEM7RUFDMUMsc0JBQXNCO0VBQ3RCLGVBQWU7Q0FDaEI7O0FBRUQ7RUFDRSwwQ0FBMEM7RUFDMUMsc0JBQXNCO0VBQ3RCLGVBQWU7Q0FDaEI7O0FBRUQ7RUFDRSxnQkFBZ0I7Q0FDakI7O0FBRUQ7RUFDRSxzQkFBc0I7Q0FDdkI7O0FBbUNEO0VBQ0Usd0RBQXdEO0VBQ3hELDZCQUE2QjtFQUM3QixzQkFBc0I7RUFDdEIsc0JBQXNCO0VBQ3RCLG1CQUFtQjtDQUNwQjs7QUFFRDtFQUNFLGlEQUFpRDtFQUNqRCwwQ0FBMEM7RUFDMUMsNkJBQTZCO0VBQzdCLHNCQUFzQjtFQUN0QixzQkFBc0I7RUFDdEIsbUJBQW1CO0NBQ3BCOztBQUVEO0VBQ0Usa0JBQWtCO0VBQ2xCLG1CQUFtQjtDQUNwQjs7QUFFRDtFQUNFLGlEQUFpRDtFQUNqRCwwQ0FBMEM7RUFDMUMsNkJBQTZCO0VBQzdCLHNCQUFzQjtFQUN0QixzQkFBc0I7RUFDdEIsbUJBQW1CO0NBQ3BCOztBQUVEO0VBQ0UsWUFBWTtFQUNaLFlBQVk7RUFDWixlQUFlO0NBQ2hCOztBQUVEO0VBQ0UsYUFBYTtFQUNiLGVBQWU7RUFDZixpQkFBaUI7Q0FDbEI7O0FBRUQ7RUFDRSxZQUFZO0VBQ1osaUJBQWlCO0NBQ2xCOztBQUVEO0VBQ0UsZUFBZTtDQUNoQjs7QUFFRDtFQUNFLFlBQVk7Q0FDYjs7QUF2RkQ7O0VBQ0U7SUFDRSxZQUFZO0lBQ1osaUJBQWlCO0lBQ2pCLFdBQVc7R0FDWjs7RUFDRDtJQUNFLGdCQUFnQjtHQUNqQjs7RUFJRDtJQUNFLFlBQVk7SUFDWixpQkFBaUI7SUFDakIsV0FBVztHQUNaOztFQUNEO0lBQ0UsZ0JBQWdCO0dBQ2pCOztFQUlEO0lBQ0UsWUFBWTtJQUNaLGlCQUFpQjtJQUNqQixXQUFXO0dBQ1o7O0VBQ0Q7SUFDRSxnQkFBZ0I7R0FDakI7Q0FyQkYiLCJmaWxlIjoic3R5bGUuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiLmN0Y3QtZm9ybS13cmFwcGVyIC5jdGN0LWJ1dHRvbiB7XG4gIGZvbnQtc2l6ZTogMC45ZW07XG59XG5cbi5jdGN0LWZvcm0td3JhcHBlciAuY3RjdC1tZXNzYWdlIHtcbiAgYm9yZGVyOiAxcHggc29saWQ7XG4gIHBhZGRpbmc6IDFlbTtcbn1cblxuLmN0Y3QtZm9ybS13cmFwcGVyIC5lcnJvciB7XG4gIGJhY2tncm91bmQtY29sb3I6IHJnYmEoMjU1LCA2NSwgNTQsIDAuMDIpO1xuICBib3JkZXItY29sb3I6ICNGRjQxMzY7XG4gIGNvbG9yOiAjY2YwYjAwO1xufVxuXG4uY3RjdC1mb3JtLXdyYXBwZXIgLnN1Y2Nlc3Mge1xuICBiYWNrZ3JvdW5kLWNvbG9yOiByZ2JhKDQ2LCAyMDQsIDY0LCAwLjAyKTtcbiAgYm9yZGVyLWNvbG9yOiAjMkVDQzQwO1xuICBjb2xvcjogIzFiNzkyNjtcbn1cblxuLmN0Y3QtZm9ybS13cmFwcGVyIC5jdGN0LWZvcm0tZmllbGQge1xuICBtYXJnaW46IDAgMCAxZW07XG59XG5cbi5jdGN0LWZvcm0td3JhcHBlciAuY3RjdC1maWVsZC1pbmxpbmUge1xuICBkaXNwbGF5OiBpbmxpbmUtYmxvY2s7XG59XG5cbkBtZWRpYSAobWluLXdpZHRoOiA5OTJweCkge1xuICAuY3RjdC1mb3JtLXdyYXBwZXIgLmN0Y3QtZmllbGQtaGFsZiB7XG4gICAgZmxvYXQ6IGxlZnQ7XG4gICAgbWFyZ2luLXJpZ2h0OiAyJTtcbiAgICB3aWR0aDogNDglO1xuICB9XG4gIC5jdGN0LWZvcm0td3JhcHBlciAuY3RjdC1maWVsZC1oYWxmOmxhc3Qtb2YtdHlwZSB7XG4gICAgbWFyZ2luLXJpZ2h0OiAwO1xuICB9XG59XG5cbkBtZWRpYSAobWluLXdpZHRoOiA5OTJweCkge1xuICAuY3RjdC1mb3JtLXdyYXBwZXIgLmN0Y3QtZmllbGQtdGhpcmQge1xuICAgIGZsb2F0OiBsZWZ0O1xuICAgIG1hcmdpbi1yaWdodDogMiU7XG4gICAgd2lkdGg6IDMyJTtcbiAgfVxuICAuY3RjdC1mb3JtLXdyYXBwZXIgLmN0Y3QtZmllbGQtdGhpcmQ6bGFzdC1vZi10eXBlIHtcbiAgICBtYXJnaW4tcmlnaHQ6IDA7XG4gIH1cbn1cblxuQG1lZGlhIChtaW4td2lkdGg6IDk5MnB4KSB7XG4gIC5jdGN0LWZvcm0td3JhcHBlciAuY3RjdC1maWVsZC1mb3VydGgge1xuICAgIGZsb2F0OiBsZWZ0O1xuICAgIG1hcmdpbi1yaWdodDogMiU7XG4gICAgd2lkdGg6IDI0JTtcbiAgfVxuICAuY3RjdC1mb3JtLXdyYXBwZXIgLmN0Y3QtZmllbGQtZm91cnRoOmxhc3Qtb2YtdHlwZSB7XG4gICAgbWFyZ2luLXJpZ2h0OiAwO1xuICB9XG59XG5cbi5jdGN0LWZvcm0td3JhcHBlciBpbnB1dFt0eXBlPVwidGV4dFwiXTpyZXF1aXJlZDp2YWxpZCwgLmN0Y3QtZm9ybS13cmFwcGVyIGlucHV0W3R5cGU9XCJlbWFpbFwiXTpyZXF1aXJlZDp2YWxpZCwgLmN0Y3QtZm9ybS13cmFwcGVyIGlucHV0W3R5cGU9XCJwYXNzd29yZFwiXTpyZXF1aXJlZDp2YWxpZCwgLmN0Y3QtZm9ybS13cmFwcGVyIGlucHV0W3R5cGU9XCJ0ZWxcIl06cmVxdWlyZWQ6dmFsaWQsIC5jdGN0LWZvcm0td3JhcHBlciBpbnB1dFt0eXBlPVwibnVtYmVyXCJdOnJlcXVpcmVkOnZhbGlkIHtcbiAgYmFja2dyb3VuZDogdXJsKFwiLi4vaW1hZ2VzL2NoZWNrX2NpcmNsZS5zdmdcIikgbm8tcmVwZWF0O1xuICBiYWNrZ3JvdW5kLXBvc2l0aW9uOiA4cHggNTAlO1xuICBiYWNrZ3JvdW5kLXNpemU6IDI0cHg7XG4gIGJvcmRlci1jb2xvcjogIzJFQ0M0MDtcbiAgcGFkZGluZy1sZWZ0OiA0MHB4O1xufVxuXG4uY3RjdC1mb3JtLXdyYXBwZXIgaW5wdXRbdHlwZT1cInRleHRcIl06cmVxdWlyZWQuY3RjdC1pbnZhbGlkLCAuY3RjdC1mb3JtLXdyYXBwZXIgaW5wdXRbdHlwZT1cInRleHRcIl0uY3RjdC1pbnZhbGlkLCAuY3RjdC1mb3JtLXdyYXBwZXIgaW5wdXRbdHlwZT1cImVtYWlsXCJdOnJlcXVpcmVkLmN0Y3QtaW52YWxpZCwgLmN0Y3QtZm9ybS13cmFwcGVyIGlucHV0W3R5cGU9XCJlbWFpbFwiXS5jdGN0LWludmFsaWQsIC5jdGN0LWZvcm0td3JhcHBlciBpbnB1dFt0eXBlPVwicGFzc3dvcmRcIl06cmVxdWlyZWQuY3RjdC1pbnZhbGlkLCAuY3RjdC1mb3JtLXdyYXBwZXIgaW5wdXRbdHlwZT1cInBhc3N3b3JkXCJdLmN0Y3QtaW52YWxpZCwgLmN0Y3QtZm9ybS13cmFwcGVyIGlucHV0W3R5cGU9XCJ0ZWxcIl06cmVxdWlyZWQuY3RjdC1pbnZhbGlkLCAuY3RjdC1mb3JtLXdyYXBwZXIgaW5wdXRbdHlwZT1cInRlbFwiXS5jdGN0LWludmFsaWQsIC5jdGN0LWZvcm0td3JhcHBlciBpbnB1dFt0eXBlPVwibnVtYmVyXCJdOnJlcXVpcmVkLmN0Y3QtaW52YWxpZCwgLmN0Y3QtZm9ybS13cmFwcGVyIGlucHV0W3R5cGU9XCJudW1iZXJcIl0uY3RjdC1pbnZhbGlkIHtcbiAgYmFja2dyb3VuZDogdXJsKFwiLi4vaW1hZ2VzL2Vycm9yLnN2Z1wiKSBuby1yZXBlYXQ7XG4gIGJhY2tncm91bmQtY29sb3I6IHJnYmEoMjU1LCA2NSwgNTQsIDAuMDIpO1xuICBiYWNrZ3JvdW5kLXBvc2l0aW9uOiA4cHggNTAlO1xuICBiYWNrZ3JvdW5kLXNpemU6IDI0cHg7XG4gIGJvcmRlci1jb2xvcjogI0ZGNDEzNjtcbiAgcGFkZGluZy1sZWZ0OiA0MHB4O1xufVxuXG4uY3RjdC1mb3JtLXdyYXBwZXIgLmN0Y3QtZmllbGQtZXJyb3Ige1xuICBmb250LXNpemU6IDAuODVlbTtcbiAgZm9udC1zdHlsZTogaXRhbGljO1xufVxuXG4uY3RjdC1mb3JtLXdyYXBwZXIgaW5wdXQuY3RjdC1pbnZhbGlkIHtcbiAgYmFja2dyb3VuZDogdXJsKFwiLi4vaW1hZ2VzL2Vycm9yLnN2Z1wiKSBuby1yZXBlYXQ7XG4gIGJhY2tncm91bmQtY29sb3I6IHJnYmEoMjU1LCA2NSwgNTQsIDAuMDIpO1xuICBiYWNrZ3JvdW5kLXBvc2l0aW9uOiA4cHggNTAlO1xuICBiYWNrZ3JvdW5kLXNpemU6IDI0cHg7XG4gIGJvcmRlci1jb2xvcjogI0ZGNDEzNjtcbiAgcGFkZGluZy1sZWZ0OiA0MHB4O1xufVxuXG4uY3RjdC1mb3JtLXdyYXBwZXIgLmN0Y3QtZm9ybTphZnRlciB7XG4gIGNsZWFyOiBib3RoO1xuICBjb250ZW50OiBcIlwiO1xuICBkaXNwbGF5OiB0YWJsZTtcbn1cblxuLmN0Y3QtZm9ybS13cmFwcGVyIC5jdGN0LWZvcm0gYWJiciB7XG4gIGJvcmRlcjogbm9uZTtcbiAgY29sb3I6ICNGRjQxMzY7XG4gIGZvbnQtc2l6ZTogMC45ZW07XG59XG5cbi5jdGN0LWZvcm0td3JhcHBlciAuY3RjdC1pbnB1dC1jb250YWluZXIgbGFiZWwge1xuICBjb2xvcjogI2FhYTtcbiAgZm9udC1zaXplOiAwLjhlbTtcbn1cblxuLmN0Y3QtZm9ybS13cmFwcGVyIC5jdGN0LWZpZWxkLWVycm9yIHtcbiAgY29sb3I6ICNGRjQxMzY7XG59XG5cbi5jdGN0LXR3ZW50eWZvdXJ0ZWVuIC5jdGN0LWZvcm0tZmllbGQgaW5wdXQge1xuICB3aWR0aDogMTAwJTtcbn1cbiJdfQ== */
28
  }
29
 
30
  .ctct-form-wrapper input[type="text"]:required:valid, .ctct-form-wrapper input[type="email"]:required:valid, .ctct-form-wrapper input[type="password"]:required:valid, .ctct-form-wrapper input[type="tel"]:required:valid, .ctct-form-wrapper input[type="number"]:required:valid {
31
+ background: white url("../images/check_circle.svg") no-repeat;
32
  background-position: 8px 50%;
33
  background-size: 24px;
34
  border-color: #2ECC40;
36
  }
37
 
38
  .ctct-form-wrapper input[type="text"]:required.ctct-invalid, .ctct-form-wrapper input[type="text"].ctct-invalid, .ctct-form-wrapper input[type="email"]:required.ctct-invalid, .ctct-form-wrapper input[type="email"].ctct-invalid, .ctct-form-wrapper input[type="password"]:required.ctct-invalid, .ctct-form-wrapper input[type="password"].ctct-invalid, .ctct-form-wrapper input[type="tel"]:required.ctct-invalid, .ctct-form-wrapper input[type="tel"].ctct-invalid, .ctct-form-wrapper input[type="number"]:required.ctct-invalid, .ctct-form-wrapper input[type="number"].ctct-invalid {
39
+ background: white url("../images/error.svg") no-repeat;
40
  background-color: rgba(255, 65, 54, 0.02);
41
  background-position: 8px 50%;
42
  background-size: 24px;
50
  }
51
 
52
  .ctct-form-wrapper input.ctct-invalid {
53
+ background: white url("../images/error.svg") no-repeat;
54
  background-color: rgba(255, 65, 54, 0.02);
55
  background-position: 8px 50%;
56
  background-size: 24px;
116
  }
117
  }
118
 
119
+ /*# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0eWxlLmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtFQUNFLGlCQUFpQjtDQUNsQjs7QUFFRDtFQUNFLGtCQUFrQjtFQUNsQixhQUFhO0NBQ2Q7O0FBRUQ7RUFDRSwwQ0FBMEM7RUFDMUMsc0JBQXNCO0VBQ3RCLGVBQWU7Q0FDaEI7O0FBRUQ7RUFDRSwwQ0FBMEM7RUFDMUMsc0JBQXNCO0VBQ3RCLGVBQWU7Q0FDaEI7O0FBRUQ7RUFDRSxnQkFBZ0I7Q0FDakI7O0FBRUQ7RUFDRSxzQkFBc0I7Q0FDdkI7O0FBbUNEO0VBQ0UsOERBQThEO0VBQzlELDZCQUE2QjtFQUM3QixzQkFBc0I7RUFDdEIsc0JBQXNCO0VBQ3RCLG1CQUFtQjtDQUNwQjs7QUFFRDtFQUNFLHVEQUF1RDtFQUN2RCwwQ0FBMEM7RUFDMUMsNkJBQTZCO0VBQzdCLHNCQUFzQjtFQUN0QixzQkFBc0I7RUFDdEIsbUJBQW1CO0NBQ3BCOztBQUVEO0VBQ0Usa0JBQWtCO0VBQ2xCLG1CQUFtQjtDQUNwQjs7QUFFRDtFQUNFLHVEQUF1RDtFQUN2RCwwQ0FBMEM7RUFDMUMsNkJBQTZCO0VBQzdCLHNCQUFzQjtFQUN0QixzQkFBc0I7RUFDdEIsbUJBQW1CO0NBQ3BCOztBQUVEO0VBQ0UsWUFBWTtFQUNaLFlBQVk7RUFDWixlQUFlO0NBQ2hCOztBQUVEO0VBQ0UsYUFBYTtFQUNiLGVBQWU7RUFDZixpQkFBaUI7Q0FDbEI7O0FBRUQ7RUFDRSxZQUFZO0VBQ1osaUJBQWlCO0NBQ2xCOztBQUVEO0VBQ0UsZUFBZTtDQUNoQjs7QUFFRDtFQUNFLFlBQVk7Q0FDYjs7QUF2RkQ7O0VBQ0U7SUFDRSxZQUFZO0lBQ1osaUJBQWlCO0lBQ2pCLFdBQVc7R0FDWjs7RUFDRDtJQUNFLGdCQUFnQjtHQUNqQjs7RUFJRDtJQUNFLFlBQVk7SUFDWixpQkFBaUI7SUFDakIsV0FBVztHQUNaOztFQUNEO0lBQ0UsZ0JBQWdCO0dBQ2pCOztFQUlEO0lBQ0UsWUFBWTtJQUNaLGlCQUFpQjtJQUNqQixXQUFXO0dBQ1o7O0VBQ0Q7SUFDRSxnQkFBZ0I7R0FDakI7Q0FyQkYiLCJmaWxlIjoic3R5bGUuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiLmN0Y3QtZm9ybS13cmFwcGVyIC5jdGN0LWJ1dHRvbiB7XG4gIGZvbnQtc2l6ZTogMC45ZW07XG59XG5cbi5jdGN0LWZvcm0td3JhcHBlciAuY3RjdC1tZXNzYWdlIHtcbiAgYm9yZGVyOiAxcHggc29saWQ7XG4gIHBhZGRpbmc6IDFlbTtcbn1cblxuLmN0Y3QtZm9ybS13cmFwcGVyIC5lcnJvciB7XG4gIGJhY2tncm91bmQtY29sb3I6IHJnYmEoMjU1LCA2NSwgNTQsIDAuMDIpO1xuICBib3JkZXItY29sb3I6ICNGRjQxMzY7XG4gIGNvbG9yOiAjY2YwYjAwO1xufVxuXG4uY3RjdC1mb3JtLXdyYXBwZXIgLnN1Y2Nlc3Mge1xuICBiYWNrZ3JvdW5kLWNvbG9yOiByZ2JhKDQ2LCAyMDQsIDY0LCAwLjAyKTtcbiAgYm9yZGVyLWNvbG9yOiAjMkVDQzQwO1xuICBjb2xvcjogIzFiNzkyNjtcbn1cblxuLmN0Y3QtZm9ybS13cmFwcGVyIC5jdGN0LWZvcm0tZmllbGQge1xuICBtYXJnaW46IDAgMCAxZW07XG59XG5cbi5jdGN0LWZvcm0td3JhcHBlciAuY3RjdC1maWVsZC1pbmxpbmUge1xuICBkaXNwbGF5OiBpbmxpbmUtYmxvY2s7XG59XG5cbkBtZWRpYSAobWluLXdpZHRoOiA5OTJweCkge1xuICAuY3RjdC1mb3JtLXdyYXBwZXIgLmN0Y3QtZmllbGQtaGFsZiB7XG4gICAgZmxvYXQ6IGxlZnQ7XG4gICAgbWFyZ2luLXJpZ2h0OiAyJTtcbiAgICB3aWR0aDogNDglO1xuICB9XG4gIC5jdGN0LWZvcm0td3JhcHBlciAuY3RjdC1maWVsZC1oYWxmOmxhc3Qtb2YtdHlwZSB7XG4gICAgbWFyZ2luLXJpZ2h0OiAwO1xuICB9XG59XG5cbkBtZWRpYSAobWluLXdpZHRoOiA5OTJweCkge1xuICAuY3RjdC1mb3JtLXdyYXBwZXIgLmN0Y3QtZmllbGQtdGhpcmQge1xuICAgIGZsb2F0OiBsZWZ0O1xuICAgIG1hcmdpbi1yaWdodDogMiU7XG4gICAgd2lkdGg6IDMyJTtcbiAgfVxuICAuY3RjdC1mb3JtLXdyYXBwZXIgLmN0Y3QtZmllbGQtdGhpcmQ6bGFzdC1vZi10eXBlIHtcbiAgICBtYXJnaW4tcmlnaHQ6IDA7XG4gIH1cbn1cblxuQG1lZGlhIChtaW4td2lkdGg6IDk5MnB4KSB7XG4gIC5jdGN0LWZvcm0td3JhcHBlciAuY3RjdC1maWVsZC1mb3VydGgge1xuICAgIGZsb2F0OiBsZWZ0O1xuICAgIG1hcmdpbi1yaWdodDogMiU7XG4gICAgd2lkdGg6IDI0JTtcbiAgfVxuICAuY3RjdC1mb3JtLXdyYXBwZXIgLmN0Y3QtZmllbGQtZm91cnRoOmxhc3Qtb2YtdHlwZSB7XG4gICAgbWFyZ2luLXJpZ2h0OiAwO1xuICB9XG59XG5cbi5jdGN0LWZvcm0td3JhcHBlciBpbnB1dFt0eXBlPVwidGV4dFwiXTpyZXF1aXJlZDp2YWxpZCwgLmN0Y3QtZm9ybS13cmFwcGVyIGlucHV0W3R5cGU9XCJlbWFpbFwiXTpyZXF1aXJlZDp2YWxpZCwgLmN0Y3QtZm9ybS13cmFwcGVyIGlucHV0W3R5cGU9XCJwYXNzd29yZFwiXTpyZXF1aXJlZDp2YWxpZCwgLmN0Y3QtZm9ybS13cmFwcGVyIGlucHV0W3R5cGU9XCJ0ZWxcIl06cmVxdWlyZWQ6dmFsaWQsIC5jdGN0LWZvcm0td3JhcHBlciBpbnB1dFt0eXBlPVwibnVtYmVyXCJdOnJlcXVpcmVkOnZhbGlkIHtcbiAgYmFja2dyb3VuZDogd2hpdGUgdXJsKFwiLi4vaW1hZ2VzL2NoZWNrX2NpcmNsZS5zdmdcIikgbm8tcmVwZWF0O1xuICBiYWNrZ3JvdW5kLXBvc2l0aW9uOiA4cHggNTAlO1xuICBiYWNrZ3JvdW5kLXNpemU6IDI0cHg7XG4gIGJvcmRlci1jb2xvcjogIzJFQ0M0MDtcbiAgcGFkZGluZy1sZWZ0OiA0MHB4O1xufVxuXG4uY3RjdC1mb3JtLXdyYXBwZXIgaW5wdXRbdHlwZT1cInRleHRcIl06cmVxdWlyZWQuY3RjdC1pbnZhbGlkLCAuY3RjdC1mb3JtLXdyYXBwZXIgaW5wdXRbdHlwZT1cInRleHRcIl0uY3RjdC1pbnZhbGlkLCAuY3RjdC1mb3JtLXdyYXBwZXIgaW5wdXRbdHlwZT1cImVtYWlsXCJdOnJlcXVpcmVkLmN0Y3QtaW52YWxpZCwgLmN0Y3QtZm9ybS13cmFwcGVyIGlucHV0W3R5cGU9XCJlbWFpbFwiXS5jdGN0LWludmFsaWQsIC5jdGN0LWZvcm0td3JhcHBlciBpbnB1dFt0eXBlPVwicGFzc3dvcmRcIl06cmVxdWlyZWQuY3RjdC1pbnZhbGlkLCAuY3RjdC1mb3JtLXdyYXBwZXIgaW5wdXRbdHlwZT1cInBhc3N3b3JkXCJdLmN0Y3QtaW52YWxpZCwgLmN0Y3QtZm9ybS13cmFwcGVyIGlucHV0W3R5cGU9XCJ0ZWxcIl06cmVxdWlyZWQuY3RjdC1pbnZhbGlkLCAuY3RjdC1mb3JtLXdyYXBwZXIgaW5wdXRbdHlwZT1cInRlbFwiXS5jdGN0LWludmFsaWQsIC5jdGN0LWZvcm0td3JhcHBlciBpbnB1dFt0eXBlPVwibnVtYmVyXCJdOnJlcXVpcmVkLmN0Y3QtaW52YWxpZCwgLmN0Y3QtZm9ybS13cmFwcGVyIGlucHV0W3R5cGU9XCJudW1iZXJcIl0uY3RjdC1pbnZhbGlkIHtcbiAgYmFja2dyb3VuZDogd2hpdGUgdXJsKFwiLi4vaW1hZ2VzL2Vycm9yLnN2Z1wiKSBuby1yZXBlYXQ7XG4gIGJhY2tncm91bmQtY29sb3I6IHJnYmEoMjU1LCA2NSwgNTQsIDAuMDIpO1xuICBiYWNrZ3JvdW5kLXBvc2l0aW9uOiA4cHggNTAlO1xuICBiYWNrZ3JvdW5kLXNpemU6IDI0cHg7XG4gIGJvcmRlci1jb2xvcjogI0ZGNDEzNjtcbiAgcGFkZGluZy1sZWZ0OiA0MHB4O1xufVxuXG4uY3RjdC1mb3JtLXdyYXBwZXIgLmN0Y3QtZmllbGQtZXJyb3Ige1xuICBmb250LXNpemU6IDAuODVlbTtcbiAgZm9udC1zdHlsZTogaXRhbGljO1xufVxuXG4uY3RjdC1mb3JtLXdyYXBwZXIgaW5wdXQuY3RjdC1pbnZhbGlkIHtcbiAgYmFja2dyb3VuZDogd2hpdGUgdXJsKFwiLi4vaW1hZ2VzL2Vycm9yLnN2Z1wiKSBuby1yZXBlYXQ7XG4gIGJhY2tncm91bmQtY29sb3I6IHJnYmEoMjU1LCA2NSwgNTQsIDAuMDIpO1xuICBiYWNrZ3JvdW5kLXBvc2l0aW9uOiA4cHggNTAlO1xuICBiYWNrZ3JvdW5kLXNpemU6IDI0cHg7XG4gIGJvcmRlci1jb2xvcjogI0ZGNDEzNjtcbiAgcGFkZGluZy1sZWZ0OiA0MHB4O1xufVxuXG4uY3RjdC1mb3JtLXdyYXBwZXIgLmN0Y3QtZm9ybTphZnRlciB7XG4gIGNsZWFyOiBib3RoO1xuICBjb250ZW50OiBcIlwiO1xuICBkaXNwbGF5OiB0YWJsZTtcbn1cblxuLmN0Y3QtZm9ybS13cmFwcGVyIC5jdGN0LWZvcm0gYWJiciB7XG4gIGJvcmRlcjogbm9uZTtcbiAgY29sb3I6ICNGRjQxMzY7XG4gIGZvbnQtc2l6ZTogMC45ZW07XG59XG5cbi5jdGN0LWZvcm0td3JhcHBlciAuY3RjdC1pbnB1dC1jb250YWluZXIgbGFiZWwge1xuICBjb2xvcjogI2FhYTtcbiAgZm9udC1zaXplOiAwLjhlbTtcbn1cblxuLmN0Y3QtZm9ybS13cmFwcGVyIC5jdGN0LWZpZWxkLWVycm9yIHtcbiAgY29sb3I6ICNGRjQxMzY7XG59XG5cbi5jdGN0LXR3ZW50eWZvdXJ0ZWVuIC5jdGN0LWZvcm0tZmllbGQgaW5wdXQge1xuICB3aWR0aDogMTAwJTtcbn1cbiJdfQ== */
assets/css/style.min.css CHANGED
@@ -1 +1 @@
1
- .ctct-form-wrapper .ctct-button{font-size:.9em}.ctct-form-wrapper .ctct-message{border:1px solid;padding:1em}.ctct-form-wrapper .error{background-color:rgba(255,65,54,.02);border-color:#ff4136;color:#cf0b00}.ctct-form-wrapper .success{background-color:rgba(46,204,64,.02);border-color:#2ecc40;color:#1b7926}.ctct-form-wrapper .ctct-form-field{margin:0 0 1em}.ctct-form-wrapper .ctct-field-inline{display:inline-block}.ctct-form-wrapper input[type=email]:required:valid,.ctct-form-wrapper input[type=number]:required:valid,.ctct-form-wrapper input[type=password]:required:valid,.ctct-form-wrapper input[type=tel]:required:valid,.ctct-form-wrapper input[type=text]:required:valid{background:url(../images/check_circle.svg) no-repeat;background-position:8px 50%;background-size:24px;border-color:#2ecc40;padding-left:40px}.ctct-form-wrapper input[type=email].ctct-invalid,.ctct-form-wrapper input[type=email]:required.ctct-invalid,.ctct-form-wrapper input[type=number].ctct-invalid,.ctct-form-wrapper input[type=number]:required.ctct-invalid,.ctct-form-wrapper input[type=password].ctct-invalid,.ctct-form-wrapper input[type=password]:required.ctct-invalid,.ctct-form-wrapper input[type=tel].ctct-invalid,.ctct-form-wrapper input[type=tel]:required.ctct-invalid,.ctct-form-wrapper input[type=text].ctct-invalid,.ctct-form-wrapper input[type=text]:required.ctct-invalid{background:url(../images/error.svg) no-repeat;background-color:rgba(255,65,54,.02);background-position:8px 50%;background-size:24px;border-color:#ff4136;padding-left:40px}.ctct-form-wrapper .ctct-field-error{font-size:.85em;font-style:italic}.ctct-form-wrapper input.ctct-invalid{background:url(../images/error.svg) no-repeat;background-color:rgba(255,65,54,.02);background-position:8px 50%;background-size:24px;border-color:#ff4136;padding-left:40px}.ctct-form-wrapper .ctct-form:after{clear:both;content:"";display:table}.ctct-form-wrapper .ctct-form abbr{border:none;color:#ff4136;font-size:.9em}.ctct-form-wrapper .ctct-input-container label{color:#aaa;font-size:.8em}.ctct-form-wrapper .ctct-field-error{color:#ff4136}.ctct-twentyfourteen .ctct-form-field input{width:100%}@media (min-width:992px){.ctct-form-wrapper .ctct-field-half{float:left;margin-right:2%;width:48%}.ctct-form-wrapper .ctct-field-half:last-of-type{margin-right:0}.ctct-form-wrapper .ctct-field-third{float:left;margin-right:2%;width:32%}.ctct-form-wrapper .ctct-field-third:last-of-type{margin-right:0}.ctct-form-wrapper .ctct-field-fourth{float:left;margin-right:2%;width:24%}.ctct-form-wrapper .ctct-field-fourth:last-of-type{margin-right:0}}
1
+ .ctct-form-wrapper .ctct-button{font-size:.9em}.ctct-form-wrapper .ctct-message{border:1px solid;padding:1em}.ctct-form-wrapper .error{background-color:rgba(255,65,54,.02);border-color:#ff4136;color:#cf0b00}.ctct-form-wrapper .success{background-color:rgba(46,204,64,.02);border-color:#2ecc40;color:#1b7926}.ctct-form-wrapper .ctct-form-field{margin:0 0 1em}.ctct-form-wrapper .ctct-field-inline{display:inline-block}.ctct-form-wrapper input[type=email]:required:valid,.ctct-form-wrapper input[type=number]:required:valid,.ctct-form-wrapper input[type=password]:required:valid,.ctct-form-wrapper input[type=tel]:required:valid,.ctct-form-wrapper input[type=text]:required:valid{background:#fff url(../images/check_circle.svg) no-repeat;background-position:8px 50%;background-size:24px;border-color:#2ecc40;padding-left:40px}.ctct-form-wrapper input[type=email].ctct-invalid,.ctct-form-wrapper input[type=email]:required.ctct-invalid,.ctct-form-wrapper input[type=number].ctct-invalid,.ctct-form-wrapper input[type=number]:required.ctct-invalid,.ctct-form-wrapper input[type=password].ctct-invalid,.ctct-form-wrapper input[type=password]:required.ctct-invalid,.ctct-form-wrapper input[type=tel].ctct-invalid,.ctct-form-wrapper input[type=tel]:required.ctct-invalid,.ctct-form-wrapper input[type=text].ctct-invalid,.ctct-form-wrapper input[type=text]:required.ctct-invalid{background:#fff url(../images/error.svg) no-repeat;background-color:rgba(255,65,54,.02);background-position:8px 50%;background-size:24px;border-color:#ff4136;padding-left:40px}.ctct-form-wrapper .ctct-field-error{font-size:.85em;font-style:italic}.ctct-form-wrapper input.ctct-invalid{background:#fff url(../images/error.svg) no-repeat;background-color:rgba(255,65,54,.02);background-position:8px 50%;background-size:24px;border-color:#ff4136;padding-left:40px}.ctct-form-wrapper .ctct-form:after{clear:both;content:"";display:table}.ctct-form-wrapper .ctct-form abbr{border:none;color:#ff4136;font-size:.9em}.ctct-form-wrapper .ctct-input-container label{color:#aaa;font-size:.8em}.ctct-form-wrapper .ctct-field-error{color:#ff4136}.ctct-twentyfourteen .ctct-form-field input{width:100%}@media (min-width:992px){.ctct-form-wrapper .ctct-field-half{float:left;margin-right:2%;width:48%}.ctct-form-wrapper .ctct-field-half:last-of-type{margin-right:0}.ctct-form-wrapper .ctct-field-third{float:left;margin-right:2%;width:32%}.ctct-form-wrapper .ctct-field-third:last-of-type{margin-right:0}.ctct-form-wrapper .ctct-field-fourth{float:left;margin-right:2%;width:24%}.ctct-form-wrapper .ctct-field-fourth:last-of-type{margin-right:0}}
assets/sass/_inputs.scss CHANGED
@@ -14,7 +14,7 @@
14
 
15
  // show success!
16
  &:required:valid {
17
- background: url( '../images/check_circle.svg' ) no-repeat;
18
  background-position: 8px 50%;
19
  background-size: 24px;
20
  border-color: $color-success;
@@ -24,7 +24,7 @@
24
  // show error.
25
  &:required.ctct-invalid,
26
  &.ctct-invalid {
27
- background: url( '../images/error.svg' ) no-repeat;
28
  background-color: fade-out($color-error, 0.98);
29
  background-position: 8px 50%;
30
  background-size: 24px;
@@ -41,7 +41,7 @@
41
  }
42
 
43
  input.ctct-invalid {
44
- background: url( '../images/error.svg' ) no-repeat;
45
  background-color: fade-out($color-error, 0.98);
46
  background-position: 8px 50%;
47
  background-size: 24px;
14
 
15
  // show success!
16
  &:required:valid {
17
+ background: rgb(255,255,255) url( '../images/check_circle.svg' ) no-repeat;
18
  background-position: 8px 50%;
19
  background-size: 24px;
20
  border-color: $color-success;
24
  // show error.
25
  &:required.ctct-invalid,
26
  &.ctct-invalid {
27
+ background: rgb(255,255,255) url( '../images/error.svg' ) no-repeat;
28
  background-color: fade-out($color-error, 0.98);
29
  background-position: 8px 50%;
30
  background-size: 24px;
41
  }
42
 
43
  input.ctct-invalid {
44
+ background: rgb(255,255,255) url( '../images/error.svg' ) no-repeat;
45
  background-color: fade-out($color-error, 0.98);
46
  background-position: 8px 50%;
47
  background-size: 24px;
assets/sass/admin-forms.scss CHANGED
@@ -3,7 +3,7 @@
3
  @import 'modal';
4
 
5
 
6
- .misc-pub-section {
7
  &.misc-pub-visibility,
8
  &.misc-pub-curtime {
9
  display: none;
3
  @import 'modal';
4
 
5
 
6
+ .post-type-ctct_forms .misc-pub-section {
7
  &.misc-pub-visibility,
8
  &.misc-pub-curtime {
9
  display: none;
constant-contact-forms.php CHANGED
@@ -12,7 +12,7 @@
12
  * Plugin Name: Constant Contact Forms for WordPress
13
  * Plugin URI: https://www.constantcontact.com
14
  * Description: Be a better marketer. All it takes is Constant Contact email marketing.
15
- * Version: 1.2.0
16
  * Author: Constant Contact
17
  * Author URI: https://www.constantcontact.com
18
  * License: GPLv3
@@ -77,7 +77,7 @@ class Constant_Contact {
77
  * @var string
78
  * @since 1.0.0
79
  */
80
- const VERSION = '1.2.0';
81
 
82
  /**
83
  * URL of plugin directory
@@ -319,13 +319,15 @@ class Constant_Contact {
319
  */
320
  function _deactivate() {
321
 
322
- // If we deactivate the plugin, remove our saved dismiss state for the activation
323
- // admin notice that pops up, so we can re-prompt the user to connect.
324
- $this->notifications->delete_dismissed_notification( 'activation' );
325
-
326
- // Remove our saved transients for our lists, so we force a refresh on re-connection.
327
- delete_transient( 'ctct_lists' );
328
 
 
 
 
329
  }
330
 
331
  /**
12
  * Plugin Name: Constant Contact Forms for WordPress
13
  * Plugin URI: https://www.constantcontact.com
14
  * Description: Be a better marketer. All it takes is Constant Contact email marketing.
15
+ * Version: 1.2.1
16
  * Author: Constant Contact
17
  * Author URI: https://www.constantcontact.com
18
  * License: GPLv3
77
  * @var string
78
  * @since 1.0.0
79
  */
80
+ const VERSION = '1.2.1';
81
 
82
  /**
83
  * URL of plugin directory
319
  */
320
  function _deactivate() {
321
 
322
+ // Should be nothing to delete for non-met users, since it never ran in the first place.
323
+ if ( $this->meets_php_requirements() ) {
324
+ // If we deactivate the plugin, remove our saved dismiss state for the activation
325
+ // admin notice that pops up, so we can re-prompt the user to connect.
326
+ $this->notifications->delete_dismissed_notification( 'activation' );
 
327
 
328
+ // Remove our saved transients for our lists, so we force a refresh on re-connection.
329
+ delete_transient( 'ctct_lists' );
330
+ }
331
  }
332
 
333
  /**
includes/class-mail.php CHANGED
@@ -195,10 +195,17 @@ class ConstantContact_Mail {
195
 
196
  // If we already have sent this e-mail, don't send it again.
197
  if ( $last_sent === $mail_key ) {
198
- $this->maybe_log_mail_status( vsprintf( __( 'Duplicate send mail for: %s and: %s' ), array(
 
 
 
 
 
 
 
199
  $destination_email,
200
- $mail_key,
201
- ) ) );
202
  return true;
203
  }
204
 
195
 
196
  // If we already have sent this e-mail, don't send it again.
197
  if ( $last_sent === $mail_key ) {
198
+ $this->maybe_log_mail_status(
199
+ vsprintf(
200
+ __( 'Duplicate send mail for: %s and: %s' ),
201
+ array(
202
+ $destination_email,
203
+ $mail_key,
204
+ )
205
+ ),
206
  $destination_email,
207
+ $mail_key
208
+ );
209
  return true;
210
  }
211
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: constantcontact
3
  Tags: capture, contacts, constant contact, constant contact form, constant contact newsletter, constant contact official, contact forms, email, form, forms, marketing, mobile, newsletter, opt-in, plugin, signup, subscribe, subscription, widget
4
  Requires at least: 4.0.0
5
  Tested up to: 4.7.2
6
- Stable tag: 1.2.0
7
  License: GPLv2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -33,6 +33,13 @@ BONUS: If you have a Constant Contact account, all new email addresses that you
33
 
34
  == Changelog ==
35
 
 
 
 
 
 
 
 
36
  = 1.2.0 =
37
  * Added: Reveal shortcode for newly published form in admin notice and popup for non-connected accounts.
38
  * Added: Classes for individual form inputs and textareas on rendered form.
3
  Tags: capture, contacts, constant contact, constant contact form, constant contact newsletter, constant contact official, contact forms, email, form, forms, marketing, mobile, newsletter, opt-in, plugin, signup, subscribe, subscription, widget
4
  Requires at least: 4.0.0
5
  Tested up to: 4.7.2
6
+ Stable tag: 1.2.1
7
  License: GPLv2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
33
 
34
  == Changelog ==
35
 
36
+ = 1.2.1 =
37
+ * Fixed: Re-show sections of "Publish" metabox incorrectly hidden for post types outside Constant Contact Forms.
38
+ * Fixed: Issues with transparent background on frontend forms when input is valid.
39
+ * Fixed: Fatal errors on deactivation if user is on PHP 5.3 or lower.
40
+ * Fixed: PHP Warnings regarding missing parameters for maybe_log_mail_status().
41
+ * Updated: Bumped Guzzle to 5.3.1 for PHP7.1 compatibility.
42
+
43
  = 1.2.0 =
44
  * Added: Reveal shortcode for newly published form in admin notice and popup for non-connected accounts.
45
  * Added: Classes for individual form inputs and textareas on rendered form.
vendor/constantcontact/guzzlehttp/guzzle/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
  # CHANGELOG
2
 
 
 
 
 
 
 
 
3
  ## 5.3.0 - 2015-05-19
4
 
5
  * Mock now supports `save_to`
1
  # CHANGELOG
2
 
3
+ ## 5.3.1 - 2016-07-18
4
+
5
+ * Address HTTP_PROXY security vulnerability, CVE-2016-5385:
6
+ https://httpoxy.org/
7
+ * Event name fix: https://github.com/guzzle/guzzle/commit/fcae91ff31de41e312fe113ec3acbcda31b2622e
8
+ * Response header case sensitivity fix: https://github.com/guzzle/guzzle/commit/043eeadf20ee40ddc6712faee4d3957a91f2b041
9
+
10
  ## 5.3.0 - 2015-05-19
11
 
12
  * Mock now supports `save_to`
vendor/constantcontact/guzzlehttp/guzzle/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Michael Dowling, https://github.com/mtdowling <mtdowling@gmail.com>
2
 
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
  of this software and associated documentation files (the "Software"), to deal
1
+ Copyright (c) 2011-2015 Michael Dowling, https://github.com/mtdowling <mtdowling@gmail.com>
2
 
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
  of this software and associated documentation files (the "Software"), to deal
vendor/constantcontact/guzzlehttp/guzzle/README.md CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/UPGRADING.md CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/composer.json CHANGED
@@ -14,11 +14,11 @@
14
  ],
15
  "require": {
16
  "php": ">=5.4.0",
17
- "guzzlehttp/ringphp": "^1.1"
 
18
  },
19
  "require-dev": {
20
  "ext-curl": "*",
21
- "psr/log": "^1.0",
22
  "phpunit/phpunit": "^4.0"
23
  },
24
  "autoload": {
@@ -31,9 +31,8 @@
31
  "GuzzleHttp\\Tests\\": "tests/"
32
  }
33
  },
34
- "extra": {
35
- "branch-alias": {
36
- "dev-master": "5.0-dev"
37
- }
38
  }
39
  }
14
  ],
15
  "require": {
16
  "php": ">=5.4.0",
17
+ "guzzlehttp/ringphp": "^1.1",
18
+ "react/promise": "^2.2"
19
  },
20
  "require-dev": {
21
  "ext-curl": "*",
 
22
  "phpunit/phpunit": "^4.0"
23
  },
24
  "autoload": {
31
  "GuzzleHttp\\Tests\\": "tests/"
32
  }
33
  },
34
+ "scripts": {
35
+ "test": "make test",
36
+ "test-ci": "make coverage"
 
37
  }
38
  }
vendor/constantcontact/guzzlehttp/guzzle/docs/Makefile DELETED
@@ -1,153 +0,0 @@
1
- # Makefile for Sphinx documentation
2
- #
3
-
4
- # You can set these variables from the command line.
5
- SPHINXOPTS =
6
- SPHINXBUILD = sphinx-build
7
- PAPER =
8
- BUILDDIR = _build
9
-
10
- # Internal variables.
11
- PAPEROPT_a4 = -D latex_paper_size=a4
12
- PAPEROPT_letter = -D latex_paper_size=letter
13
- ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
14
- # the i18n builder cannot share the environment and doctrees with the others
15
- I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
16
-
17
- .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
18
-
19
- help:
20
- @echo "Please use \`make <target>' where <target> is one of"
21
- @echo " html to make standalone HTML files"
22
- @echo " dirhtml to make HTML files named index.html in directories"
23
- @echo " singlehtml to make a single large HTML file"
24
- @echo " pickle to make pickle files"
25
- @echo " json to make JSON files"
26
- @echo " htmlhelp to make HTML files and a HTML help project"
27
- @echo " qthelp to make HTML files and a qthelp project"
28
- @echo " devhelp to make HTML files and a Devhelp project"
29
- @echo " epub to make an epub"
30
- @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
31
- @echo " latexpdf to make LaTeX files and run them through pdflatex"
32
- @echo " text to make text files"
33
- @echo " man to make manual pages"
34
- @echo " texinfo to make Texinfo files"
35
- @echo " info to make Texinfo files and run them through makeinfo"
36
- @echo " gettext to make PO message catalogs"
37
- @echo " changes to make an overview of all changed/added/deprecated items"
38
- @echo " linkcheck to check all external links for integrity"
39
- @echo " doctest to run all doctests embedded in the documentation (if enabled)"
40
-
41
- clean:
42
- -rm -rf $(BUILDDIR)/*
43
-
44
- html:
45
- $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
46
- @echo
47
- @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
48
-
49
- dirhtml:
50
- $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
51
- @echo
52
- @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
53
-
54
- singlehtml:
55
- $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
56
- @echo
57
- @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
58
-
59
- pickle:
60
- $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
61
- @echo
62
- @echo "Build finished; now you can process the pickle files."
63
-
64
- json:
65
- $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
66
- @echo
67
- @echo "Build finished; now you can process the JSON files."
68
-
69
- htmlhelp:
70
- $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
71
- @echo
72
- @echo "Build finished; now you can run HTML Help Workshop with the" \
73
- ".hhp project file in $(BUILDDIR)/htmlhelp."
74
-
75
- qthelp:
76
- $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
77
- @echo
78
- @echo "Build finished; now you can run "qcollectiongenerator" with the" \
79
- ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
80
- @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Guzzle.qhcp"
81
- @echo "To view the help file:"
82
- @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Guzzle.qhc"
83
-
84
- devhelp:
85
- $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
86
- @echo
87
- @echo "Build finished."
88
- @echo "To view the help file:"
89
- @echo "# mkdir -p $$HOME/.local/share/devhelp/Guzzle"
90
- @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Guzzle"
91
- @echo "# devhelp"
92
-
93
- epub:
94
- $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
95
- @echo
96
- @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
97
-
98
- latex:
99
- $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
100
- @echo
101
- @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
102
- @echo "Run \`make' in that directory to run these through (pdf)latex" \
103
- "(use \`make latexpdf' here to do that automatically)."
104
-
105
- latexpdf:
106
- $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
107
- @echo "Running LaTeX files through pdflatex..."
108
- $(MAKE) -C $(BUILDDIR)/latex all-pdf
109
- @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
110
-
111
- text:
112
- $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
113
- @echo
114
- @echo "Build finished. The text files are in $(BUILDDIR)/text."
115
-
116
- man:
117
- $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
118
- @echo
119
- @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
120
-
121
- texinfo:
122
- $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
123
- @echo
124
- @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
125
- @echo "Run \`make' in that directory to run these through makeinfo" \
126
- "(use \`make info' here to do that automatically)."
127
-
128
- info:
129
- $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
130
- @echo "Running Texinfo files through makeinfo..."
131
- make -C $(BUILDDIR)/texinfo info
132
- @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
133
-
134
- gettext:
135
- $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
136
- @echo
137
- @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
138
-
139
- changes:
140
- $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
141
- @echo
142
- @echo "The overview file is in $(BUILDDIR)/changes."
143
-
144
- linkcheck:
145
- $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
146
- @echo
147
- @echo "Link check complete; look for any errors in the above output " \
148
- "or in $(BUILDDIR)/linkcheck/output.txt."
149
-
150
- doctest:
151
- $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
152
- @echo "Testing of doctests in the sources finished, look at the " \
153
- "results in $(BUILDDIR)/doctest/output.txt."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/docs/_static/guzzle-icon.png DELETED
Binary file
vendor/constantcontact/guzzlehttp/guzzle/docs/_static/logo.png DELETED
Binary file
vendor/constantcontact/guzzlehttp/guzzle/docs/_templates/nav_links.html DELETED
@@ -1,3 +0,0 @@
1
- <li><a href="https://github.com/guzzle/guzzle">GitHub</a></li>
2
- <li><a href="https://groups.google.com/forum/?hl=en#!forum/guzzle">Forum</a></li>
3
- <li><a href="irc:irc.freenode.com/#guzzlephp">IRC</a></li>
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/docs/clients.rst DELETED
@@ -1,1326 +0,0 @@
1
- =======
2
- Clients
3
- =======
4
-
5
- Clients are used to create requests, create transactions, send requests
6
- through an HTTP handler, and return a response. You can add default request
7
- options to a client that are applied to every request (e.g., default headers,
8
- default query string parameters, etc.), and you can add event listeners and
9
- subscribers to every request created by a client.
10
-
11
- Creating a client
12
- =================
13
-
14
- The constructor of a client accepts an associative array of configuration
15
- options.
16
-
17
- base_url
18
- Configures a base URL for the client so that requests created
19
- using a relative URL are combined with the ``base_url`` of the client
20
- according to section `5.2 of RFC 3986 <http://tools.ietf.org/html/rfc3986#section-5.2>`_.
21
-
22
- .. code-block:: php
23
-
24
- // Create a client with a base URL
25
- $client = new GuzzleHttp\Client(['base_url' => 'https://github.com']);
26
- // Send a request to https://github.com/notifications
27
- $response = $client->get('/notifications');
28
-
29
- Don't feel like reading RFC 3986? Here are some quick examples on how a
30
- ``base_url`` is resolved with another URI.
31
-
32
- ======================= ================== ===============================
33
- base_url URI Result
34
- ======================= ================== ===============================
35
- ``http://foo.com`` ``/bar`` ``http://foo.com/bar``
36
- ``http://foo.com/foo`` ``/bar`` ``http://foo.com/bar``
37
- ``http://foo.com/foo`` ``bar`` ``http://foo.com/bar``
38
- ``http://foo.com/foo/`` ``bar`` ``http://foo.com/foo/bar``
39
- ``http://foo.com`` ``http://baz.com`` ``http://baz.com``
40
- ``http://foo.com/?bar`` ``bar`` ``http://foo.com/bar``
41
- ======================= ================== ===============================
42
-
43
- handler
44
- Configures the `RingPHP handler <http://ringphp.readthedocs.org>`_
45
- used to transfer the HTTP requests of a client. Guzzle will, by default,
46
- utilize a stacked handlers that chooses the best handler to use based on the
47
- provided request options and based on the extensions available in the
48
- environment.
49
-
50
- message_factory
51
- Specifies the factory used to create HTTP requests and responses
52
- (``GuzzleHttp\Message\MessageFactoryInterface``).
53
-
54
- defaults
55
- Associative array of :ref:`request-options` that are applied to every
56
- request created by the client. This allows you to specify things like
57
- default headers (e.g., User-Agent), default query string parameters, SSL
58
- configurations, and any other supported request options.
59
-
60
- emitter
61
- Specifies an event emitter (``GuzzleHttp\Event\EmitterInterface``) instance
62
- to be used by the client to emit request events. This option is useful if
63
- you need to inject an emitter with listeners/subscribers already attached.
64
-
65
- Here's an example of creating a client with various options.
66
-
67
- .. code-block:: php
68
-
69
- use GuzzleHttp\Client;
70
-
71
- $client = new Client([
72
- 'base_url' => ['https://api.twitter.com/{version}/', ['version' => 'v1.1']],
73
- 'defaults' => [
74
- 'headers' => ['Foo' => 'Bar'],
75
- 'query' => ['testing' => '123'],
76
- 'auth' => ['username', 'password'],
77
- 'proxy' => 'tcp://localhost:80'
78
- ]
79
- ]);
80
-
81
- Sending Requests
82
- ================
83
-
84
- Requests can be created using various methods of a client. You can create
85
- **and** send requests using one of the following methods:
86
-
87
- - ``GuzzleHttp\Client::get``: Sends a GET request.
88
- - ``GuzzleHttp\Client::head``: Sends a HEAD request
89
- - ``GuzzleHttp\Client::post``: Sends a POST request
90
- - ``GuzzleHttp\Client::put``: Sends a PUT request
91
- - ``GuzzleHttp\Client::delete``: Sends a DELETE request
92
- - ``GuzzleHttp\Client::options``: Sends an OPTIONS request
93
-
94
- Each of the above methods accepts a URL as the first argument and an optional
95
- associative array of :ref:`request-options` as the second argument.
96
-
97
- Synchronous Requests
98
- --------------------
99
-
100
- Guzzle sends synchronous (blocking) requests when the ``future`` request option
101
- is not specified. This means that the request will complete immediately, and if
102
- an error is encountered, a ``GuzzleHttp\Exception\RequestException`` will be
103
- thrown.
104
-
105
- .. code-block:: php
106
-
107
- $client = new GuzzleHttp\Client();
108
-
109
- $client->put('http://httpbin.org', [
110
- 'headers' => ['X-Foo' => 'Bar'],
111
- 'body' => 'this is the body!',
112
- 'save_to' => '/path/to/local/file',
113
- 'allow_redirects' => false,
114
- 'timeout' => 5
115
- ]);
116
-
117
- Synchronous Error Handling
118
- ~~~~~~~~~~~~~~~~~~~~~~~~~~
119
-
120
- When a recoverable error is encountered while calling the ``send()`` method of
121
- a client, a ``GuzzleHttp\Exception\RequestException`` is thrown.
122
-
123
- .. code-block:: php
124
-
125
- use GuzzleHttp\Client;
126
- use GuzzleHttp\Exception\RequestException;
127
-
128
- $client = new Client();
129
-
130
- try {
131
- $client->get('http://httpbin.org');
132
- } catch (RequestException $e) {
133
- echo $e->getRequest() . "\n";
134
- if ($e->hasResponse()) {
135
- echo $e->getResponse() . "\n";
136
- }
137
- }
138
-
139
- ``GuzzleHttp\Exception\RequestException`` always contains a
140
- ``GuzzleHttp\Message\RequestInterface`` object that can be accessed using the
141
- exception's ``getRequest()`` method.
142
-
143
- A response might be present in the exception. In the event of a networking
144
- error, no response will be received. You can check if a ``RequestException``
145
- has a response using the ``hasResponse()`` method. If the exception has a
146
- response, then you can access the associated
147
- ``GuzzleHttp\Message\ResponseInterface`` using the ``getResponse()`` method of
148
- the exception.
149
-
150
- Asynchronous Requests
151
- ---------------------
152
-
153
- You can send asynchronous requests by setting the ``future`` request option
154
- to ``true`` (or a string that your handler understands). This creates a
155
- ``GuzzleHttp\Message\FutureResponse`` object that has not yet completed. Once
156
- you have a future response, you can use a promise object obtained by calling
157
- the ``then`` method of the response to take an action when the response has
158
- completed or encounters an error.
159
-
160
- .. code-block:: php
161
-
162
- $response = $client->put('http://httpbin.org/get', ['future' => true]);
163
-
164
- // Call the function when the response completes
165
- $response->then(function ($response) {
166
- echo $response->getStatusCode();
167
- });
168
-
169
- You can call the ``wait()`` method of a future response to block until it has
170
- completed. You also use a future response object just like a normal response
171
- object by accessing the methods of the response. Using a future response like a
172
- normal response object, also known as *dereferencing*, will block until the
173
- response has completed.
174
-
175
- .. code-block:: php
176
-
177
- $response = $client->put('http://httpbin.org/get', ['future' => true]);
178
-
179
- // Block until the response has completed
180
- echo $response->getStatusCode();
181
-
182
- .. important::
183
-
184
- If an exception occurred while transferring the future response, then the
185
- exception encountered will be thrown when dereferencing.
186
-
187
- .. note::
188
-
189
- It depends on the RingPHP handler used by a client, but you typically need
190
- to use the same RingPHP handler in order to utilize asynchronous requests
191
- across multiple clients.
192
-
193
- Asynchronous Error Handling
194
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
195
-
196
- Handling errors with future response object promises is a bit different. When
197
- using a promise, exceptions are forwarded to the ``$onError`` function provided
198
- to the second argument of the ``then()`` function.
199
-
200
- .. code-block:: php
201
-
202
- $response = $client->put('http://httpbin.org/get', ['future' => true]);
203
-
204
- $response
205
- ->then(
206
- function ($response) {
207
- // This is called when the request succeeded
208
- echo 'Success: ' . $response->getStatusCode();
209
- // Returning a value will forward the value to the next promise
210
- // in the chain.
211
- return $response;
212
- },
213
- function ($error) {
214
- // This is called when the exception failed.
215
- echo 'Exception: ' . $error->getMessage();
216
- // Throwing will "forward" the exception to the next promise
217
- // in the chain.
218
- throw $error;
219
- }
220
- )
221
- ->then(
222
- function($response) {
223
- // This is called after the first promise in the chain. It
224
- // receives the value returned from the first promise.
225
- echo $response->getReasonPhrase();
226
- },
227
- function ($error) {
228
- // This is called if the first promise error handler in the
229
- // chain rethrows the exception.
230
- echo 'Error: ' . $error->getMessage();
231
- }
232
- );
233
-
234
- Please see the `React/Promises project documentation <https://github.com/reactphp/promise>`_
235
- for more information on how promise resolution and rejection forwarding works.
236
-
237
- HTTP Errors
238
- -----------
239
-
240
- If the ``exceptions`` request option is not set to ``false``, then exceptions
241
- are thrown for HTTP protocol errors as well:
242
- ``GuzzleHttp\Exception\ClientErrorResponseException`` for 4xx level HTTP
243
- responses and ``GuzzleHttp\Exception\ServerException`` for 5xx level responses,
244
- both of which extend from ``GuzzleHttp\Exception\BadResponseException``.
245
-
246
- Creating Requests
247
- -----------------
248
-
249
- You can create a request without sending it. This is useful for building up
250
- requests over time or sending requests in concurrently.
251
-
252
- .. code-block:: php
253
-
254
- $request = $client->createRequest('GET', 'http://httpbin.org', [
255
- 'headers' => ['X-Foo' => 'Bar']
256
- ]);
257
-
258
- // Modify the request as needed
259
- $request->setHeader('Baz', 'bar');
260
-
261
- After creating a request, you can send it with the client's ``send()`` method.
262
-
263
- .. code-block:: php
264
-
265
- $response = $client->send($request);
266
-
267
- Sending Requests With a Pool
268
- ============================
269
-
270
- You can send requests concurrently using a fixed size pool via the
271
- ``GuzzleHttp\Pool`` class. The Pool class is an implementation of
272
- ``GuzzleHttp\Ring\Future\FutureInterface``, meaning it can be dereferenced at a
273
- later time or cancelled before sending. The Pool constructor accepts a client
274
- object, iterator or array that yields ``GuzzleHttp\Message\RequestInterface``
275
- objects, and an optional associative array of options that can be used to
276
- affect the transfer.
277
-
278
- .. code-block:: php
279
-
280
- use GuzzleHttp\Pool;
281
-
282
- $requests = [
283
- $client->createRequest('GET', 'http://httpbin.org'),
284
- $client->createRequest('DELETE', 'http://httpbin.org/delete'),
285
- $client->createRequest('PUT', 'http://httpbin.org/put', ['body' => 'test'])
286
- ];
287
-
288
- $options = [];
289
-
290
- // Create a pool. Note: the options array is optional.
291
- $pool = new Pool($client, $requests, $options);
292
-
293
- // Send the requests
294
- $pool->wait();
295
-
296
- The Pool constructor accepts the following associative array of options:
297
-
298
- - **pool_size**: Integer representing the maximum number of requests that are
299
- allowed to be sent concurrently.
300
- - **before**: Callable or array representing the event listeners to add to
301
- each request's :ref:`before_event` event.
302
- - **complete**: Callable or array representing the event listeners to add to
303
- each request's :ref:`complete_event` event.
304
- - **error**: Callable or array representing the event listeners to add to
305
- each request's :ref:`error_event` event.
306
- - **end**: Callable or array representing the event listeners to add to
307
- each request's :ref:`end_event` event.
308
-
309
- The "before", "complete", "error", and "end" event options accept a callable or
310
- an array of associative arrays where each associative array contains a "fn" key
311
- with a callable value, an optional "priority" key representing the event
312
- priority (with a default value of 0), and an optional "once" key that can be
313
- set to true so that the event listener will be removed from the request after
314
- it is first triggered.
315
-
316
- .. code-block:: php
317
-
318
- use GuzzleHttp\Pool;
319
- use GuzzleHttp\Event\CompleteEvent;
320
-
321
- // Add a single event listener using a callable.
322
- Pool::send($client, $requests, [
323
- 'complete' => function (CompleteEvent $event) {
324
- echo 'Completed request to ' . $event->getRequest()->getUrl() . "\n";
325
- echo 'Response: ' . $event->getResponse()->getBody() . "\n\n";
326
- }
327
- ]);
328
-
329
- // The above is equivalent to the following, but the following structure
330
- // allows you to add multiple event listeners to the same event name.
331
- Pool::send($client, $requests, [
332
- 'complete' => [
333
- [
334
- 'fn' => function (CompleteEvent $event) { /* ... */ },
335
- 'priority' => 0, // Optional
336
- 'once' => false // Optional
337
- ]
338
- ]
339
- ]);
340
-
341
- Asynchronous Response Handling
342
- ------------------------------
343
-
344
- When sending requests concurrently using a pool, the request/response/error
345
- lifecycle must be handled asynchronously. This means that you give the Pool
346
- multiple requests and handle the response or errors that is associated with the
347
- request using event callbacks.
348
-
349
- .. code-block:: php
350
-
351
- use GuzzleHttp\Pool;
352
- use GuzzleHttp\Event\ErrorEvent;
353
-
354
- Pool::send($client, $requests, [
355
- 'complete' => function (CompleteEvent $event) {
356
- echo 'Completed request to ' . $event->getRequest()->getUrl() . "\n";
357
- echo 'Response: ' . $event->getResponse()->getBody() . "\n\n";
358
- // Do something with the completion of the request...
359
- },
360
- 'error' => function (ErrorEvent $event) {
361
- echo 'Request failed: ' . $event->getRequest()->getUrl() . "\n";
362
- echo $event->getException();
363
- // Do something to handle the error...
364
- }
365
- ]);
366
-
367
- The ``GuzzleHttp\Event\ErrorEvent`` event object is emitted when an error
368
- occurs during a transfer. With this event, you have access to the request that
369
- was sent, the response that was received (if one was received), access to
370
- transfer statistics, and the ability to intercept the exception with a
371
- different ``GuzzleHttp\Message\ResponseInterface`` object. See :doc:`events`
372
- for more information.
373
-
374
- Handling Errors After Transferring
375
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
376
-
377
- It sometimes might be easier to handle all of the errors that occurred during a
378
- transfer after all of the requests have been sent. Here we are adding each
379
- failed request to an array that we can use to process errors later.
380
-
381
- .. code-block:: php
382
-
383
- use GuzzleHttp\Pool;
384
- use GuzzleHttp\Event\ErrorEvent;
385
-
386
- $errors = [];
387
- Pool::send($client, $requests, [
388
- 'error' => function (ErrorEvent $event) use (&$errors) {
389
- $errors[] = $event;
390
- }
391
- ]);
392
-
393
- foreach ($errors as $error) {
394
- // Handle the error...
395
- }
396
-
397
- .. _batch-requests:
398
-
399
- Batching Requests
400
- -----------------
401
-
402
- Sometimes you just want to send a few requests concurrently and then process
403
- the results all at once after they've been sent. Guzzle provides a convenience
404
- function ``GuzzleHttp\Pool::batch()`` that makes this very simple:
405
-
406
- .. code-block:: php
407
-
408
- use GuzzleHttp\Pool;
409
- use GuzzleHttp\Client;
410
-
411
- $client = new Client();
412
-
413
- $requests = [
414
- $client->createRequest('GET', 'http://httpbin.org/get'),
415
- $client->createRequest('HEAD', 'http://httpbin.org/get'),
416
- $client->createRequest('PUT', 'http://httpbin.org/put'),
417
- ];
418
-
419
- // Results is a GuzzleHttp\BatchResults object.
420
- $results = Pool::batch($client, $requests);
421
-
422
- // Can be accessed by index.
423
- echo $results[0]->getStatusCode();
424
-
425
- // Can be accessed by request.
426
- echo $results->getResult($requests[0])->getStatusCode();
427
-
428
- // Retrieve all successful responses
429
- foreach ($results->getSuccessful() as $response) {
430
- echo $response->getStatusCode() . "\n";
431
- }
432
-
433
- // Retrieve all failures.
434
- foreach ($results->getFailures() as $requestException) {
435
- echo $requestException->getMessage() . "\n";
436
- }
437
-
438
- ``GuzzleHttp\Pool::batch()`` accepts an optional associative array of options
439
- in the third argument that allows you to specify the 'before', 'complete',
440
- 'error', and 'end' events as well as specify the maximum number of requests to
441
- send concurrently using the 'pool_size' option key.
442
-
443
- .. _request-options:
444
-
445
- Request Options
446
- ===============
447
-
448
- You can customize requests created by a client using **request options**.
449
- Request options control various aspects of a request including, headers,
450
- query string parameters, timeout settings, the body of a request, and much
451
- more.
452
-
453
- All of the following examples use the following client:
454
-
455
- .. code-block:: php
456
-
457
- $client = new GuzzleHttp\Client(['base_url' => 'http://httpbin.org']);
458
-
459
- headers
460
- -------
461
-
462
- :Summary: Associative array of headers to add to the request. Each key is the
463
- name of a header, and each value is a string or array of strings
464
- representing the header field values.
465
- :Types: array
466
- :Defaults: None
467
-
468
- .. code-block:: php
469
-
470
- // Set various headers on a request
471
- $client->get('/get', [
472
- 'headers' => [
473
- 'User-Agent' => 'testing/1.0',
474
- 'Accept' => 'application/json',
475
- 'X-Foo' => ['Bar', 'Baz']
476
- ]
477
- ]);
478
-
479
- body
480
- ----
481
-
482
- :Summary: The ``body`` option is used to control the body of an entity
483
- enclosing request (e.g., PUT, POST, PATCH).
484
- :Types:
485
- - string
486
- - ``fopen()`` resource
487
- - ``GuzzleHttp\Stream\StreamInterface``
488
- - ``GuzzleHttp\Post\PostBodyInterface``
489
- :Default: None
490
-
491
- This setting can be set to any of the following types:
492
-
493
- - string
494
-
495
- .. code-block:: php
496
-
497
- // You can send requests that use a string as the message body.
498
- $client->put('/put', ['body' => 'foo']);
499
-
500
- - resource returned from ``fopen()``
501
-
502
- .. code-block:: php
503
-
504
- // You can send requests that use a stream resource as the body.
505
- $resource = fopen('http://httpbin.org', 'r');
506
- $client->put('/put', ['body' => $resource]);
507
-
508
- - Array
509
-
510
- Use an array to send POST style requests that use a
511
- ``GuzzleHttp\Post\PostBodyInterface`` object as the body.
512
-
513
- .. code-block:: php
514
-
515
- // You can send requests that use a POST body containing fields & files.
516
- $client->post('/post', [
517
- 'body' => [
518
- 'field' => 'abc',
519
- 'other_field' => '123',
520
- 'file_name' => fopen('/path/to/file', 'r')
521
- ]
522
- ]);
523
-
524
- - ``GuzzleHttp\Stream\StreamInterface``
525
-
526
- .. code-block:: php
527
-
528
- // You can send requests that use a Guzzle stream object as the body
529
- $stream = GuzzleHttp\Stream\Stream::factory('contents...');
530
- $client->post('/post', ['body' => $stream]);
531
-
532
- json
533
- ----
534
-
535
- :Summary: The ``json`` option is used to easily upload JSON encoded data as the
536
- body of a request. A Content-Type header of ``application/json`` will be
537
- added if no Content-Type header is already present on the message.
538
- :Types:
539
- Any PHP type that can be operated on by PHP's ``json_encode()`` function.
540
- :Default: None
541
-
542
- .. code-block:: php
543
-
544
- $request = $client->createRequest('PUT', '/put', ['json' => ['foo' => 'bar']]);
545
- echo $request->getHeader('Content-Type');
546
- // application/json
547
- echo $request->getBody();
548
- // {"foo":"bar"}
549
-
550
- .. note::
551
-
552
- This request option does not support customizing the Content-Type header
553
- or any of the options from PHP's `json_encode() <http://www.php.net/manual/en/function.json-encode.php>`_
554
- function. If you need to customize these settings, then you must pass the
555
- JSON encoded data into the request yourself using the ``body`` request
556
- option and you must specify the correct Content-Type header using the
557
- ``headers`` request option.
558
-
559
- query
560
- -----
561
-
562
- :Summary: Associative array of query string values to add to the request.
563
- :Types:
564
- - array
565
- - ``GuzzleHttp\Query``
566
- :Default: None
567
-
568
- .. code-block:: php
569
-
570
- // Send a GET request to /get?foo=bar
571
- $client->get('/get', ['query' => ['foo' => 'bar']]);
572
-
573
- Query strings specified in the ``query`` option are combined with any query
574
- string values that are parsed from the URL.
575
-
576
- .. code-block:: php
577
-
578
- // Send a GET request to /get?abc=123&foo=bar
579
- $client->get('/get?abc=123', ['query' => ['foo' => 'bar']]);
580
-
581
- auth
582
- ----
583
-
584
- :Summary: Pass an array of HTTP authentication parameters to use with the
585
- request. The array must contain the username in index [0], the password in
586
- index [1], and you can optionally provide a built-in authentication type in
587
- index [2]. Pass ``null`` to disable authentication for a request.
588
- :Types:
589
- - array
590
- - string
591
- - null
592
- :Default: None
593
-
594
- The built-in authentication types are as follows:
595
-
596
- basic
597
- Use `basic HTTP authentication <http://www.ietf.org/rfc/rfc2069.txt>`_ in
598
- the ``Authorization`` header (the default setting used if none is
599
- specified).
600
-
601
- .. code-block:: php
602
-
603
- $client->get('/get', ['auth' => ['username', 'password']]);
604
-
605
- digest
606
- Use `digest authentication <http://www.ietf.org/rfc/rfc2069.txt>`_ (must be
607
- supported by the HTTP handler).
608
-
609
- .. code-block:: php
610
-
611
- $client->get('/get', ['auth' => ['username', 'password', 'digest']]);
612
-
613
- *This is currently only supported when using the cURL handler, but creating
614
- a replacement that can be used with any HTTP handler is planned.*
615
-
616
- .. important::
617
-
618
- The authentication type (whether it's provided as a string or as the third
619
- option in an array) is always converted to a lowercase string. Take this
620
- into account when implementing custom authentication types and when
621
- implementing custom message factories.
622
-
623
- Custom Authentication Schemes
624
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
625
-
626
- You can also provide a string representing a custom authentication type name.
627
- When using a custom authentication type string, you will need to implement
628
- the authentication method in an event listener that checks the ``auth`` request
629
- option of a request before it is sent. Authentication listeners that require
630
- a request is not modified after they are signed should have a very low priority
631
- to ensure that they are fired last or near last in the event chain.
632
-
633
- .. code-block:: php
634
-
635
- use GuzzleHttp\Event\BeforeEvent;
636
- use GuzzleHttp\Event\RequestEvents;
637
-
638
- /**
639
- * Custom authentication listener that handles the "foo" auth type.
640
- *
641
- * Listens to the "before" event of a request and only modifies the request
642
- * when the "auth" config setting of the request is "foo".
643
- */
644
- class FooAuth implements GuzzleHttp\Event\SubscriberInterface
645
- {
646
- private $password;
647
-
648
- public function __construct($password)
649
- {
650
- $this->password = $password;
651
- }
652
-
653
- public function getEvents()
654
- {
655
- return ['before' => ['sign', RequestEvents::SIGN_REQUEST]];
656
- }
657
-
658
- public function sign(BeforeEvent $e)
659
- {
660
- if ($e->getRequest()->getConfig()['auth'] == 'foo') {
661
- $e->getRequest()->setHeader('X-Foo', 'Foo ' . $this->password);
662
- }
663
- }
664
- }
665
-
666
- $client->getEmitter()->attach(new FooAuth('password'));
667
- $client->get('/', ['auth' => 'foo']);
668
-
669
- Adapter Specific Authentication Schemes
670
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
671
-
672
- If you need to use authentication methods provided by cURL (e.g., NTLM, GSS,
673
- etc.), then you need to specify a curl handler option in the ``options``
674
- request option array. See :ref:`config-option` for more information.
675
-
676
- .. _cookies-option:
677
-
678
- cookies
679
- -------
680
-
681
- :Summary: Specifies whether or not cookies are used in a request or what cookie
682
- jar to use or what cookies to send.
683
- :Types:
684
- - bool
685
- - array
686
- - ``GuzzleHttp\Cookie\CookieJarInterface``
687
- :Default: None
688
-
689
- Set to ``true`` to use a shared cookie session associated with the client.
690
-
691
- .. code-block:: php
692
-
693
- // Enable cookies using the shared cookie jar of the client.
694
- $client->get('/get', ['cookies' => true]);
695
-
696
- Pass an associative array containing cookies to send in the request and start a
697
- new cookie session.
698
-
699
- .. code-block:: php
700
-
701
- // Enable cookies and send specific cookies
702
- $client->get('/get', ['cookies' => ['foo' => 'bar']]);
703
-
704
- Set to a ``GuzzleHttp\Cookie\CookieJarInterface`` object to use an existing
705
- cookie jar.
706
-
707
- .. code-block:: php
708
-
709
- $jar = new GuzzleHttp\Cookie\CookieJar();
710
- $client->get('/get', ['cookies' => $jar]);
711
-
712
- .. _allow_redirects-option:
713
-
714
- allow_redirects
715
- ---------------
716
-
717
- :Summary: Describes the redirect behavior of a request
718
- :Types:
719
- - bool
720
- - array
721
- :Default:
722
- ::
723
-
724
- [
725
- 'max' => 5,
726
- 'strict' => false,
727
- 'referer' => true,
728
- 'protocols' => ['http', 'https']
729
- ]
730
-
731
- Set to ``false`` to disable redirects.
732
-
733
- .. code-block:: php
734
-
735
- $res = $client->get('/redirect/3', ['allow_redirects' => false]);
736
- echo $res->getStatusCode();
737
- // 302
738
-
739
- Set to ``true`` (the default setting) to enable normal redirects with a maximum
740
- number of 5 redirects.
741
-
742
- .. code-block:: php
743
-
744
- $res = $client->get('/redirect/3');
745
- echo $res->getStatusCode();
746
- // 200
747
-
748
- Pass an associative array containing the 'max' key to specify the maximum
749
- number of redirects, provide a 'strict' key value to specify whether or not to
750
- use strict RFC compliant redirects (meaning redirect POST requests with POST
751
- requests vs. doing what most browsers do which is redirect POST requests with
752
- GET requests), provide a 'referer' key to specify whether or not the "Referer"
753
- header should be added when redirecting, and provide a 'protocols' array that
754
- specifies which protocols are supported for redirects (defaults to
755
- ``['http', 'https']``).
756
-
757
- .. code-block:: php
758
-
759
- $res = $client->get('/redirect/3', [
760
- 'allow_redirects' => [
761
- 'max' => 10, // allow at most 10 redirects.
762
- 'strict' => true, // use "strict" RFC compliant redirects.
763
- 'referer' => true, // add a Referer header
764
- 'protocols' => ['https'] // only allow https URLs
765
- ]
766
- ]);
767
- echo $res->getStatusCode();
768
- // 200
769
-
770
- decode_content
771
- --------------
772
-
773
- :Summary: Specify whether or not ``Content-Encoding`` responses (gzip,
774
- deflate, etc.) are automatically decoded.
775
- :Types:
776
- - string
777
- - bool
778
- :Default: ``true``
779
-
780
- This option can be used to control how content-encoded response bodies are
781
- handled. By default, ``decode_content`` is set to true, meaning any gzipped
782
- or deflated response will be decoded by Guzzle.
783
-
784
- When set to ``false``, the body of a response is never decoded, meaning the
785
- bytes pass through the handler unchanged.
786
-
787
- .. code-block:: php
788
-
789
- // Request gzipped data, but do not decode it while downloading
790
- $client->get('/foo.js', [
791
- 'headers' => ['Accept-Encoding' => 'gzip'],
792
- 'decode_content' => false
793
- ]);
794
-
795
- When set to a string, the bytes of a response are decoded and the string value
796
- provided to the ``decode_content`` option is passed as the ``Accept-Encoding``
797
- header of the request.
798
-
799
- .. code-block:: php
800
-
801
- // Pass "gzip" as the Accept-Encoding header.
802
- $client->get('/foo.js', ['decode_content' => 'gzip']);
803
-
804
- .. _save_to-option:
805
-
806
- save_to
807
- -------
808
-
809
- :Summary: Specify where the body of a response will be saved.
810
- :Types:
811
- - string
812
- - ``fopen()`` resource
813
- - ``GuzzleHttp\Stream\StreamInterface``
814
- :Default: PHP temp stream
815
-
816
- Pass a string to specify the path to a file that will store the contents of the
817
- response body:
818
-
819
- .. code-block:: php
820
-
821
- $client->get('/stream/20', ['save_to' => '/path/to/file']);
822
-
823
- Pass a resource returned from ``fopen()`` to write the response to a PHP stream:
824
-
825
- .. code-block:: php
826
-
827
- $resource = fopen('/path/to/file', 'w');
828
- $client->get('/stream/20', ['save_to' => $resource]);
829
-
830
- Pass a ``GuzzleHttp\Stream\StreamInterface`` object to stream the response body
831
- to an open Guzzle stream:
832
-
833
- .. code-block:: php
834
-
835
- $resource = fopen('/path/to/file', 'w');
836
- $stream = GuzzleHttp\Stream\Stream::factory($resource);
837
- $client->get('/stream/20', ['save_to' => $stream]);
838
-
839
- .. _events-option:
840
-
841
- events
842
- ------
843
-
844
- :Summary: An associative array mapping event names to a callable. Or an
845
- associative array containing the 'fn' key that maps to a callable, an
846
- optional 'priority' key used to specify the event priority, and an optional
847
- 'once' key used to specify if the event should remove itself the first time
848
- it is triggered.
849
- :Types: array
850
- :Default: None
851
-
852
- .. code-block:: php
853
-
854
- use GuzzleHttp\Event\BeforeEvent;
855
- use GuzzleHttp\Event\HeadersEvent;
856
- use GuzzleHttp\Event\CompleteEvent;
857
- use GuzzleHttp\Event\ErrorEvent;
858
-
859
- $client->get('/', [
860
- 'events' => [
861
- 'before' => function (BeforeEvent $e) { echo 'Before'; },
862
- 'complete' => function (CompleteEvent $e) { echo 'Complete'; },
863
- 'error' => function (ErrorEvent $e) { echo 'Error'; },
864
- ]
865
- ]);
866
-
867
- Here's an example of using the associative array format for control over the
868
- priority and whether or not an event should be triggered more than once.
869
-
870
- .. code-block:: php
871
-
872
- $client->get('/', [
873
- 'events' => [
874
- 'before' => [
875
- 'fn' => function (BeforeEvent $e) { echo 'Before'; },
876
- 'priority' => 100,
877
- 'once' => true
878
- ]
879
- ]
880
- ]);
881
-
882
- .. _subscribers-option:
883
-
884
- subscribers
885
- -----------
886
-
887
- :Summary: Array of event subscribers to add to the request. Each value in the
888
- array must be an instance of ``GuzzleHttp\Event\SubscriberInterface``.
889
- :Types: array
890
- :Default: None
891
-
892
- .. code-block:: php
893
-
894
- use GuzzleHttp\Subscriber\History;
895
- use GuzzleHttp\Subscriber\Mock;
896
- use GuzzleHttp\Message\Response;
897
-
898
- $history = new History();
899
- $mock = new Mock([new Response(200)]);
900
- $client->get('/', ['subscribers' => [$history, $mock]]);
901
-
902
- echo $history;
903
- // Outputs the request and response history
904
-
905
- .. _exceptions-option:
906
-
907
- exceptions
908
- ----------
909
-
910
- :Summary: Set to ``false`` to disable throwing exceptions on an HTTP protocol
911
- errors (i.e., 4xx and 5xx responses). Exceptions are thrown by default when
912
- HTTP protocol errors are encountered.
913
- :Types: bool
914
- :Default: ``true``
915
-
916
- .. code-block:: php
917
-
918
- $client->get('/status/500');
919
- // Throws a GuzzleHttp\Exception\ServerException
920
-
921
- $res = $client->get('/status/500', ['exceptions' => false]);
922
- echo $res->getStatusCode();
923
- // 500
924
-
925
- .. _timeout-option:
926
-
927
- timeout
928
- -------
929
-
930
- :Summary: Float describing the timeout of the request in seconds. Use ``0``
931
- to wait indefinitely (the default behavior).
932
- :Types: float
933
- :Default: ``0``
934
-
935
- .. code-block:: php
936
-
937
- // Timeout if a server does not return a response in 3.14 seconds.
938
- $client->get('/delay/5', ['timeout' => 3.14]);
939
- // PHP Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException'
940
-
941
- .. _connect_timeout-option:
942
-
943
- connect_timeout
944
- ---------------
945
-
946
- :Summary: Float describing the number of seconds to wait while trying to connect
947
- to a server. Use ``0`` to wait indefinitely (the default behavior).
948
- :Types: float
949
- :Default: ``0``
950
-
951
- .. code-block:: php
952
-
953
- // Timeout if the client fails to connect to the server in 3.14 seconds.
954
- $client->get('/delay/5', ['connect_timeout' => 3.14]);
955
-
956
- .. note::
957
-
958
- This setting must be supported by the HTTP handler used to send a request.
959
- ``connect_timeout`` is currently only supported by the built-in cURL
960
- handler.
961
-
962
- .. _verify-option:
963
-
964
- verify
965
- ------
966
-
967
- :Summary: Describes the SSL certificate verification behavior of a request.
968
-
969
- - Set to ``true`` to enable SSL certificate verification and use the default
970
- CA bundle provided by operating system.
971
- - Set to ``false`` to disable certificate verification (this is insecure!).
972
- - Set to a string to provide the path to a CA bundle to enable verification
973
- using a custom certificate.
974
- :Types:
975
- - bool
976
- - string
977
- :Default: ``true``
978
-
979
- .. code-block:: php
980
-
981
- // Use the system's CA bundle (this is the default setting)
982
- $client->get('/', ['verify' => true]);
983
-
984
- // Use a custom SSL certificate on disk.
985
- $client->get('/', ['verify' => '/path/to/cert.pem']);
986
-
987
- // Disable validation entirely (don't do this!).
988
- $client->get('/', ['verify' => false]);
989
-
990
- Not all system's have a known CA bundle on disk. For example, Windows and
991
- OS X do not have a single common location for CA bundles. When setting
992
- "verify" to ``true``, Guzzle will do its best to find the most appropriate
993
- CA bundle on your system. When using cURL or the PHP stream wrapper on PHP
994
- versions >= 5.6, this happens by default. When using the PHP stream
995
- wrapper on versions < 5.6, Guzzle tries to find your CA bundle in the
996
- following order:
997
-
998
- 1. Check if ``openssl.cafile`` is set in your php.ini file.
999
- 2. Check if ``curl.cainfo`` is set in your php.ini file.
1000
- 3. Check if ``/etc/pki/tls/certs/ca-bundle.crt`` exists (Red Hat, CentOS,
1001
- Fedora; provided by the ca-certificates package)
1002
- 4. Check if ``/etc/ssl/certs/ca-certificates.crt`` exists (Ubuntu, Debian;
1003
- provided by the ca-certificates package)
1004
- 5. Check if ``/usr/local/share/certs/ca-root-nss.crt`` exists (FreeBSD;
1005
- provided by the ca_root_nss package)
1006
- 6. Check if ``/usr/local/etc/openssl/cert.pem`` (OS X; provided by homebrew)
1007
- 7. Check if ``C:\windows\system32\curl-ca-bundle.crt`` exists (Windows)
1008
- 8. Check if ``C:\windows\curl-ca-bundle.crt`` exists (Windows)
1009
-
1010
- The result of this lookup is cached in memory so that subsequent calls
1011
- in the same process will return very quickly. However, when sending only
1012
- a single request per-process in something like Apache, you should consider
1013
- setting the ``openssl.cafile`` environment variable to the path on disk
1014
- to the file so that this entire process is skipped.
1015
-
1016
- If you do not need a specific certificate bundle, then Mozilla provides a
1017
- commonly used CA bundle which can be downloaded
1018
- `here <https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt>`_
1019
- (provided by the maintainer of cURL). Once you have a CA bundle available on
1020
- disk, you can set the "openssl.cafile" PHP ini setting to point to the path to
1021
- the file, allowing you to omit the "verify" request option. Much more detail on
1022
- SSL certificates can be found on the
1023
- `cURL website <http://curl.haxx.se/docs/sslcerts.html>`_.
1024
-
1025
- .. _cert-option:
1026
-
1027
- cert
1028
- ----
1029
-
1030
- :Summary: Set to a string to specify the path to a file containing a PEM
1031
- formatted client side certificate. If a password is required, then set to
1032
- an array containing the path to the PEM file in the first array element
1033
- followed by the password required for the certificate in the second array
1034
- element.
1035
- :Types:
1036
- - string
1037
- - array
1038
- :Default: None
1039
-
1040
- .. code-block:: php
1041
-
1042
- $client->get('/', ['cert' => ['/path/server.pem', 'password']]);
1043
-
1044
- .. _ssl_key-option:
1045
-
1046
- ssl_key
1047
- -------
1048
-
1049
- :Summary: Specify the path to a file containing a private SSL key in PEM
1050
- format. If a password is required, then set to an array containing the path
1051
- to the SSL key in the first array element followed by the password required
1052
- for the certificate in the second element.
1053
- :Types:
1054
- - string
1055
- - array
1056
- :Default: None
1057
-
1058
- .. note::
1059
-
1060
- ``ssl_key`` is implemented by HTTP handlers. This is currently only
1061
- supported by the cURL handler, but might be supported by other third-part
1062
- handlers.
1063
-
1064
- .. _proxy-option:
1065
-
1066
- proxy
1067
- -----
1068
-
1069
- :Summary: Pass a string to specify an HTTP proxy, or an array to specify
1070
- different proxies for different protocols.
1071
- :Types:
1072
- - string
1073
- - array
1074
- :Default: None
1075
-
1076
- Pass a string to specify a proxy for all protocols.
1077
-
1078
- .. code-block:: php
1079
-
1080
- $client->get('/', ['proxy' => 'tcp://localhost:8125']);
1081
-
1082
- Pass an associative array to specify HTTP proxies for specific URI schemes
1083
- (i.e., "http", "https").
1084
-
1085
- .. code-block:: php
1086
-
1087
- $client->get('/', [
1088
- 'proxy' => [
1089
- 'http' => 'tcp://localhost:8125', // Use this proxy with "http"
1090
- 'https' => 'tcp://localhost:9124' // Use this proxy with "https"
1091
- ]
1092
- ]);
1093
-
1094
- .. note::
1095
-
1096
- You can provide proxy URLs that contain a scheme, username, and password.
1097
- For example, ``"http://username:password@192.168.16.1:10"``.
1098
-
1099
- .. _debug-option:
1100
-
1101
- debug
1102
- -----
1103
-
1104
- :Summary: Set to ``true`` or set to a PHP stream returned by ``fopen()`` to
1105
- enable debug output with the handler used to send a request. For example,
1106
- when using cURL to transfer requests, cURL's verbose of ``CURLOPT_VERBOSE``
1107
- will be emitted. When using the PHP stream wrapper, stream wrapper
1108
- notifications will be emitted. If set to true, the output is written to
1109
- PHP's STDOUT. If a PHP stream is provided, output is written to the stream.
1110
- :Types:
1111
- - bool
1112
- - ``fopen()`` resource
1113
- :Default: None
1114
-
1115
- .. code-block:: php
1116
-
1117
- $client->get('/get', ['debug' => true]);
1118
-
1119
- Running the above example would output something like the following:
1120
-
1121
- ::
1122
-
1123
- * About to connect() to httpbin.org port 80 (#0)
1124
- * Trying 107.21.213.98... * Connected to httpbin.org (107.21.213.98) port 80 (#0)
1125
- > GET /get HTTP/1.1
1126
- Host: httpbin.org
1127
- User-Agent: Guzzle/4.0 curl/7.21.4 PHP/5.5.7
1128
-
1129
- < HTTP/1.1 200 OK
1130
- < Access-Control-Allow-Origin: *
1131
- < Content-Type: application/json
1132
- < Date: Sun, 16 Feb 2014 06:50:09 GMT
1133
- < Server: gunicorn/0.17.4
1134
- < Content-Length: 335
1135
- < Connection: keep-alive
1136
- <
1137
- * Connection #0 to host httpbin.org left intact
1138
-
1139
- .. _stream-option:
1140
-
1141
- stream
1142
- ------
1143
-
1144
- :Summary: Set to ``true`` to stream a response rather than download it all
1145
- up-front.
1146
- :Types: bool
1147
- :Default: ``false``
1148
-
1149
- .. code-block:: php
1150
-
1151
- $response = $client->get('/stream/20', ['stream' => true]);
1152
- // Read bytes off of the stream until the end of the stream is reached
1153
- $body = $response->getBody();
1154
- while (!$body->eof()) {
1155
- echo $body->read(1024);
1156
- }
1157
-
1158
- .. note::
1159
-
1160
- Streaming response support must be implemented by the HTTP handler used by
1161
- a client. This option might not be supported by every HTTP handler, but the
1162
- interface of the response object remains the same regardless of whether or
1163
- not it is supported by the handler.
1164
-
1165
- .. _expect-option:
1166
-
1167
- expect
1168
- ------
1169
-
1170
- :Summary: Controls the behavior of the "Expect: 100-Continue" header.
1171
- :Types:
1172
- - bool
1173
- - integer
1174
- :Default: ``1048576``
1175
-
1176
- Set to ``true`` to enable the "Expect: 100-Continue" header for all requests
1177
- that sends a body. Set to ``false`` to disable the "Expect: 100-Continue"
1178
- header for all requests. Set to a number so that the size of the payload must
1179
- be greater than the number in order to send the Expect header. Setting to a
1180
- number will send the Expect header for all requests in which the size of the
1181
- payload cannot be determined or where the body is not rewindable.
1182
-
1183
- By default, Guzzle will add the "Expect: 100-Continue" header when the size of
1184
- the body of a request is greater than 1 MB and a request is using HTTP/1.1.
1185
-
1186
- .. note::
1187
-
1188
- This option only takes effect when using HTTP/1.1. The HTTP/1.0 and
1189
- HTTP/2.0 protocols do not support the "Expect: 100-Continue" header.
1190
- Support for handling the "Expect: 100-Continue" workflow must be
1191
- implemented by Guzzle HTTP handlers used by a client.
1192
-
1193
- .. _version-option:
1194
-
1195
- version
1196
- -------
1197
-
1198
- :Summary: Protocol version to use with the request.
1199
- :Types: string, float
1200
- :Default: ``1.1``
1201
-
1202
- .. code-block:: php
1203
-
1204
- // Force HTTP/1.0
1205
- $request = $client->createRequest('GET', '/get', ['version' => 1.0]);
1206
- echo $request->getProtocolVersion();
1207
- // 1.0
1208
-
1209
- .. _config-option:
1210
-
1211
- config
1212
- ------
1213
-
1214
- :Summary: Associative array of config options that are forwarded to a request's
1215
- configuration collection. These values are used as configuration options
1216
- that can be consumed by plugins and handlers.
1217
- :Types: array
1218
- :Default: None
1219
-
1220
- .. code-block:: php
1221
-
1222
- $request = $client->createRequest('GET', '/get', ['config' => ['foo' => 'bar']]);
1223
- echo $request->getConfig('foo');
1224
- // 'bar'
1225
-
1226
- Some HTTP handlers allow you to specify custom handler-specific settings. For
1227
- example, you can pass custom cURL options to requests by passing an associative
1228
- array in the ``config`` request option under the ``curl`` key.
1229
-
1230
- .. code-block:: php
1231
-
1232
- // Use custom cURL options with the request. This example uses NTLM auth
1233
- // to authenticate with a server.
1234
- $client->get('/', [
1235
- 'config' => [
1236
- 'curl' => [
1237
- CURLOPT_HTTPAUTH => CURLAUTH_NTLM,
1238
- CURLOPT_USERPWD => 'username:password'
1239
- ]
1240
- ]
1241
- ]);
1242
-
1243
- future
1244
- ------
1245
-
1246
- :Summary: Specifies whether or not a response SHOULD be an instance of a
1247
- ``GuzzleHttp\Message\FutureResponse`` object.
1248
- :Types:
1249
- - bool
1250
- - string
1251
- :Default: ``false``
1252
-
1253
- By default, Guzzle requests should be synchronous. You can create asynchronous
1254
- future responses by passing the ``future`` request option as ``true``. The
1255
- response will only be executed when it is used like a normal response, the
1256
- ``wait()`` method of the response is called, or the corresponding handler that
1257
- created the response is destructing and there are futures that have not been
1258
- resolved.
1259
-
1260
- .. important::
1261
-
1262
- This option only has an effect if your handler can create and return future
1263
- responses. However, even if a response is completed synchronously, Guzzle
1264
- will ensure that a FutureResponse object is returned for API consistency.
1265
-
1266
- .. code-block:: php
1267
-
1268
- $response = $client->get('/foo', ['future' => true])
1269
- ->then(function ($response) {
1270
- echo 'I got a response! ' . $response;
1271
- });
1272
-
1273
- Event Subscribers
1274
- =================
1275
-
1276
- Requests emit lifecycle events when they are transferred. A client object has a
1277
- ``GuzzleHttp\Common\EventEmitter`` object that can be used to add event
1278
- *listeners* and event *subscribers* to all requests created by the client.
1279
-
1280
- .. important::
1281
-
1282
- **Every** event listener or subscriber added to a client will be added to
1283
- every request created by the client.
1284
-
1285
- .. code-block:: php
1286
-
1287
- use GuzzleHttp\Client;
1288
- use GuzzleHttp\Event\BeforeEvent;
1289
-
1290
- $client = new Client();
1291
-
1292
- // Add a listener that will echo out requests before they are sent
1293
- $client->getEmitter()->on('before', function (BeforeEvent $e) {
1294
- echo 'About to send request: ' . $e->getRequest();
1295
- });
1296
-
1297
- $client->get('http://httpbin.org/get');
1298
- // Outputs the request as a string because of the event
1299
-
1300
- See :doc:`events` for more information on the event system used in Guzzle.
1301
-
1302
- Environment Variables
1303
- =====================
1304
-
1305
- Guzzle exposes a few environment variables that can be used to customize the
1306
- behavior of the library.
1307
-
1308
- ``GUZZLE_CURL_SELECT_TIMEOUT``
1309
- Controls the duration in seconds that a curl_multi_* handler will use when
1310
- selecting on curl handles using ``curl_multi_select()``. Some systems
1311
- have issues with PHP's implementation of ``curl_multi_select()`` where
1312
- calling this function always results in waiting for the maximum duration of
1313
- the timeout.
1314
- ``HTTP_PROXY``
1315
- Defines the proxy to use when sending requests using the "http" protocol.
1316
- ``HTTPS_PROXY``
1317
- Defines the proxy to use when sending requests using the "https" protocol.
1318
-
1319
- Relevant ini Settings
1320
- ---------------------
1321
-
1322
- Guzzle can utilize PHP ini settings when configuring clients.
1323
-
1324
- ``openssl.cafile``
1325
- Specifies the path on disk to a CA file in PEM format to use when sending
1326
- requests over "https". See: https://wiki.php.net/rfc/tls-peer-verification#phpini_defaults
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/docs/conf.py DELETED
@@ -1,28 +0,0 @@
1
- import sys, os
2
- from sphinx.highlighting import lexers
3
- from pygments.lexers.web import PhpLexer
4
-
5
-
6
- lexers['php'] = PhpLexer(startinline=True, linenos=1)
7
- lexers['php-annotations'] = PhpLexer(startinline=True, linenos=1)
8
- primary_domain = 'php'
9
-
10
- extensions = []
11
- templates_path = ['_templates']
12
- source_suffix = '.rst'
13
- master_doc = 'index'
14
- project = u'Guzzle'
15
- copyright = u'2014, Michael Dowling'
16
- version = '5.0.0'
17
- html_title = "Guzzle Documentation"
18
- html_short_title = "Guzzle"
19
-
20
- exclude_patterns = ['_build']
21
- html_static_path = ['_static']
22
-
23
- on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
24
-
25
- if not on_rtd: # only import and set the theme if we're building docs locally
26
- import sphinx_rtd_theme
27
- html_theme = 'sphinx_rtd_theme'
28
- html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/docs/events.rst DELETED
@@ -1,516 +0,0 @@
1
- ============
2
- Event System
3
- ============
4
-
5
- Guzzle uses an event emitter to allow you to easily extend the behavior of a
6
- request, change the response associated with a request, and implement custom
7
- error handling. All events in Guzzle are managed and emitted by an
8
- **event emitter**.
9
-
10
- Event Emitters
11
- ==============
12
-
13
- Clients, requests, and any other class that implements the
14
- ``GuzzleHttp\Event\HasEmitterInterface`` interface have a
15
- ``GuzzleHttp\Event\Emitter`` object. You can add event *listeners* and
16
- event *subscribers* to an event *emitter*.
17
-
18
- emitter
19
- An object that implements ``GuzzleHttp\Event\EmitterInterface``. This
20
- object emits named events to event listeners. You may register event
21
- listeners on subscribers on an emitter.
22
-
23
- event listeners
24
- Callable functions that are registered on an event emitter for specific
25
- events. Event listeners are registered on an emitter with a *priority*
26
- setting. If no priority is provided, ``0`` is used by default.
27
-
28
- event subscribers
29
- Classes that tell an event emitter what methods to listen to and what
30
- functions on the class to invoke when the event is triggered. Event
31
- subscribers subscribe event listeners to an event emitter. They should be
32
- used when creating more complex event based logic in applications (i.e.,
33
- cookie handling is implemented using an event subscriber because it's
34
- easier to share a subscriber than an anonymous function and because
35
- handling cookies is a complex process).
36
-
37
- priority
38
- Describes the order in which event listeners are invoked when an event is
39
- emitted. The higher a priority value, the earlier the event listener will
40
- be invoked (a higher priority means the listener is more important). If
41
- no priority is provided, the priority is assumed to be ``0``.
42
-
43
- When specifying an event priority, you can pass ``"first"`` or ``"last"`` to
44
- dynamically specify the priority based on the current event priorities
45
- associated with the given event name in the emitter. Use ``"first"`` to set
46
- the priority to the current highest priority plus one. Use ``"last"`` to
47
- set the priority to the current lowest event priority minus one. It is
48
- important to remember that these dynamic priorities are calculated only at
49
- the point of insertion into the emitter and they are not rearranged after
50
- subsequent listeners are added to an emitter.
51
-
52
- propagation
53
- Describes whether or not other event listeners are triggered. Event
54
- emitters will trigger every event listener registered to a specific event
55
- in priority order until all of the listeners have been triggered **or**
56
- until the propagation of an event is stopped.
57
-
58
- Getting an EventEmitter
59
- -----------------------
60
-
61
- You can get the event emitter of ``GuzzleHttp\Event\HasEmitterInterface``
62
- object using the the ``getEmitter()`` method. Here's an example of getting a
63
- client object's event emitter.
64
-
65
- .. code-block:: php
66
-
67
- $client = new GuzzleHttp\Client();
68
- $emitter = $client->getEmitter();
69
-
70
- .. note::
71
-
72
- You'll notice that the event emitter used in Guzzle is very similar to the
73
- `Symfony2 EventDispatcher component <https://github.com/symfony/symfony/tree/master/src/Symfony/Component/EventDispatcher>`_.
74
- This is because the Guzzle event system is based on the Symfony2 event
75
- system with several changes. Guzzle uses its own event emitter to improve
76
- performance, isolate Guzzle from changes to the Symfony, and provide a few
77
- improvements that make it easier to use for an HTTP client (e.g., the
78
- addition of the ``once()`` method).
79
-
80
- Adding Event Listeners
81
- ----------------------
82
-
83
- After you have the emitter, you can register event listeners that listen to
84
- specific events using the ``on()`` method. When registering an event listener,
85
- you must tell the emitter what event to listen to (e.g., "before", "after",
86
- "progress", "complete", "error", etc.), what callable to invoke when the
87
- event is triggered, and optionally provide a priority.
88
-
89
- .. code-block:: php
90
-
91
- use GuzzleHttp\Event\BeforeEvent;
92
-
93
- $emitter->on('before', function (BeforeEvent $event) {
94
- echo $event->getRequest();
95
- });
96
-
97
- When a listener is triggered, it is passed an event that implements the
98
- ``GuzzleHttp\Event\EventInterface`` interface, the name of the event, and the
99
- event emitter itself. The above example could more verbosely be written as
100
- follows:
101
-
102
- .. code-block:: php
103
-
104
- use GuzzleHttp\Event\BeforeEvent;
105
-
106
- $emitter->on('before', function (BeforeEvent $event, $name) {
107
- echo $event->getRequest();
108
- });
109
-
110
- You can add an event listener that automatically removes itself after it is
111
- triggered using the ``once()`` method of an event emitter.
112
-
113
- .. code-block:: php
114
-
115
- $client = new GuzzleHttp\Client();
116
- $client->getEmitter()->once('before', function () {
117
- echo 'This will only happen once... per request!';
118
- });
119
-
120
- Event Propagation
121
- -----------------
122
-
123
- Event listeners can prevent other event listeners from being triggered by
124
- stopping an event's propagation.
125
-
126
- Stopping event propagation can be useful, for example, if an event listener has
127
- changed the state of the subject to such an extent that allowing subsequent
128
- event listeners to be triggered could place the subject in an inconsistent
129
- state. This technique is used in Guzzle extensively when intercepting error
130
- events with responses.
131
-
132
- You can stop the propagation of an event using the ``stopPropagation()`` method
133
- of a ``GuzzleHttp\Event\EventInterface`` object:
134
-
135
- .. code-block:: php
136
-
137
- use GuzzleHttp\Event\ErrorEvent;
138
-
139
- $emitter->on('error', function (ErrorEvent $event) {
140
- $event->stopPropagation();
141
- });
142
-
143
- After stopping the propagation of an event, any subsequent event listeners that
144
- have not yet been triggered will not be triggered. You can check to see if the
145
- propagation of an event was stopped using the ``isPropagationStopped()`` method
146
- of the event.
147
-
148
- .. code-block:: php
149
-
150
- $client = new GuzzleHttp\Client();
151
- $emitter = $client->getEmitter();
152
- // Note: assume that the $errorEvent was created
153
- if ($emitter->emit('error', $errorEvent)->isPropagationStopped()) {
154
- echo 'It was stopped!';
155
- }
156
-
157
- .. hint::
158
-
159
- When emitting events, the event that was emitted is returned from the
160
- emitter. This allows you to easily chain calls as shown in the above
161
- example.
162
-
163
- Event Subscribers
164
- -----------------
165
-
166
- Event subscribers are classes that implement the
167
- ``GuzzleHttp\Event\SubscriberInterface`` object. They are used to register
168
- one or more event listeners to methods of the class. Event subscribers tell
169
- event emitters exactly which events to listen to and what method to invoke on
170
- the class when the event is triggered by called the ``getEvents()`` method of
171
- a subscriber.
172
-
173
- The following example registers event listeners to the ``before`` and
174
- ``complete`` event of a request. When the ``before`` event is emitted, the
175
- ``onBefore`` instance method of the subscriber is invoked. When the
176
- ``complete`` event is emitted, the ``onComplete`` event of the subscriber is
177
- invoked. Each array value in the ``getEvents()`` return value MUST
178
- contain the name of the method to invoke and can optionally contain the
179
- priority of the listener (as shown in the ``before`` listener in the example).
180
-
181
- .. code-block:: php
182
-
183
- use GuzzleHttp\Event\EmitterInterface;
184
- use GuzzleHttp\Event\SubscriberInterface;
185
- use GuzzleHttp\Event\BeforeEvent;
186
- use GuzzleHttp\Event\CompleteEvent;
187
-
188
- class SimpleSubscriber implements SubscriberInterface
189
- {
190
- public function getEvents()
191
- {
192
- return [
193
- // Provide name and optional priority
194
- 'before' => ['onBefore', 100],
195
- 'complete' => ['onComplete'],
196
- // You can pass a list of listeners with different priorities
197
- 'error' => [['beforeError', 'first'], ['afterError', 'last']]
198
- ];
199
- }
200
-
201
- public function onBefore(BeforeEvent $event, $name)
202
- {
203
- echo 'Before!';
204
- }
205
-
206
- public function onComplete(CompleteEvent $event, $name)
207
- {
208
- echo 'Complete!';
209
- }
210
- }
211
-
212
- To register the listeners the subscriber needs to be attached to the emitter:
213
-
214
- .. code-block:: php
215
-
216
- $client = new GuzzleHttp\Client();
217
- $emitter = $client->getEmitter();
218
- $subscriber = new SimpleSubscriber();
219
- $emitter->attach($subscriber);
220
-
221
- //to remove the listeners
222
- $emitter->detach($subscriber);
223
-
224
- .. note::
225
-
226
- You can specify event priorities using integers or ``"first"`` and
227
- ``"last"`` to dynamically determine the priority.
228
-
229
- Event Priorities
230
- ================
231
-
232
- When adding event listeners or subscribers, you can provide an optional event
233
- priority. This priority is used to determine how early or late a listener is
234
- triggered. Specifying the correct priority is an important aspect of ensuring
235
- a listener behaves as expected. For example, if you wanted to ensure that
236
- cookies associated with a redirect were added to a cookie jar, you'd need to
237
- make sure that the listener that collects the cookies is triggered before the
238
- listener that performs the redirect.
239
-
240
- In order to help make the process of determining the correct event priority of
241
- a listener easier, Guzzle provides several pre-determined named event
242
- priorities. These priorities are exposed as constants on the
243
- ``GuzzleHttp\Event\RequestEvents`` object.
244
-
245
- last
246
- Use ``"last"`` as an event priority to set the priority to the current
247
- lowest event priority minus one.
248
-
249
- first
250
- Use ``"first"`` as an event priority to set the priority to the current
251
- highest priority plus one.
252
-
253
- ``GuzzleHttp\Event\RequestEvents::EARLY``
254
- Used when you want a listener to be triggered as early as possible in the
255
- event chain.
256
-
257
- ``GuzzleHttp\Event\RequestEvents::LATE``
258
- Used when you want a listener to be to be triggered as late as possible in
259
- the event chain.
260
-
261
- ``GuzzleHttp\Event\RequestEvents::PREPARE_REQUEST``
262
- Used when you want a listener to be trigger while a request is being
263
- prepared during the ``before`` event. This event priority is used by the
264
- ``GuzzleHttp\Subscriber\Prepare`` event subscriber which is responsible for
265
- guessing a Content-Type, Content-Length, and Expect header of a request.
266
- You should subscribe after this event is triggered if you want to ensure
267
- that this subscriber has already been triggered.
268
-
269
- ``GuzzleHttp\Event\RequestEvents::SIGN_REQUEST``
270
- Used when you want a listener to be triggered when a request is about to be
271
- signed. Any listener triggered at this point should expect that the request
272
- object will no longer be mutated. If you are implementing a custom
273
- signature subscriber, then you should use this event priority to sign
274
- requests.
275
-
276
- ``GuzzleHttp\Event\RequestEvents::VERIFY_RESPONSE``
277
- Used when you want a listener to be triggered when a response is being
278
- validated during the ``complete`` event. The
279
- ``GuzzleHttp\Subscriber\HttpError`` event subscriber uses this event
280
- priority to check if an exception should be thrown due to a 4xx or 5xx
281
- level response status code. If you are doing any kind of verification of a
282
- response during the complete event, it should happen at this priority.
283
-
284
- ``GuzzleHttp\Event\RequestEvents::REDIRECT_RESPONSE``
285
- Used when you want a listener to be triggered when a response is being
286
- redirected during the ``complete`` event. The
287
- ``GuzzleHttp\Subscriber\Redirect`` event subscriber uses this event
288
- priority when performing redirects.
289
-
290
- You can use the above event priorities as a guideline for determining the
291
- priority of you event listeners. You can use these constants and add to or
292
- subtract from them to ensure that a listener happens before or after the named
293
- priority.
294
-
295
- .. note::
296
-
297
- "first" and "last" priorities are not adjusted after they added to an
298
- emitter. For example, if you add a listener with a priority of "first",
299
- you can still add subsequent listeners with a higher priority which would
300
- be triggered before the listener added with a priority of "first".
301
-
302
- Working With Request Events
303
- ===========================
304
-
305
- Requests emit lifecycle events when they are transferred.
306
-
307
- .. important::
308
-
309
- Excluding the ``end`` event, request lifecycle events may be triggered
310
- multiple times due to redirects, retries, or reusing a request multiple
311
- times. Use the ``once()`` method want the event to be triggered once. You
312
- can also remove an event listener from an emitter by using the emitter which
313
- is provided to the listener.
314
-
315
- .. _before_event:
316
-
317
- before
318
- ------
319
-
320
- The ``before`` event is emitted before a request is sent. The event emitted is
321
- a ``GuzzleHttp\Event\BeforeEvent``.
322
-
323
- .. code-block:: php
324
-
325
- use GuzzleHttp\Client;
326
- use GuzzleHttp\Event\EmitterInterface;
327
- use GuzzleHttp\Event\BeforeEvent;
328
-
329
- $client = new Client(['base_url' => 'http://httpbin.org']);
330
- $request = $client->createRequest('GET', '/');
331
- $request->getEmitter()->on(
332
- 'before',
333
- function (BeforeEvent $e, $name) {
334
- echo $name . "\n";
335
- // "before"
336
- echo $e->getRequest()->getMethod() . "\n";
337
- // "GET" / "POST" / "PUT" / etc.
338
- echo get_class($e->getClient());
339
- // "GuzzleHttp\Client"
340
- }
341
- );
342
-
343
- You can intercept a request with a response before the request is sent over the
344
- wire. The ``intercept()`` method of the ``BeforeEvent`` accepts a
345
- ``GuzzleHttp\Message\ResponseInterface``. Intercepting the event will prevent
346
- the request from being sent over the wire and stops the propagation of the
347
- ``before`` event, preventing subsequent event listeners from being invoked.
348
-
349
- .. code-block:: php
350
-
351
- use GuzzleHttp\Client;
352
- use GuzzleHttp\Event\BeforeEvent;
353
- use GuzzleHttp\Message\Response;
354
-
355
- $client = new Client(['base_url' => 'http://httpbin.org']);
356
- $request = $client->createRequest('GET', '/status/500');
357
- $request->getEmitter()->on('before', function (BeforeEvent $e) {
358
- $response = new Response(200);
359
- $e->intercept($response);
360
- });
361
-
362
- $response = $client->send($request);
363
- echo $response->getStatusCode();
364
- // 200
365
-
366
- .. attention::
367
-
368
- Any exception encountered while executing the ``before`` event will trigger
369
- the ``error`` event of a request.
370
-
371
- .. _complete_event:
372
-
373
- complete
374
- --------
375
-
376
- The ``complete`` event is emitted after a transaction completes and an entire
377
- response has been received. The event is a ``GuzzleHttp\Event\CompleteEvent``.
378
-
379
- You can intercept the ``complete`` event with a different response if needed
380
- using the ``intercept()`` method of the event. This can be useful, for example,
381
- for changing the response for caching.
382
-
383
- .. code-block:: php
384
-
385
- use GuzzleHttp\Client;
386
- use GuzzleHttp\Event\CompleteEvent;
387
- use GuzzleHttp\Message\Response;
388
-
389
- $client = new Client(['base_url' => 'http://httpbin.org']);
390
- $request = $client->createRequest('GET', '/status/302');
391
- $cachedResponse = new Response(200);
392
-
393
- $request->getEmitter()->on(
394
- 'complete',
395
- function (CompleteEvent $e) use ($cachedResponse) {
396
- if ($e->getResponse()->getStatusCode() == 302) {
397
- // Intercept the original transaction with the new response
398
- $e->intercept($cachedResponse);
399
- }
400
- }
401
- );
402
-
403
- $response = $client->send($request);
404
- echo $response->getStatusCode();
405
- // 200
406
-
407
- .. attention::
408
-
409
- Any ``GuzzleHttp\Exception\RequestException`` encountered while executing
410
- the ``complete`` event will trigger the ``error`` event of a request.
411
-
412
- .. _error_event:
413
-
414
- error
415
- -----
416
-
417
- The ``error`` event is emitted when a request fails (whether it's from a
418
- networking error or an HTTP protocol error). The event emitted is a
419
- ``GuzzleHttp\Event\ErrorEvent``.
420
-
421
- This event is useful for retrying failed requests. Here's an example of
422
- retrying failed basic auth requests by re-sending the original request with
423
- a username and password.
424
-
425
- .. code-block:: php
426
-
427
- use GuzzleHttp\Client;
428
- use GuzzleHttp\Event\ErrorEvent;
429
-
430
- $client = new Client(['base_url' => 'http://httpbin.org']);
431
- $request = $client->createRequest('GET', '/basic-auth/foo/bar');
432
- $request->getEmitter()->on('error', function (ErrorEvent $e) {
433
- if ($e->getResponse()->getStatusCode() == 401) {
434
- // Add authentication stuff as needed and retry the request
435
- $e->getRequest()->setHeader('Authorization', 'Basic ' . base64_encode('foo:bar'));
436
- // Get the client of the event and retry the request
437
- $newResponse = $e->getClient()->send($e->getRequest());
438
- // Intercept the original transaction with the new response
439
- $e->intercept($newResponse);
440
- }
441
- });
442
-
443
- .. attention::
444
-
445
- If an ``error`` event is intercepted with a response, then the ``complete``
446
- event of a request is triggered. If the ``complete`` event fails, then the
447
- ``error`` event is triggered once again.
448
-
449
- .. _progress_event:
450
-
451
- progress
452
- --------
453
-
454
- The ``progress`` event is emitted when data is uploaded or downloaded. The
455
- event emitted is a ``GuzzleHttp\Event\ProgressEvent``.
456
-
457
- You can access the emitted progress values using the corresponding public
458
- properties of the event object:
459
-
460
- - ``$downloadSize``: The number of bytes that will be downloaded (if known)
461
- - ``$downloaded``: The number of bytes that have been downloaded
462
- - ``$uploadSize``: The number of bytes that will be uploaded (if known)
463
- - ``$uploaded``: The number of bytes that have been uploaded
464
-
465
- This event cannot be intercepted.
466
-
467
- .. code-block:: php
468
-
469
- use GuzzleHttp\Client;
470
- use GuzzleHttp\Event\ProgressEvent;
471
-
472
- $client = new Client(['base_url' => 'http://httpbin.org']);
473
- $request = $client->createRequest('PUT', '/put', [
474
- 'body' => str_repeat('.', 100000)
475
- ]);
476
-
477
- $request->getEmitter()->on('progress', function (ProgressEvent $e) {
478
- echo 'Downloaded ' . $e->downloaded . ' of ' . $e->downloadSize . ' '
479
- . 'Uploaded ' . $e->uploaded . ' of ' . $e->uploadSize . "\r";
480
- });
481
-
482
- $client->send($request);
483
- echo "\n";
484
-
485
- .. _end_event:
486
-
487
- end
488
- ---
489
-
490
- The ``end`` event is a terminal event, emitted once per request, that provides
491
- access to the response that was received or the exception that was encountered.
492
- The event emitted is a ``GuzzleHttp\Event\EndEvent``.
493
-
494
- This event can be intercepted, but keep in mind that the ``complete`` event
495
- will not fire after intercepting this event.
496
-
497
- .. code-block:: php
498
-
499
- use GuzzleHttp\Client;
500
- use GuzzleHttp\Event\EndEvent;
501
-
502
- $client = new Client(['base_url' => 'http://httpbin.org']);
503
- $request = $client->createRequest('PUT', '/put', [
504
- 'body' => str_repeat('.', 100000)
505
- ]);
506
-
507
- $request->getEmitter()->on('end', function (EndEvent $e) {
508
- if ($e->getException()) {
509
- echo 'Error: ' . $e->getException()->getMessage();
510
- } else {
511
- echo 'Response: ' . $e->getResponse();
512
- }
513
- });
514
-
515
- $client->send($request);
516
- echo "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/docs/faq.rst DELETED
@@ -1,199 +0,0 @@
1
- ===
2
- FAQ
3
- ===
4
-
5
- Why should I use Guzzle?
6
- ========================
7
-
8
- Guzzle makes it easy to send HTTP requests and super simple to integrate with
9
- web services. Guzzle manages things like persistent connections, represents
10
- query strings as collections, makes it simple to send streaming POST requests
11
- with fields and files, and abstracts away the underlying HTTP transport layer.
12
- By providing an object oriented interface for HTTP clients, requests, responses,
13
- headers, and message bodies, Guzzle makes it so that you no longer need to fool
14
- around with cURL options, stream contexts, or sockets.
15
-
16
- **Asynchronous and Synchronous Requests**
17
-
18
- Guzzle allows you to send both asynchronous and synchronous requests using the
19
- same interface and no direct dependency on an event loop. This flexibility
20
- allows Guzzle to send an HTTP request using the most appropriate HTTP handler
21
- based on the request being sent. For example, when sending synchronous
22
- requests, Guzzle will by default send requests using cURL easy handles to
23
- ensure you're using the fastest possible method for serially transferring HTTP
24
- requests. When sending asynchronous requests, Guzzle might use cURL's multi
25
- interface or any other asynchronous handler you configure. When you request
26
- streaming data, Guzzle will by default use PHP's stream wrapper.
27
-
28
- **Streams**
29
-
30
- Request and response message bodies use :doc:`Guzzle Streams <streams>`,
31
- allowing you to stream data without needing to load it all into memory.
32
- Guzzle's stream layer provides a large suite of functionality:
33
-
34
- - You can modify streams at runtime using custom or a number of
35
- pre-made decorators.
36
- - You can emit progress events as data is read from a stream.
37
- - You can validate the integrity of a stream using a rolling hash as data is
38
- read from a stream.
39
-
40
- **Event System and Plugins**
41
-
42
- Guzzle's event system allows you to completely modify the behavior of a client
43
- or request at runtime to cater them for any API. You can send a request with a
44
- client, and the client can do things like automatically retry your request if
45
- it fails, automatically redirect, log HTTP messages that are sent over the
46
- wire, emit progress events as data is uploaded and downloaded, sign requests
47
- using OAuth 1.0, verify the integrity of messages before and after they are
48
- sent over the wire, and anything else you might need.
49
-
50
- **Testable**
51
-
52
- Another important aspect of Guzzle is that it's really
53
- :doc:`easy to test clients <testing>`. You can mock HTTP responses and when
54
- testing an handler implementation, Guzzle provides a mock node.js web server.
55
-
56
- **Ecosystem**
57
-
58
- Guzzle has a large `ecosystem of plugins <http://guzzle.readthedocs.org/en/latest/index.html#http-components>`_,
59
- including `service descriptions <https://github.com/guzzle/guzzle-services>`_
60
- which allows you to abstract web services using service descriptions. These
61
- service descriptions define how to serialize an HTTP request and how to parse
62
- an HTTP response into a more meaningful model object.
63
-
64
- - `Guzzle Command <https://github.com/guzzle/command>`_: Provides the building
65
- blocks for service description abstraction.
66
- - `Guzzle Services <https://github.com/guzzle/guzzle-services>`_: Provides an
67
- implementation of "Guzzle Command" that utilizes Guzzle's service description
68
- format.
69
-
70
- Does Guzzle require cURL?
71
- =========================
72
-
73
- No. Guzzle can use any HTTP handler to send requests. This means that Guzzle
74
- can be used with cURL, PHP's stream wrapper, sockets, and non-blocking libraries
75
- like `React <http://reactphp.org/>`_. You just need to configure a
76
- `RingPHP <http://guzzle-ring.readthedocs.org/en/latest/>`_ handler to use a
77
- different method of sending requests.
78
-
79
- .. note::
80
-
81
- Guzzle has historically only utilized cURL to send HTTP requests. cURL is
82
- an amazing HTTP client (arguably the best), and Guzzle will continue to use
83
- it by default when it is available. It is rare, but some developers don't
84
- have cURL installed on their systems or run into version specific issues.
85
- By allowing swappable HTTP handlers, Guzzle is now much more customizable
86
- and able to adapt to fit the needs of more developers.
87
-
88
- Can Guzzle send asynchronous requests?
89
- ======================================
90
-
91
- Yes. Pass the ``future`` true request option to a request to send it
92
- asynchronously. Guzzle will then return a ``GuzzleHttp\Message\FutureResponse``
93
- object that can be used synchronously by accessing the response object like a
94
- normal response, and it can be used asynchronously using a promise that is
95
- notified when the response is resolved with a real response or rejected with an
96
- exception.
97
-
98
- .. code-block:: php
99
-
100
- $request = $client->createRequest('GET', ['future' => true]);
101
- $client->send($request)->then(function ($response) {
102
- echo 'Got a response! ' . $response;
103
- });
104
-
105
- You can force an asynchronous response to complete using the ``wait()`` method
106
- of a response.
107
-
108
- .. code-block:: php
109
-
110
- $request = $client->createRequest('GET', ['future' => true]);
111
- $futureResponse = $client->send($request);
112
- $futureResponse->wait();
113
-
114
- How can I add custom cURL options?
115
- ==================================
116
-
117
- cURL offer a huge number of `customizable options <http://us1.php.net/curl_setopt>`_.
118
- While Guzzle normalizes many of these options across different handlers, there
119
- are times when you need to set custom cURL options. This can be accomplished
120
- by passing an associative array of cURL settings in the **curl** key of the
121
- **config** request option.
122
-
123
- For example, let's say you need to customize the outgoing network interface
124
- used with a client.
125
-
126
- .. code-block:: php
127
-
128
- $client->get('/', [
129
- 'config' => [
130
- 'curl' => [
131
- CURLOPT_INTERFACE => 'xxx.xxx.xxx.xxx'
132
- ]
133
- ]
134
- ]);
135
-
136
- How can I add custom stream context options?
137
- ============================================
138
-
139
- You can pass custom `stream context options <http://www.php.net/manual/en/context.php>`_
140
- using the **stream_context** key of the **config** request option. The
141
- **stream_context** array is an associative array where each key is a PHP
142
- transport, and each value is an associative array of transport options.
143
-
144
- For example, let's say you need to customize the outgoing network interface
145
- used with a client and allow self-signed certificates.
146
-
147
- .. code-block:: php
148
-
149
- $client->get('/', [
150
- 'stream' => true,
151
- 'config' => [
152
- 'stream_context' => [
153
- 'ssl' => [
154
- 'allow_self_signed' => true
155
- ],
156
- 'socket' => [
157
- 'bindto' => 'xxx.xxx.xxx.xxx'
158
- ]
159
- ]
160
- ]
161
- ]);
162
-
163
- Why am I getting an SSL verification error?
164
- ===========================================
165
-
166
- You need to specify the path on disk to the CA bundle used by Guzzle for
167
- verifying the peer certificate. See :ref:`verify-option`.
168
-
169
- What is this Maximum function nesting error?
170
- ============================================
171
-
172
- Maximum function nesting level of '100' reached, aborting
173
-
174
- You could run into this error if you have the XDebug extension installed and
175
- you execute a lot of requests in callbacks. This error message comes
176
- specifically from the XDebug extension. PHP itself does not have a function
177
- nesting limit. Change this setting in your php.ini to increase the limit::
178
-
179
- xdebug.max_nesting_level = 1000
180
-
181
- Why am I getting a 417 error response?
182
- ======================================
183
-
184
- This can occur for a number of reasons, but if you are sending PUT, POST, or
185
- PATCH requests with an ``Expect: 100-Continue`` header, a server that does not
186
- support this header will return a 417 response. You can work around this by
187
- setting the ``expect`` request option to ``false``:
188
-
189
- .. code-block:: php
190
-
191
- $client = new GuzzleHttp\Client();
192
-
193
- // Disable the expect header on a single request
194
- $response = $client->put('/', [], 'the body', [
195
- 'expect' => false
196
- ]);
197
-
198
- // Disable the expect header on all client requests
199
- $client->setDefaultOption('expect', false)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/docs/handlers.rst DELETED
@@ -1,43 +0,0 @@
1
- ================
2
- RingPHP Handlers
3
- ================
4
-
5
- Guzzle uses RingPHP handlers to send HTTP requests over the wire.
6
- RingPHP provides a low-level library that can be used to "glue" Guzzle with
7
- any transport method you choose. By default, Guzzle utilizes cURL and PHP's
8
- stream wrappers to send HTTP requests.
9
-
10
- RingPHP handlers makes it extremely simple to integrate Guzzle with any
11
- HTTP transport. For example, you could quite easily bridge Guzzle and React
12
- to use Guzzle in React's event loop.
13
-
14
- Using a handler
15
- ---------------
16
-
17
- You can change the handler used by a client using the ``handler`` option in the
18
- ``GuzzleHttp\Client`` constructor.
19
-
20
- .. code-block:: php
21
-
22
- use GuzzleHttp\Client;
23
- use GuzzleHttp\Ring\Client\MockHandler;
24
-
25
- // Create a mock handler that always returns a 200 response.
26
- $handler = new MockHandler(['status' => 200]);
27
-
28
- // Configure to client to use the mock handler.
29
- $client = new Client(['handler' => $handler]);
30
-
31
- At its core, handlers are simply PHP callables that accept a request array
32
- and return a ``GuzzleHttp\Ring\Future\FutureArrayInterface``. This future array
33
- can be used just like a normal PHP array, causing it to block, or you can use
34
- the promise interface using the ``then()`` method of the future. Guzzle hooks
35
- up to the RingPHP project using a very simple bridge class
36
- (``GuzzleHttp\RingBridge``).
37
-
38
- Creating a handler
39
- ------------------
40
-
41
- See the `RingPHP <http://ringphp.readthedocs.org>`_ project
42
- documentation for more information on creating custom handlers that can be
43
- used with Guzzle clients.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/docs/http-messages.rst DELETED
@@ -1,483 +0,0 @@
1
- =============================
2
- Request and Response Messages
3
- =============================
4
-
5
- Guzzle is an HTTP client that sends HTTP requests to a server and receives HTTP
6
- responses. Both requests and responses are referred to as messages.
7
-
8
- Headers
9
- =======
10
-
11
- Both request and response messages contain HTTP headers.
12
-
13
- Complex Headers
14
- ---------------
15
-
16
- Some headers contain additional key value pair information. For example, Link
17
- headers contain a link and several key value pairs:
18
-
19
- ::
20
-
21
- <http://foo.com>; rel="thing"; type="image/jpeg"
22
-
23
- Guzzle provides a convenience feature that can be used to parse these types of
24
- headers:
25
-
26
- .. code-block:: php
27
-
28
- use GuzzleHttp\Message\Request;
29
-
30
- $request = new Request('GET', '/', [
31
- 'Link' => '<http:/.../front.jpeg>; rel="front"; type="image/jpeg"'
32
- ]);
33
-
34
- $parsed = Request::parseHeader($request, 'Link');
35
- var_export($parsed);
36
-
37
- Will output:
38
-
39
- .. code-block:: php
40
-
41
- array (
42
- 0 =>
43
- array (
44
- 0 => '<http:/.../front.jpeg>',
45
- 'rel' => 'front',
46
- 'type' => 'image/jpeg',
47
- ),
48
- )
49
-
50
- The result contains a hash of key value pairs. Header values that have no key
51
- (i.e., the link) are indexed numerically while headers parts that form a key
52
- value pair are added as a key value pair.
53
-
54
- See :ref:`headers` for information on how the headers of a request and response
55
- can be accessed and modified.
56
-
57
- Body
58
- ====
59
-
60
- Both request and response messages can contain a body.
61
-
62
- You can check to see if a request or response has a body using the
63
- ``getBody()`` method:
64
-
65
- .. code-block:: php
66
-
67
- $response = GuzzleHttp\get('http://httpbin.org/get');
68
- if ($response->getBody()) {
69
- echo $response->getBody();
70
- // JSON string: { ... }
71
- }
72
-
73
- The body used in request and response objects is a
74
- ``GuzzleHttp\Stream\StreamInterface``. This stream is used for both uploading
75
- data and downloading data. Guzzle will, by default, store the body of a message
76
- in a stream that uses PHP temp streams. When the size of the body exceeds
77
- 2 MB, the stream will automatically switch to storing data on disk rather than
78
- in memory (protecting your application from memory exhaustion).
79
-
80
- You can change the body used in a request or response using the ``setBody()``
81
- method:
82
-
83
- .. code-block:: php
84
-
85
- use GuzzleHttp\Stream\Stream;
86
- $request = $client->createRequest('PUT', 'http://httpbin.org/put');
87
- $request->setBody(Stream::factory('foo'));
88
-
89
- The easiest way to create a body for a request is using the static
90
- ``GuzzleHttp\Stream\Stream::factory()`` method. This method accepts various
91
- inputs like strings, resources returned from ``fopen()``, and other
92
- ``GuzzleHttp\Stream\StreamInterface`` objects.
93
-
94
- The body of a request or response can be cast to a string or you can read and
95
- write bytes off of the stream as needed.
96
-
97
- .. code-block:: php
98
-
99
- use GuzzleHttp\Stream\Stream;
100
- $request = $client->createRequest('PUT', 'http://httpbin.org/put', ['body' => 'testing...']);
101
-
102
- echo $request->getBody()->read(4);
103
- // test
104
- echo $request->getBody()->read(4);
105
- // ing.
106
- echo $request->getBody()->read(1024);
107
- // ..
108
- var_export($request->eof());
109
- // true
110
-
111
- You can find out more about Guzzle stream objects in :doc:`streams`.
112
-
113
- Requests
114
- ========
115
-
116
- Requests are sent from a client to a server. Requests include the method to
117
- be applied to a resource, the identifier of the resource, and the protocol
118
- version to use.
119
-
120
- Clients are used to create request messages. More precisely, clients use
121
- a ``GuzzleHttp\Message\MessageFactoryInterface`` to create request messages.
122
- You create requests with a client using the ``createRequest()`` method.
123
-
124
- .. code-block:: php
125
-
126
- // Create a request but don't send it immediately
127
- $request = $client->createRequest('GET', 'http://httpbin.org/get');
128
-
129
- Request Methods
130
- ---------------
131
-
132
- When creating a request, you are expected to provide the HTTP method you wish
133
- to perform. You can specify any method you'd like, including a custom method
134
- that might not be part of RFC 7231 (like "MOVE").
135
-
136
- .. code-block:: php
137
-
138
- // Create a request using a completely custom HTTP method
139
- $request = $client->createRequest('MOVE', 'http://httpbin.org/move', ['exceptions' => false]);
140
-
141
- echo $request->getMethod();
142
- // MOVE
143
-
144
- $response = $client->send($request);
145
- echo $response->getStatusCode();
146
- // 405
147
-
148
- You can create and send a request using methods on a client that map to the
149
- HTTP method you wish to use.
150
-
151
- :GET: ``$client->get('http://httpbin.org/get', [/** options **/])``
152
- :POST: ``$client->post('http://httpbin.org/post', [/** options **/])``
153
- :HEAD: ``$client->head('http://httpbin.org/get', [/** options **/])``
154
- :PUT: ``$client->put('http://httpbin.org/put', [/** options **/])``
155
- :DELETE: ``$client->delete('http://httpbin.org/delete', [/** options **/])``
156
- :OPTIONS: ``$client->options('http://httpbin.org/get', [/** options **/])``
157
- :PATCH: ``$client->patch('http://httpbin.org/put', [/** options **/])``
158
-
159
- .. code-block:: php
160
-
161
- $response = $client->patch('http://httpbin.org/patch', ['body' => 'content']);
162
-
163
- Request URI
164
- -----------
165
-
166
- The resource you are requesting with an HTTP request is identified by the
167
- path of the request, the query string, and the "Host" header of the request.
168
-
169
- When creating a request, you can provide the entire resource URI as a URL.
170
-
171
- .. code-block:: php
172
-
173
- $response = $client->get('http://httbin.org/get?q=foo');
174
-
175
- Using the above code, you will send a request that uses ``httpbin.org`` as
176
- the Host header, sends the request over port 80, uses ``/get`` as the path,
177
- and sends ``?q=foo`` as the query string. All of this is parsed automatically
178
- from the provided URI.
179
-
180
- Sometimes you don't know what the entire request will be when it is created.
181
- In these cases, you can modify the request as needed before sending it using
182
- the ``createRequest()`` method of the client and methods on the request that
183
- allow you to change it.
184
-
185
- .. code-block:: php
186
-
187
- $request = $client->createRequest('GET', 'http://httbin.org');
188
-
189
- You can change the path of the request using ``setPath()``:
190
-
191
- .. code-block:: php
192
-
193
- $request->setPath('/get');
194
- echo $request->getPath();
195
- // /get
196
- echo $request->getUrl();
197
- // http://httpbin.com/get
198
-
199
- Scheme
200
- ~~~~~~
201
-
202
- The `scheme <http://tools.ietf.org/html/rfc3986#section-3.1>`_ of a request
203
- specifies the protocol to use when sending the request. When using Guzzle, the
204
- scheme can be set to "http" or "https".
205
-
206
- You can change the scheme of the request using the ``setScheme()`` method:
207
-
208
- .. code-block:: php
209
-
210
- $request = $client->createRequest('GET', 'http://httbin.org');
211
- $request->setScheme('https');
212
- echo $request->getScheme();
213
- // https
214
- echo $request->getUrl();
215
- // https://httpbin.com/get
216
-
217
- Port
218
- ~~~~
219
-
220
- No port is necessary when using the "http" or "https" schemes, but you can
221
- override the port using ``setPort()``. If you need to modify the port used with
222
- the specified scheme from the default setting, then you must use the
223
- ``setPort()`` method.
224
-
225
- .. code-block:: php
226
-
227
- $request = $client->createRequest('GET', 'http://httbin.org');
228
- $request->setPort(8080);
229
- echo $request->getPort();
230
- // 8080
231
- echo $request->getUrl();
232
- // https://httpbin.com:8080/get
233
-
234
- // Set the port back to the default value for the scheme
235
- $request->setPort(443);
236
- echo $request->getUrl();
237
- // https://httpbin.com/get
238
-
239
- Query string
240
- ~~~~~~~~~~~~
241
-
242
- You can get the query string of the request using the ``getQuery()`` method.
243
- This method returns a ``GuzzleHttp\Query`` object. A Query object can be
244
- accessed like a PHP array, iterated in a foreach statement like a PHP array,
245
- and cast to a string.
246
-
247
- .. code-block:: php
248
-
249
- $request = $client->createRequest('GET', 'http://httbin.org');
250
- $query = $request->getQuery();
251
- $query['foo'] = 'bar';
252
- $query['baz'] = 'bam';
253
- $query['bam'] = ['test' => 'abc'];
254
-
255
- echo $request->getQuery();
256
- // foo=bar&baz=bam&bam%5Btest%5D=abc
257
-
258
- echo $request->getQuery()['foo'];
259
- // bar
260
- echo $request->getQuery()->get('foo');
261
- // bar
262
- echo $request->getQuery()->get('foo');
263
- // bar
264
-
265
- var_export($request->getQuery()['bam']);
266
- // array('test' => 'abc')
267
-
268
- foreach ($query as $key => $value) {
269
- var_export($value);
270
- }
271
-
272
- echo $request->getUrl();
273
- // https://httpbin.com/get?foo=bar&baz=bam&bam%5Btest%5D=abc
274
-
275
- Query Aggregators
276
- ^^^^^^^^^^^^^^^^^
277
-
278
- Query objects can store scalar values or arrays of values. When an array of
279
- values is added to a query object, the query object uses a query aggregator to
280
- convert the complex structure into a string. Query objects will use
281
- `PHP style query strings <http://www.php.net/http_build_query>`_ when complex
282
- query string parameters are converted to a string. You can customize how
283
- complex query string parameters are aggregated using the ``setAggregator()``
284
- method of a query string object.
285
-
286
- .. code-block:: php
287
-
288
- $query->setAggregator($query::duplicateAggregator());
289
-
290
- In the above example, we've changed the query object to use the
291
- "duplicateAggregator". This aggregator will allow duplicate entries to appear
292
- in a query string rather than appending "[n]" to each value. So if you had a
293
- query string with ``['a' => ['b', 'c']]``, the duplicate aggregator would
294
- convert this to "a=b&a=c" while the default aggregator would convert this to
295
- "a[0]=b&a[1]=c" (with urlencoded brackets).
296
-
297
- The ``setAggregator()`` method accepts a ``callable`` which is used to convert
298
- a deeply nested array of query string variables into a flattened array of key
299
- value pairs. The callable accepts an array of query data and returns a
300
- flattened array of key value pairs where each value is an array of strings.
301
- You can use the ``GuzzleHttp\Query::walkQuery()`` static function to easily
302
- create custom query aggregators.
303
-
304
- Host
305
- ~~~~
306
-
307
- You can change the host header of the request in a predictable way using the
308
- ``setHost()`` method of a request:
309
-
310
- .. code-block:: php
311
-
312
- $request->setHost('www.google.com');
313
- echo $request->getHost();
314
- // www.google.com
315
- echo $request->getUrl();
316
- // https://www.google.com/get?foo=bar&baz=bam
317
-
318
- .. note::
319
-
320
- The Host header can also be changed by modifying the Host header of a
321
- request directly, but modifying the Host header directly could result in
322
- sending a request to a different Host than what is specified in the Host
323
- header (sometimes this is actually the desired behavior).
324
-
325
- Resource
326
- ~~~~~~~~
327
-
328
- You can use the ``getResource()`` method of a request to return the path and
329
- query string of a request in a single string.
330
-
331
- .. code-block:: php
332
-
333
- $request = $client->createRequest('GET', 'http://httpbin.org/get?baz=bar');
334
- echo $request->getResource();
335
- // /get?baz=bar
336
-
337
- Request Config
338
- --------------
339
-
340
- Request messages contain a configuration collection that can be used by
341
- event listeners and HTTP handlers to modify how a request behaves or is
342
- transferred over the wire. For example, many of the request options that are
343
- specified when creating a request are actually set as config options that are
344
- only acted upon by handlers and listeners when the request is sent.
345
-
346
- You can get access to the request's config object using the ``getConfig()``
347
- method of a request.
348
-
349
- .. code-block:: php
350
-
351
- $request = $client->createRequest('GET', '/');
352
- $config = $request->getConfig();
353
-
354
- The config object is a ``GuzzleHttp\Collection`` object that acts like
355
- an associative array. You can grab values from the collection using array like
356
- access. You can also modify and remove values using array like access.
357
-
358
- .. code-block:: php
359
-
360
- $config['foo'] = 'bar';
361
- echo $config['foo'];
362
- // bar
363
-
364
- var_export(isset($config['foo']));
365
- // true
366
-
367
- unset($config['foo']);
368
- var_export(isset($config['foo']));
369
- // false
370
-
371
- var_export($config['foo']);
372
- // NULL
373
-
374
- HTTP handlers and event listeners can expose additional customization options
375
- through request config settings. For example, in order to specify custom cURL
376
- options to the cURL handler, you need to specify an associative array in the
377
- ``curl`` ``config`` request option.
378
-
379
- .. code-block:: php
380
-
381
- $client->get('/', [
382
- 'config' => [
383
- 'curl' => [
384
- CURLOPT_HTTPAUTH => CURLAUTH_NTLM,
385
- CURLOPT_USERPWD => 'username:password'
386
- ]
387
- ]
388
- ]);
389
-
390
- Consult the HTTP handlers and event listeners you are using to see if they
391
- allow customization through request configuration options.
392
-
393
- Event Emitter
394
- -------------
395
-
396
- Request objects implement ``GuzzleHttp\Event\HasEmitterInterface``, so they
397
- have a method called ``getEmitter()`` that can be used to get an event emitter
398
- used by the request. Any listener or subscriber attached to a request will only
399
- be triggered for the lifecycle events of a specific request. Conversely, adding
400
- an event listener or subscriber to a client will listen to all lifecycle events
401
- of all requests created by the client.
402
-
403
- See :doc:`events` for more information.
404
-
405
- Responses
406
- =========
407
-
408
- Responses are the HTTP messages a client receives from a server after sending
409
- an HTTP request message.
410
-
411
- Start-Line
412
- ----------
413
-
414
- The start-line of a response contains the protocol and protocol version,
415
- status code, and reason phrase.
416
-
417
- .. code-block:: php
418
-
419
- $response = GuzzleHttp\get('http://httpbin.org/get');
420
- echo $response->getStatusCode();
421
- // 200
422
- echo $response->getReasonPhrase();
423
- // OK
424
- echo $response->getProtocolVersion();
425
- // 1.1
426
-
427
- Body
428
- ----
429
-
430
- As described earlier, you can get the body of a response using the
431
- ``getBody()`` method.
432
-
433
- .. code-block:: php
434
-
435
- if ($body = $response->getBody()) {
436
- echo $body;
437
- // Cast to a string: { ... }
438
- $body->seek(0);
439
- // Rewind the body
440
- $body->read(1024);
441
- // Read bytes of the body
442
- }
443
-
444
- When working with JSON responses, you can use the ``json()`` method of a
445
- response:
446
-
447
- .. code-block:: php
448
-
449
- $json = $response->json();
450
-
451
- .. note::
452
-
453
- Guzzle uses the ``json_decode()`` method of PHP and uses arrays rather than
454
- ``stdClass`` objects for objects.
455
-
456
- You can use the ``xml()`` method when working with XML data.
457
-
458
- .. code-block:: php
459
-
460
- $xml = $response->xml();
461
-
462
- .. note::
463
-
464
- Guzzle uses the ``SimpleXMLElement`` objects when converting response
465
- bodies to XML.
466
-
467
- Effective URL
468
- -------------
469
-
470
- The URL that was ultimately accessed that returned a response can be accessed
471
- using the ``getEffectiveUrl()`` method of a response. This method will return
472
- the URL of a request or the URL of the last redirected URL if any redirects
473
- occurred while transferring a request.
474
-
475
- .. code-block:: php
476
-
477
- $response = GuzzleHttp\get('http://httpbin.org/get');
478
- echo $response->getEffectiveUrl();
479
- // http://httpbin.org/get
480
-
481
- $response = GuzzleHttp\get('http://httpbin.org/redirect-to?url=http://www.google.com');
482
- echo $response->getEffectiveUrl();
483
- // http://www.google.com
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/docs/index.rst DELETED
@@ -1,98 +0,0 @@
1
- .. title:: Guzzle | PHP HTTP client and framework for consuming RESTful web services
2
-
3
- ======
4
- Guzzle
5
- ======
6
-
7
- Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and
8
- trivial to integrate with web services.
9
-
10
- - Manages things like persistent connections, represents query strings as
11
- collections, simplifies sending streaming POST requests with fields and
12
- files, and abstracts away the underlying HTTP transport layer.
13
- - Can send both synchronous and asynchronous requests using the same interface
14
- without requiring a dependency on a specific event loop.
15
- - Pluggable HTTP handlers allows Guzzle to integrate with any method you choose
16
- for sending HTTP requests over the wire (e.g., cURL, sockets, PHP's stream
17
- wrapper, non-blocking event loops like `React <http://reactphp.org/>`_, etc.).
18
- - Guzzle makes it so that you no longer need to fool around with cURL options,
19
- stream contexts, or sockets.
20
-
21
- .. code-block:: php
22
-
23
- $client = new GuzzleHttp\Client();
24
- $response = $client->get('http://guzzlephp.org');
25
- $res = $client->get('https://api.github.com/user', ['auth' => ['user', 'pass']]);
26
- echo $res->getStatusCode();
27
- // "200"
28
- echo $res->getHeader('content-type');
29
- // 'application/json; charset=utf8'
30
- echo $res->getBody();
31
- // {"type":"User"...'
32
- var_export($res->json());
33
- // Outputs the JSON decoded data
34
-
35
- // Send an asynchronous request.
36
- $req = $client->createRequest('GET', 'http://httpbin.org', ['future' => true]);
37
- $client->send($req)->then(function ($response) {
38
- echo 'I completed! ' . $response;
39
- });
40
-
41
- User guide
42
- ----------
43
-
44
- .. toctree::
45
- :maxdepth: 2
46
-
47
- overview
48
- quickstart
49
- clients
50
- http-messages
51
- events
52
- streams
53
- handlers
54
- testing
55
- faq
56
-
57
- HTTP Components
58
- ---------------
59
-
60
- There are a number of optional libraries you can use along with Guzzle's HTTP
61
- layer to add capabilities to the client.
62
-
63
- `Log Subscriber <https://github.com/guzzle/log-subscriber>`_
64
- Logs HTTP requests and responses sent over the wire using customizable
65
- log message templates.
66
-
67
- `OAuth Subscriber <https://github.com/guzzle/oauth-subscriber>`_
68
- Signs requests using OAuth 1.0.
69
-
70
- `Cache Subscriber <https://github.com/guzzle/cache-subscriber>`_
71
- Implements a private transparent proxy cache that caches HTTP responses.
72
-
73
- `Retry Subscriber <https://github.com/guzzle/retry-subscriber>`_
74
- Retries failed requests using customizable retry strategies (e.g., retry
75
- based on response status code, cURL error codes, etc.)
76
-
77
- `Message Integrity Subscriber <https://github.com/guzzle/message-integrity-subscriber>`_
78
- Verifies the message integrity of HTTP responses using customizable
79
- validators. This plugin can be used, for example, to verify the Content-MD5
80
- headers of responses.
81
-
82
- Service Description Commands
83
- ----------------------------
84
-
85
- You can use the **Guzzle Command** library to encapsulate interaction with a
86
- web service using command objects. Building on top of Guzzle's command
87
- abstraction allows you to easily implement things like service description that
88
- can be used to serialize requests and parse responses using a meta-description
89
- of a web service.
90
-
91
- `Guzzle Command <https://github.com/guzzle/command>`_
92
- Provides the foundational elements used to build high-level, command based,
93
- web service clients with Guzzle.
94
-
95
- `Guzzle Services <https://github.com/guzzle/guzzle-services>`_
96
- Provides an implementation of the *Guzzle Command* library that uses
97
- Guzzle service descriptions to describe web services, serialize requests,
98
- and parse responses into easy to use model structures.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/docs/overview.rst DELETED
@@ -1,150 +0,0 @@
1
- ========
2
- Overview
3
- ========
4
-
5
- Requirements
6
- ============
7
-
8
- #. PHP 5.4.0
9
- #. To use the PHP stream handler, ``allow_url_fopen`` must be enabled in your
10
- system's php.ini.
11
- #. To use the cURL handler, you must have a recent version of cURL >= 7.16.2
12
- compiled with OpenSSL and zlib.
13
-
14
- .. note::
15
-
16
- Guzzle no longer requires cURL in order to send HTTP requests. Guzzle will
17
- use the PHP stream wrapper to send HTTP requests if cURL is not installed.
18
- Alternatively, you can provide your own HTTP handler used to send requests.
19
-
20
- .. _installation:
21
-
22
- Installation
23
- ============
24
-
25
- The recommended way to install Guzzle is with `Composer <http://getcomposer.org>`_. Composer is a dependency
26
- management tool for PHP that allows you to declare the dependencies your project needs and installs them into your
27
- project.
28
-
29
- .. code-block:: bash
30
-
31
- # Install Composer
32
- curl -sS https://getcomposer.org/installer | php
33
-
34
- You can add Guzzle as a dependency using the composer.phar CLI:
35
-
36
- .. code-block:: bash
37
-
38
- php composer.phar require guzzlehttp/guzzle:~5.0
39
-
40
- Alternatively, you can specify Guzzle as a dependency in your project's
41
- existing composer.json file:
42
-
43
- .. code-block:: js
44
-
45
- {
46
- "require": {
47
- "guzzlehttp/guzzle": "~5.0"
48
- }
49
- }
50
-
51
- After installing, you need to require Composer's autoloader:
52
-
53
- .. code-block:: php
54
-
55
- require 'vendor/autoload.php';
56
-
57
- You can find out more on how to install Composer, configure autoloading, and
58
- other best-practices for defining dependencies at `getcomposer.org <http://getcomposer.org>`_.
59
-
60
- Bleeding edge
61
- -------------
62
-
63
- During your development, you can keep up with the latest changes on the master
64
- branch by setting the version requirement for Guzzle to ``~5.0@dev``.
65
-
66
- .. code-block:: js
67
-
68
- {
69
- "require": {
70
- "guzzlehttp/guzzle": "~5.0@dev"
71
- }
72
- }
73
-
74
- License
75
- =======
76
-
77
- Licensed using the `MIT license <http://opensource.org/licenses/MIT>`_.
78
-
79
- Copyright (c) 2014 Michael Dowling <https://github.com/mtdowling>
80
-
81
- Permission is hereby granted, free of charge, to any person obtaining a copy
82
- of this software and associated documentation files (the "Software"), to deal
83
- in the Software without restriction, including without limitation the rights
84
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
85
- copies of the Software, and to permit persons to whom the Software is
86
- furnished to do so, subject to the following conditions:
87
-
88
- The above copyright notice and this permission notice shall be included in
89
- all copies or substantial portions of the Software.
90
-
91
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
92
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
93
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
94
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
95
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
96
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
97
- THE SOFTWARE.
98
-
99
- Contributing
100
- ============
101
-
102
- Guidelines
103
- ----------
104
-
105
- 1. Guzzle follows PSR-0, PSR-1, and PSR-2.
106
- 2. Guzzle is meant to be lean and fast with very few dependencies.
107
- 3. Guzzle has a minimum PHP version requirement of PHP 5.4. Pull requests must
108
- not require a PHP version greater than PHP 5.4.
109
- 4. All pull requests must include unit tests to ensure the change works as
110
- expected and to prevent regressions.
111
-
112
- Running the tests
113
- -----------------
114
-
115
- In order to contribute, you'll need to checkout the source from GitHub and
116
- install Guzzle's dependencies using Composer:
117
-
118
- .. code-block:: bash
119
-
120
- git clone https://github.com/guzzle/guzzle.git
121
- cd guzzle && curl -s http://getcomposer.org/installer | php && ./composer.phar install --dev
122
-
123
- Guzzle is unit tested with PHPUnit. Run the tests using the vendored PHPUnit
124
- binary:
125
-
126
- .. code-block:: bash
127
-
128
- vendor/bin/phpunit
129
-
130
- .. note::
131
-
132
- You'll need to install node.js v0.5.0 or newer in order to perform
133
- integration tests on Guzzle's HTTP handlers.
134
-
135
- Reporting a security vulnerability
136
- ==================================
137
-
138
- We want to ensure that Guzzle is a secure HTTP client library for everyone. If
139
- you've discovered a security vulnerability in Guzzle, we appreciate your help
140
- in disclosing it to us in a `responsible manner <http://en.wikipedia.org/wiki/Responsible_disclosure>`_.
141
-
142
- Publicly disclosing a vulnerability can put the entire community at risk. If
143
- you've discovered a security concern, please email us at
144
- security@guzzlephp.org. We'll work with you to make sure that we understand the
145
- scope of the issue, and that we fully address your concern. We consider
146
- correspondence sent to security@guzzlephp.org our highest priority, and work to
147
- address any issues that arise as quickly as possible.
148
-
149
- After a security vulnerability has been corrected, a security hotfix release will
150
- be deployed as soon as possible.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/docs/quickstart.rst DELETED
@@ -1,448 +0,0 @@
1
- ==========
2
- Quickstart
3
- ==========
4
-
5
- This page provides a quick introduction to Guzzle and introductory examples.
6
- If you have not already installed, Guzzle, head over to the :ref:`installation`
7
- page.
8
-
9
- Make a Request
10
- ==============
11
-
12
- You can send requests with Guzzle using a ``GuzzleHttp\ClientInterface``
13
- object.
14
-
15
- Creating a Client
16
- -----------------
17
-
18
- The procedural API is simple but not very testable; it's best left for quick
19
- prototyping. If you want to use Guzzle in a more flexible and testable way,
20
- then you'll need to use a ``GuzzleHttp\ClientInterface`` object.
21
-
22
- .. code-block:: php
23
-
24
- use GuzzleHttp\Client;
25
-
26
- $client = new Client();
27
- $response = $client->get('http://httpbin.org/get');
28
-
29
- // You can use the same methods you saw in the procedural API
30
- $response = $client->delete('http://httpbin.org/delete');
31
- $response = $client->head('http://httpbin.org/get');
32
- $response = $client->options('http://httpbin.org/get');
33
- $response = $client->patch('http://httpbin.org/patch');
34
- $response = $client->post('http://httpbin.org/post');
35
- $response = $client->put('http://httpbin.org/put');
36
-
37
- You can create a request with a client and then send the request with the
38
- client when you're ready.
39
-
40
- .. code-block:: php
41
-
42
- $request = $client->createRequest('GET', 'http://www.foo.com');
43
- $response = $client->send($request);
44
-
45
- Client objects provide a great deal of flexibility in how request are
46
- transferred including default request options, subscribers that are attached
47
- to each request, and a base URL that allows you to send requests with relative
48
- URLs. You can find out all about clients in the :doc:`clients` page of the
49
- documentation.
50
-
51
- Using Responses
52
- ===============
53
-
54
- In the previous examples, we retrieved a ``$response`` variable. This value is
55
- actually a ``GuzzleHttp\Message\ResponseInterface`` object and contains lots
56
- of helpful information.
57
-
58
- You can get the status code and reason phrase of the response.
59
-
60
- .. code-block:: php
61
-
62
- $code = $response->getStatusCode();
63
- // 200
64
-
65
- $reason = $response->getReasonPhrase();
66
- // OK
67
-
68
- By providing the ``future`` request option to a request, you can send requests
69
- asynchronously using the promise interface of a future response.
70
-
71
- .. code-block:: php
72
-
73
- $client->get('http://httpbin.org', ['future' => true])
74
- ->then(function ($response) {
75
- echo $response->getStatusCode();
76
- });
77
-
78
- Response Body
79
- -------------
80
-
81
- The body of a response can be retrieved and cast to a string.
82
-
83
- .. code-block:: php
84
-
85
- $body = $response->getBody();
86
- echo $body;
87
- // { "some_json_data" ...}
88
-
89
- You can also read read bytes from body of a response like a stream.
90
-
91
- .. code-block:: php
92
-
93
- $body = $response->getBody();
94
-
95
- while (!$body->eof()) {
96
- echo $body->read(1024);
97
- }
98
-
99
- JSON Responses
100
- ~~~~~~~~~~~~~~
101
-
102
- You can more easily work with JSON responses using the ``json()`` method of a
103
- response.
104
-
105
- .. code-block:: php
106
-
107
- $response = $client->get('http://httpbin.org/get');
108
- $json = $response->json();
109
- var_dump($json[0]['origin']);
110
-
111
- Guzzle internally uses PHP's ``json_decode()`` function to parse responses. If
112
- Guzzle is unable to parse the JSON response body, then a
113
- ``GuzzleHttp\Exception\ParseException`` is thrown.
114
-
115
- XML Responses
116
- ~~~~~~~~~~~~~
117
-
118
- You can use a response's ``xml()`` method to more easily work with responses
119
- that contain XML data.
120
-
121
- .. code-block:: php
122
-
123
- $response = $client->get('https://github.com/mtdowling.atom');
124
- $xml = $response->xml();
125
- echo $xml->id;
126
- // tag:github.com,2008:/mtdowling
127
-
128
- Guzzle internally uses a ``SimpleXMLElement`` object to parse responses. If
129
- Guzzle is unable to parse the XML response body, then a
130
- ``GuzzleHttp\Exception\ParseException`` is thrown.
131
-
132
- Query String Parameters
133
- =======================
134
-
135
- Sending query string parameters with a request is easy. You can set query
136
- string parameters in the request's URL.
137
-
138
- .. code-block:: php
139
-
140
- $response = $client->get('http://httpbin.org?foo=bar');
141
-
142
- You can also specify the query string parameters using the ``query`` request
143
- option.
144
-
145
- .. code-block:: php
146
-
147
- $client->get('http://httpbin.org', [
148
- 'query' => ['foo' => 'bar']
149
- ]);
150
-
151
- And finally, you can build up the query string of a request as needed by
152
- calling the ``getQuery()`` method of a request and modifying the request's
153
- ``GuzzleHttp\Query`` object as needed.
154
-
155
- .. code-block:: php
156
-
157
- $request = $client->createRequest('GET', 'http://httpbin.org');
158
- $query = $request->getQuery();
159
- $query->set('foo', 'bar');
160
-
161
- // You can use the query string object like an array
162
- $query['baz'] = 'bam';
163
-
164
- // The query object can be cast to a string
165
- echo $query;
166
- // foo=bar&baz=bam
167
-
168
- // Setting a value to false or null will cause the "=" sign to be omitted
169
- $query['empty'] = null;
170
- echo $query;
171
- // foo=bar&baz=bam&empty
172
-
173
- // Use an empty string to include the "=" sign with an empty value
174
- $query['empty'] = '';
175
- echo $query;
176
- // foo=bar&baz=bam&empty=
177
-
178
- .. _headers:
179
-
180
- Request and Response Headers
181
- ----------------------------
182
-
183
- You can specify request headers when sending or creating requests with a
184
- client. In the following example, we send the ``X-Foo-Header`` with a value of
185
- ``value`` by setting the ``headers`` request option.
186
-
187
- .. code-block:: php
188
-
189
- $response = $client->get('http://httpbin.org/get', [
190
- 'headers' => ['X-Foo-Header' => 'value']
191
- ]);
192
-
193
- You can view the headers of a response using header specific methods of a
194
- response class. Headers work exactly the same way for request and response
195
- object.
196
-
197
- You can retrieve a header from a request or response using the ``getHeader()``
198
- method of the object. This method is case-insensitive and by default will
199
- return a string containing the header field value.
200
-
201
- .. code-block:: php
202
-
203
- $response = $client->get('http://www.yahoo.com');
204
- $length = $response->getHeader('Content-Length');
205
-
206
- Header fields that contain multiple values can be retrieved as a string or as
207
- an array. Retrieving the field values as a string will naively concatenate all
208
- of the header values together with a comma. Because not all header fields
209
- should be represented this way (e.g., ``Set-Cookie``), you can pass an optional
210
- flag to the ``getHeader()`` method to retrieve the header values as an array.
211
-
212
- .. code-block:: php
213
-
214
- $values = $response->getHeader('Set-Cookie', true);
215
- foreach ($values as $value) {
216
- echo $value;
217
- }
218
-
219
- You can test if a request or response has a specific header using the
220
- ``hasHeader()`` method. This method accepts a case-insensitive string and
221
- returns true if the header is present or false if it is not.
222
-
223
- You can retrieve all of the headers of a message using the ``getHeaders()``
224
- method of a request or response. The return value is an associative array where
225
- the keys represent the header name as it will be sent over the wire, and each
226
- value is an array of strings associated with the header.
227
-
228
- .. code-block:: php
229
-
230
- $headers = $response->getHeaders();
231
- foreach ($message->getHeaders() as $name => $values) {
232
- echo $name . ": " . implode(", ", $values);
233
- }
234
-
235
- Modifying headers
236
- -----------------
237
-
238
- The headers of a message can be modified using the ``setHeader()``,
239
- ``addHeader()``, ``setHeaders()``, and ``removeHeader()`` methods of a request
240
- or response object.
241
-
242
- .. code-block:: php
243
-
244
- $request = $client->createRequest('GET', 'http://httpbin.org/get');
245
-
246
- // Set a single value for a header
247
- $request->setHeader('User-Agent', 'Testing!');
248
-
249
- // Set multiple values for a header in one call
250
- $request->setHeader('X-Foo', ['Baz', 'Bar']);
251
-
252
- // Add a header to the message
253
- $request->addHeader('X-Foo', 'Bam');
254
-
255
- echo $request->getHeader('X-Foo');
256
- // Baz, Bar, Bam
257
-
258
- // Remove a specific header using a case-insensitive name
259
- $request->removeHeader('x-foo');
260
- echo $request->getHeader('X-Foo');
261
- // Echoes an empty string: ''
262
-
263
- Uploading Data
264
- ==============
265
-
266
- Guzzle provides several methods of uploading data.
267
-
268
- You can send requests that contain a stream of data by passing a string,
269
- resource returned from ``fopen``, or a ``GuzzleHttp\Stream\StreamInterface``
270
- object to the ``body`` request option.
271
-
272
- .. code-block:: php
273
-
274
- $r = $client->post('http://httpbin.org/post', ['body' => 'raw data']);
275
-
276
- You can easily upload JSON data using the ``json`` request option.
277
-
278
- .. code-block:: php
279
-
280
- $r = $client->put('http://httpbin.org/put', ['json' => ['foo' => 'bar']]);
281
-
282
- POST Requests
283
- -------------
284
-
285
- In addition to specifying the raw data of a request using the ``body`` request
286
- option, Guzzle provides helpful abstractions over sending POST data.
287
-
288
- Sending POST Fields
289
- ~~~~~~~~~~~~~~~~~~~
290
-
291
- Sending ``application/x-www-form-urlencoded`` POST requests requires that you
292
- specify the body of a POST request as an array.
293
-
294
- .. code-block:: php
295
-
296
- $response = $client->post('http://httpbin.org/post', [
297
- 'body' => [
298
- 'field_name' => 'abc',
299
- 'other_field' => '123'
300
- ]
301
- ]);
302
-
303
- You can also build up POST requests before sending them.
304
-
305
- .. code-block:: php
306
-
307
- $request = $client->createRequest('POST', 'http://httpbin.org/post');
308
- $postBody = $request->getBody();
309
-
310
- // $postBody is an instance of GuzzleHttp\Post\PostBodyInterface
311
- $postBody->setField('foo', 'bar');
312
- echo $postBody->getField('foo');
313
- // 'bar'
314
-
315
- echo json_encode($postBody->getFields());
316
- // {"foo": "bar"}
317
-
318
- // Send the POST request
319
- $response = $client->send($request);
320
-
321
- Sending POST Files
322
- ~~~~~~~~~~~~~~~~~~
323
-
324
- Sending ``multipart/form-data`` POST requests (POST requests that contain
325
- files) is the same as sending ``application/x-www-form-urlencoded``, except
326
- some of the array values of the POST fields map to PHP ``fopen`` resources, or
327
- ``GuzzleHttp\Stream\StreamInterface``, or
328
- ``GuzzleHttp\Post\PostFileInterface`` objects.
329
-
330
- .. code-block:: php
331
-
332
- use GuzzleHttp\Post\PostFile;
333
-
334
- $response = $client->post('http://httpbin.org/post', [
335
- 'body' => [
336
- 'field_name' => 'abc',
337
- 'file_filed' => fopen('/path/to/file', 'r'),
338
- 'other_file' => new PostFile('other_file', 'this is the content')
339
- ]
340
- ]);
341
-
342
- Just like when sending POST fields, you can also build up POST requests with
343
- files before sending them.
344
-
345
- .. code-block:: php
346
-
347
- use GuzzleHttp\Post\PostFile;
348
-
349
- $request = $client->createRequest('POST', 'http://httpbin.org/post');
350
- $postBody = $request->getBody();
351
- $postBody->setField('foo', 'bar');
352
- $postBody->addFile(new PostFile('test', fopen('/path/to/file', 'r')));
353
- $response = $client->send($request);
354
-
355
- Cookies
356
- =======
357
-
358
- Guzzle can maintain a cookie session for you if instructed using the
359
- ``cookies`` request option.
360
-
361
- - Set to ``true`` to use a shared cookie session associated with the client.
362
- - Pass an associative array containing cookies to send in the request and start
363
- a new cookie session.
364
- - Set to a ``GuzzleHttp\Subscriber\CookieJar\CookieJarInterface`` object to use
365
- an existing cookie jar.
366
-
367
- Redirects
368
- =========
369
-
370
- Guzzle will automatically follow redirects unless you tell it not to. You can
371
- customize the redirect behavior using the ``allow_redirects`` request option.
372
-
373
- - Set to true to enable normal redirects with a maximum number of 5 redirects.
374
- This is the default setting.
375
- - Set to false to disable redirects.
376
- - Pass an associative array containing the 'max' key to specify the maximum
377
- number of redirects and optionally provide a 'strict' key value to specify
378
- whether or not to use strict RFC compliant redirects (meaning redirect POST
379
- requests with POST requests vs. doing what most browsers do which is
380
- redirect POST requests with GET requests).
381
-
382
- .. code-block:: php
383
-
384
- $response = $client->get('http://github.com');
385
- echo $response->getStatusCode();
386
- // 200
387
- echo $response->getEffectiveUrl();
388
- // 'https://github.com/'
389
-
390
- The following example shows that redirects can be disabled.
391
-
392
- .. code-block:: php
393
-
394
- $response = $client->get('http://github.com', ['allow_redirects' => false]);
395
- echo $response->getStatusCode();
396
- // 301
397
- echo $response->getEffectiveUrl();
398
- // 'http://github.com/'
399
-
400
- Exceptions
401
- ==========
402
-
403
- Guzzle throws exceptions for errors that occur during a transfer.
404
-
405
- - In the event of a networking error (connection timeout, DNS errors, etc.),
406
- a ``GuzzleHttp\Exception\RequestException`` is thrown. This exception
407
- extends from ``GuzzleHttp\Exception\TransferException``. Catching this
408
- exception will catch any exception that can be thrown while transferring
409
- (non-parallel) requests.
410
-
411
- .. code-block:: php
412
-
413
- use GuzzleHttp\Exception\RequestException;
414
-
415
- try {
416
- $client->get('https://github.com/_abc_123_404');
417
- } catch (RequestException $e) {
418
- echo $e->getRequest();
419
- if ($e->hasResponse()) {
420
- echo $e->getResponse();
421
- }
422
- }
423
-
424
- - A ``GuzzleHttp\Exception\ClientException`` is thrown for 400
425
- level errors if the ``exceptions`` request option is set to true. This
426
- exception extends from ``GuzzleHttp\Exception\BadResponseException`` and
427
- ``GuzzleHttp\Exception\BadResponseException`` extends from
428
- ``GuzzleHttp\Exception\RequestException``.
429
-
430
- .. code-block:: php
431
-
432
- use GuzzleHttp\Exception\ClientException;
433
-
434
- try {
435
- $client->get('https://github.com/_abc_123_404');
436
- } catch (ClientException $e) {
437
- echo $e->getRequest();
438
- echo $e->getResponse();
439
- }
440
-
441
- - A ``GuzzleHttp\Exception\ServerException`` is thrown for 500 level
442
- errors if the ``exceptions`` request option is set to true. This
443
- exception extends from ``GuzzleHttp\Exception\BadResponseException``.
444
- - A ``GuzzleHttp\Exception\TooManyRedirectsException`` is thrown when too
445
- many redirects are followed. This exception extends from ``GuzzleHttp\Exception\RequestException``.
446
-
447
- All of the above exceptions extend from
448
- ``GuzzleHttp\Exception\TransferException``.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/docs/requirements.txt DELETED
@@ -1,2 +0,0 @@
1
- Sphinx>=1.2b1
2
- guzzle_sphinx_theme>=0.6.0
 
 
vendor/constantcontact/guzzlehttp/guzzle/docs/streams.rst DELETED
@@ -1,213 +0,0 @@
1
- =======
2
- Streams
3
- =======
4
-
5
- Guzzle uses stream objects to represent request and response message bodies.
6
- These stream objects allow you to work with various types of data all using a
7
- common interface.
8
-
9
- HTTP messages consist of a start-line, headers, and a body. The body of an HTTP
10
- message can be very small or extremely large. Attempting to represent the body
11
- of a message as a string can easily consume more memory than intended because
12
- the body must be stored completely in memory. Attempting to store the body of a
13
- request or response in memory would preclude the use of that implementation from
14
- being able to work with large message bodies. The StreamInterface is used in
15
- order to hide the implementation details of where a stream of data is read from
16
- or written to.
17
-
18
- Guzzle's StreamInterface exposes several methods that enable streams to be read
19
- from, written to, and traversed effectively.
20
-
21
- Streams expose their capabilities using three methods: ``isReadable()``,
22
- ``isWritable()``, and ``isSeekable()``. These methods can be used by stream
23
- collaborators to determine if a stream is capable of their requirements.
24
-
25
- Each stream instance has various capabilities: they can be read-only,
26
- write-only, read-write, allow arbitrary random access (seeking forwards or
27
- backwards to any location), or only allow sequential access (for example in the
28
- case of a socket or pipe).
29
-
30
- Creating Streams
31
- ================
32
-
33
- The best way to create a stream is using the static factory method,
34
- ``GuzzleHttp\Stream\Stream::factory()``. This factory accepts strings,
35
- resources returned from ``fopen()``, an object that implements
36
- ``__toString()``, and an object that implements
37
- ``GuzzleHttp\Stream\StreamInterface``.
38
-
39
- .. code-block:: php
40
-
41
- use GuzzleHttp\Stream\Stream;
42
-
43
- $stream = Stream::factory('string data');
44
- echo $stream;
45
- // string data
46
- echo $stream->read(3);
47
- // str
48
- echo $stream->getContents();
49
- // ing data
50
- var_export($stream->eof());
51
- // true
52
- var_export($stream->tell());
53
- // 11
54
-
55
- Metadata
56
- ========
57
-
58
- Guzzle streams expose stream metadata through the ``getMetadata()`` method.
59
- This method provides the data you would retrieve when calling PHP's
60
- `stream_get_meta_data() function <http://php.net/manual/en/function.stream-get-meta-data.php>`_,
61
- and can optionally expose other custom data.
62
-
63
- .. code-block:: php
64
-
65
- use GuzzleHttp\Stream\Stream;
66
-
67
- $resource = fopen('/path/to/file', 'r');
68
- $stream = Stream::factory($resource);
69
- echo $stream->getMetadata('uri');
70
- // /path/to/file
71
- var_export($stream->isReadable());
72
- // true
73
- var_export($stream->isWritable());
74
- // false
75
- var_export($stream->isSeekable());
76
- // true
77
-
78
- Stream Decorators
79
- =================
80
-
81
- With the small and focused interface, add custom functionality to streams is
82
- very simple with stream decorators. Guzzle provides several built-in decorators
83
- that provide additional stream functionality.
84
-
85
- CachingStream
86
- -------------
87
-
88
- The CachingStream is used to allow seeking over previously read bytes on
89
- non-seekable streams. This can be useful when transferring a non-seekable
90
- entity body fails due to needing to rewind the stream (for example, resulting
91
- from a redirect). Data that is read from the remote stream will be buffered in
92
- a PHP temp stream so that previously read bytes are cached first in memory,
93
- then on disk.
94
-
95
- .. code-block:: php
96
-
97
- use GuzzleHttp\Stream\Stream;
98
- use GuzzleHttp\Stream\CachingStream;
99
-
100
- $original = Stream::factory(fopen('http://www.google.com', 'r'));
101
- $stream = new CachingStream($original);
102
-
103
- $stream->read(1024);
104
- echo $stream->tell();
105
- // 1024
106
-
107
- $stream->seek(0);
108
- echo $stream->tell();
109
- // 0
110
-
111
- LimitStream
112
- -----------
113
-
114
- LimitStream can be used to read a subset or slice of an existing stream object.
115
- This can be useful for breaking a large file into smaller pieces to be sent in
116
- chunks (e.g. Amazon S3's multipart upload API).
117
-
118
- .. code-block:: php
119
-
120
- use GuzzleHttp\Stream\Stream;
121
- use GuzzleHttp\Stream\LimitStream;
122
-
123
- $original = Stream::factory(fopen('/tmp/test.txt', 'r+'));
124
- echo $original->getSize();
125
- // >>> 1048576
126
-
127
- // Limit the size of the body to 1024 bytes and start reading from byte 2048
128
- $stream = new LimitStream($original, 1024, 2048);
129
- echo $stream->getSize();
130
- // >>> 1024
131
- echo $stream->tell();
132
- // >>> 0
133
-
134
- NoSeekStream
135
- ------------
136
-
137
- NoSeekStream wraps a stream and does not allow seeking.
138
-
139
- .. code-block:: php
140
-
141
- use GuzzleHttp\Stream\Stream;
142
- use GuzzleHttp\Stream\LimitStream;
143
-
144
- $original = Stream::factory('foo');
145
- $noSeek = new NoSeekStream($original);
146
-
147
- echo $noSeek->read(3);
148
- // foo
149
- var_export($noSeek->isSeekable());
150
- // false
151
- $noSeek->seek(0);
152
- var_export($noSeek->read(3));
153
- // NULL
154
-
155
- Creating Custom Decorators
156
- --------------------------
157
-
158
- Creating a stream decorator is very easy thanks to the
159
- ``GuzzleHttp\Stream\StreamDecoratorTrait``. This trait provides methods that
160
- implement ``GuzzleHttp\Stream\StreamInterface`` by proxying to an underlying
161
- stream. Just ``use`` the ``StreamDecoratorTrait`` and implement your custom
162
- methods.
163
-
164
- For example, let's say we wanted to call a specific function each time the last
165
- byte is read from a stream. This could be implemented by overriding the
166
- ``read()`` method.
167
-
168
- .. code-block:: php
169
-
170
- use GuzzleHttp\Stream\StreamDecoratorTrait;
171
-
172
- class EofCallbackStream implements StreamInterface
173
- {
174
- use StreamDecoratorTrait;
175
-
176
- private $callback;
177
-
178
- public function __construct(StreamInterface $stream, callable $callback)
179
- {
180
- $this->stream = $stream;
181
- $this->callback = $callback;
182
- }
183
-
184
- public function read($length)
185
- {
186
- $result = $this->stream->read($length);
187
-
188
- // Invoke the callback when EOF is hit.
189
- if ($this->eof()) {
190
- call_user_func($this->callback);
191
- }
192
-
193
- return $result;
194
- }
195
- }
196
-
197
- This decorator could be added to any existing stream and used like so:
198
-
199
- .. code-block:: php
200
-
201
- use GuzzleHttp\Stream\Stream;
202
-
203
- $original = Stream::factory('foo');
204
- $eofStream = new EofCallbackStream($original, function () {
205
- echo 'EOF!';
206
- });
207
-
208
- $eofStream->read(2);
209
- $eofStream->read(1);
210
- // echoes "EOF!"
211
- $eofStream->seek(0);
212
- $eofStream->read(3);
213
- // echoes "EOF!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/docs/testing.rst DELETED
@@ -1,232 +0,0 @@
1
- ======================
2
- Testing Guzzle Clients
3
- ======================
4
-
5
- Guzzle provides several tools that will enable you to easily mock the HTTP
6
- layer without needing to send requests over the internet.
7
-
8
- * Mock subscriber
9
- * Mock handler
10
- * Node.js web server for integration testing
11
-
12
- Mock Subscriber
13
- ===============
14
-
15
- When testing HTTP clients, you often need to simulate specific scenarios like
16
- returning a successful response, returning an error, or returning specific
17
- responses in a certain order. Because unit tests need to be predictable, easy
18
- to bootstrap, and fast, hitting an actual remote API is a test smell.
19
-
20
- Guzzle provides a mock subscriber that can be attached to clients or requests
21
- that allows you to queue up a list of responses to use rather than hitting a
22
- remote API.
23
-
24
- .. code-block:: php
25
-
26
- use GuzzleHttp\Client;
27
- use GuzzleHttp\Subscriber\Mock;
28
- use GuzzleHttp\Message\Response;
29
-
30
- $client = new Client();
31
-
32
- // Create a mock subscriber and queue two responses.
33
- $mock = new Mock([
34
- new Response(200, ['X-Foo' => 'Bar']), // Use response object
35
- "HTTP/1.1 202 OK\r\nContent-Length: 0\r\n\r\n" // Use a response string
36
- ]);
37
-
38
- // Add the mock subscriber to the client.
39
- $client->getEmitter()->attach($mock);
40
- // The first request is intercepted with the first response.
41
- echo $client->get('/')->getStatusCode();
42
- //> 200
43
- // The second request is intercepted with the second response.
44
- echo $client->get('/')->getStatusCode();
45
- //> 202
46
-
47
- When no more responses are in the queue and a request is sent, an
48
- ``OutOfBoundsException`` is thrown.
49
-
50
- History Subscriber
51
- ==================
52
-
53
- When using things like the ``Mock`` subscriber, you often need to know if the
54
- requests you expected to send were sent exactly as you intended. While the mock
55
- subscriber responds with mocked responses, the ``GuzzleHttp\Subscriber\History``
56
- subscriber maintains a history of the requests that were sent by a client.
57
-
58
- .. code-block:: php
59
-
60
- use GuzzleHttp\Client;
61
- use GuzzleHttp\Subscriber\History;
62
-
63
- $client = new Client();
64
- $history = new History();
65
-
66
- // Add the history subscriber to the client.
67
- $client->getEmitter()->attach($history);
68
-
69
- $client->get('http://httpbin.org/get');
70
- $client->head('http://httpbin.org/get');
71
-
72
- // Count the number of transactions
73
- echo count($history);
74
- //> 2
75
- // Get the last request
76
- $lastRequest = $history->getLastRequest();
77
- // Get the last response
78
- $lastResponse = $history->getLastResponse();
79
-
80
- // Iterate over the transactions that were sent
81
- foreach ($history as $transaction) {
82
- echo $transaction['request']->getMethod();
83
- //> GET, HEAD
84
- echo $transaction['response']->getStatusCode();
85
- //> 200, 200
86
- }
87
-
88
- The history subscriber can also be printed, revealing the requests and
89
- responses that were sent as a string, in order.
90
-
91
- .. code-block:: php
92
-
93
- echo $history;
94
-
95
- ::
96
-
97
- > GET /get HTTP/1.1
98
- Host: httpbin.org
99
- User-Agent: Guzzle/4.0-dev curl/7.21.4 PHP/5.5.8
100
-
101
- < HTTP/1.1 200 OK
102
- Access-Control-Allow-Origin: *
103
- Content-Type: application/json
104
- Date: Tue, 25 Mar 2014 03:53:27 GMT
105
- Server: gunicorn/0.17.4
106
- Content-Length: 270
107
- Connection: keep-alive
108
-
109
- {
110
- "headers": {
111
- "Connection": "close",
112
- "X-Request-Id": "3d0f7d5c-c937-4394-8248-2b8e03fcccdb",
113
- "User-Agent": "Guzzle/4.0-dev curl/7.21.4 PHP/5.5.8",
114
- "Host": "httpbin.org"
115
- },
116
- "origin": "76.104.247.1",
117
- "args": {},
118
- "url": "http://httpbin.org/get"
119
- }
120
-
121
- > HEAD /get HTTP/1.1
122
- Host: httpbin.org
123
- User-Agent: Guzzle/4.0-dev curl/7.21.4 PHP/5.5.8
124
-
125
- < HTTP/1.1 200 OK
126
- Access-Control-Allow-Origin: *
127
- Content-length: 270
128
- Content-Type: application/json
129
- Date: Tue, 25 Mar 2014 03:53:27 GMT
130
- Server: gunicorn/0.17.4
131
- Connection: keep-alive
132
-
133
- Mock Adapter
134
- ============
135
-
136
- In addition to using the Mock subscriber, you can use the
137
- ``GuzzleHttp\Ring\Client\MockHandler`` as the handler of a client to return the
138
- same response over and over or return the result of a callable function.
139
-
140
- Test Web Server
141
- ===============
142
-
143
- Using mock responses is almost always enough when testing a web service client.
144
- When implementing custom :doc:`HTTP handlers <handlers>`, you'll need to send
145
- actual HTTP requests in order to sufficiently test the handler. However, a
146
- best practice is to contact a local web server rather than a server over the
147
- internet.
148
-
149
- - Tests are more reliable
150
- - Tests do not require a network connection
151
- - Tests have no external dependencies
152
-
153
- Using the test server
154
- ---------------------
155
-
156
- .. warning::
157
-
158
- The following functionality is provided to help developers of Guzzle
159
- develop HTTP handlers. There is no promise of backwards compatibility
160
- when it comes to the node.js test server or the ``GuzzleHttp\Tests\Server``
161
- class. If you are using the test server or ``Server`` class outside of
162
- guzzlehttp/guzzle, then you will need to configure autoloading and
163
- ensure the web server is started manually.
164
-
165
- .. hint::
166
-
167
- You almost never need to use this test web server. You should only ever
168
- consider using it when developing HTTP handlers. The test web server
169
- is not necessary for mocking requests. For that, please use the
170
- Mock subcribers and History subscriber.
171
-
172
- Guzzle ships with a node.js test server that receives requests and returns
173
- responses from a queue. The test server exposes a simple API that is used to
174
- enqueue responses and inspect the requests that it has received.
175
-
176
- Any operation on the ``Server`` object will ensure that
177
- the server is running and wait until it is able to receive requests before
178
- returning.
179
-
180
- .. code-block:: php
181
-
182
- use GuzzleHttp\Client;
183
- use GuzzleHttp\Tests\Server;
184
-
185
- // Start the server and queue a response
186
- Server::enqueue("HTTP/1.1 200 OK\r\n\Content-Length: 0r\n\r\n");
187
-
188
- $client = new Client(['base_url' => Server::$url]);
189
- echo $client->get('/foo')->getStatusCode();
190
- // 200
191
-
192
- ``GuzzleHttp\Tests\Server`` provides a static interface to the test server. You
193
- can queue an HTTP response or an array of responses by calling
194
- ``Server::enqueue()``. This method accepts a string representing an HTTP
195
- response message, a ``GuzzleHttp\Message\ResponseInterface``, or an array of
196
- HTTP message strings / ``GuzzleHttp\Message\ResponseInterface`` objects.
197
-
198
- .. code-block:: php
199
-
200
- // Queue single response
201
- Server::enqueue("HTTP/1.1 200 OK\r\n\Content-Length: 0r\n\r\n");
202
-
203
- // Clear the queue and queue an array of responses
204
- Server::enqueue([
205
- "HTTP/1.1 200 OK\r\n\Content-Length: 0r\n\r\n",
206
- "HTTP/1.1 404 Not Found\r\n\Content-Length: 0r\n\r\n"
207
- ]);
208
-
209
- When a response is queued on the test server, the test server will remove any
210
- previously queued responses. As the server receives requests, queued responses
211
- are dequeued and returned to the request. When the queue is empty, the server
212
- will return a 500 response.
213
-
214
- You can inspect the requests that the server has retrieved by calling
215
- ``Server::received()``. This method accepts an optional ``$hydrate`` parameter
216
- that specifies if you are retrieving an array of HTTP requests as strings or an
217
- array of ``GuzzleHttp\Message\RequestInterface`` objects.
218
-
219
- .. code-block:: php
220
-
221
- foreach (Server::received() as $response) {
222
- echo $response;
223
- }
224
-
225
- You can clear the list of received requests from the web server using the
226
- ``Server::flush()`` method.
227
-
228
- .. code-block:: php
229
-
230
- Server::flush();
231
- echo count(Server::received());
232
- // 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/src/BatchResults.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Client.php CHANGED
@@ -199,9 +199,12 @@ class Client implements ClientInterface
199
  'verify' => true
200
  ];
201
 
202
- // Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set
203
- if ($proxy = getenv('HTTP_PROXY')) {
204
- $settings['proxy']['http'] = $proxy;
 
 
 
205
  }
206
 
207
  if ($proxy = getenv('HTTPS_PROXY')) {
199
  'verify' => true
200
  ];
201
 
202
+ // Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set.
203
+ // We can only trust the HTTP_PROXY environment variable in a CLI
204
+ // process due to the fact that PHP has no reliable mechanism to
205
+ // get environment variables that start with "HTTP_".
206
+ if (php_sapi_name() == 'cli' && getenv('HTTP_PROXY')) {
207
+ $settings['proxy']['http'] = getenv('HTTP_PROXY');
208
  }
209
 
210
  if ($proxy = getenv('HTTPS_PROXY')) {
vendor/constantcontact/guzzlehttp/guzzle/src/ClientInterface.php CHANGED
@@ -11,7 +11,7 @@ use GuzzleHttp\Message\ResponseInterface;
11
  */
12
  interface ClientInterface extends HasEmitterInterface
13
  {
14
- const VERSION = '5.3.0';
15
 
16
  /**
17
  * Create and return a new {@see RequestInterface} object.
11
  */
12
  interface ClientInterface extends HasEmitterInterface
13
  {
14
+ const VERSION = '5.3.1';
15
 
16
  /**
17
  * Create and return a new {@see RequestInterface} object.
vendor/constantcontact/guzzlehttp/guzzle/src/Collection.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Cookie/CookieJar.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Cookie/CookieJarInterface.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Cookie/SessionCookieJar.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Cookie/SetCookie.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/AbstractEvent.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/AbstractRequestEvent.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/AbstractRetryableEvent.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/AbstractTransferEvent.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/BeforeEvent.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/CompleteEvent.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/Emitter.php CHANGED
@@ -43,8 +43,7 @@ class Emitter implements EmitterInterface
43
  public function once($eventName, callable $listener, $priority = 0)
44
  {
45
  $onceListener = function (
46
- EventInterface $event,
47
- $eventName
48
  ) use (&$onceListener, $eventName, $listener, $priority) {
49
  $this->removeListener($eventName, $onceListener);
50
  $listener($event, $eventName);
43
  public function once($eventName, callable $listener, $priority = 0)
44
  {
45
  $onceListener = function (
46
+ EventInterface $event
 
47
  ) use (&$onceListener, $eventName, $listener, $priority) {
48
  $this->removeListener($eventName, $onceListener);
49
  $listener($event, $eventName);
vendor/constantcontact/guzzlehttp/guzzle/src/Event/EmitterInterface.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/EndEvent.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/ErrorEvent.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/EventInterface.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/HasEmitterInterface.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/HasEmitterTrait.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/ListenerAttacherTrait.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/ProgressEvent.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/RequestEvents.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Event/SubscriberInterface.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Exception/BadResponseException.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Exception/ClientException.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Exception/ConnectException.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Exception/CouldNotRewindStreamException.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Exception/ParseException.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Exception/RequestException.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Exception/ServerException.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Exception/StateException.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Exception/TooManyRedirectsException.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Exception/TransferException.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Exception/XmlParseException.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/HasDataTrait.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Message/AbstractMessage.php CHANGED
@@ -107,7 +107,7 @@ abstract class AbstractMessage implements MessageInterface
107
  {
108
  $this->headers = $this->headerNames = [];
109
  foreach ($headers as $key => $value) {
110
- $this->setHeader($key, $value);
111
  }
112
  }
113
 
107
  {
108
  $this->headers = $this->headerNames = [];
109
  foreach ($headers as $key => $value) {
110
+ $this->addHeader($key, $value);
111
  }
112
  }
113
 
vendor/constantcontact/guzzlehttp/guzzle/src/Message/AppliesHeadersInterface.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Message/FutureResponse.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Message/MessageFactory.php CHANGED
@@ -87,7 +87,7 @@ class MessageFactory implements MessageFactoryInterface
87
  unset($options['config']);
88
 
89
  // Use a POST body by default
90
- if ($method == 'POST'
91
  && !isset($options['body'])
92
  && !isset($options['json'])
93
  ) {
87
  unset($options['config']);
88
 
89
  // Use a POST body by default
90
+ if (strtoupper($method) == 'POST'
91
  && !isset($options['body'])
92
  && !isset($options['json'])
93
  ) {
vendor/constantcontact/guzzlehttp/guzzle/src/Message/MessageFactoryInterface.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Message/MessageInterface.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Message/MessageParser.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Message/Request.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Message/RequestInterface.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Message/Response.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Message/ResponseInterface.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Mimetypes.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Pool.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Post/MultipartBody.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Post/PostBody.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Post/PostBodyInterface.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Post/PostFile.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Post/PostFileInterface.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Query.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/QueryParser.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/RequestFsm.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/RingBridge.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Subscriber/Cookie.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Subscriber/History.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Subscriber/HttpError.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Subscriber/Mock.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Subscriber/Prepare.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Subscriber/Redirect.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/ToArrayInterface.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Transaction.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/UriTemplate.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Url.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/src/Utils.php CHANGED
File without changes
vendor/constantcontact/guzzlehttp/guzzle/tests/BatchResultsTest.php DELETED
@@ -1,58 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests;
3
-
4
- use GuzzleHttp\BatchResults;
5
-
6
- /**
7
- * @covers \GuzzleHttp\BatchResults
8
- */
9
- class BatchResultsTest extends \PHPUnit_Framework_TestCase
10
- {
11
- public function testExposesResults()
12
- {
13
- $a = new \stdClass();
14
- $b = new \stdClass();
15
- $c = new \stdClass();
16
- $hash = new \SplObjectStorage();
17
- $hash[$a] = '1';
18
- $hash[$b] = '2';
19
- $hash[$c] = new \Exception('foo');
20
-
21
- $batch = new BatchResults($hash);
22
- $this->assertCount(3, $batch);
23
- $this->assertEquals([$a, $b, $c], $batch->getKeys());
24
- $this->assertEquals([$hash[$c]], $batch->getFailures());
25
- $this->assertEquals(['1', '2'], $batch->getSuccessful());
26
- $this->assertEquals('1', $batch->getResult($a));
27
- $this->assertNull($batch->getResult(new \stdClass()));
28
- $this->assertTrue(isset($batch[0]));
29
- $this->assertFalse(isset($batch[10]));
30
- $this->assertEquals('1', $batch[0]);
31
- $this->assertEquals('2', $batch[1]);
32
- $this->assertNull($batch[100]);
33
- $this->assertInstanceOf('Exception', $batch[2]);
34
-
35
- $results = iterator_to_array($batch);
36
- $this->assertEquals(['1', '2', $hash[$c]], $results);
37
- }
38
-
39
- /**
40
- * @expectedException \RuntimeException
41
- */
42
- public function testCannotSetByIndex()
43
- {
44
- $hash = new \SplObjectStorage();
45
- $batch = new BatchResults($hash);
46
- $batch[10] = 'foo';
47
- }
48
-
49
- /**
50
- * @expectedException \RuntimeException
51
- */
52
- public function testCannotUnsetByIndex()
53
- {
54
- $hash = new \SplObjectStorage();
55
- $batch = new BatchResults($hash);
56
- unset($batch[10]);
57
- }
58
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/ClientTest.php DELETED
@@ -1,647 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Event\BeforeEvent;
6
- use GuzzleHttp\Event\ErrorEvent;
7
- use GuzzleHttp\Message\MessageFactory;
8
- use GuzzleHttp\Message\Response;
9
- use GuzzleHttp\Exception\RequestException;
10
- use GuzzleHttp\Query;
11
- use GuzzleHttp\Ring\Client\MockHandler;
12
- use GuzzleHttp\Ring\Future\FutureArray;
13
- use GuzzleHttp\Subscriber\History;
14
- use GuzzleHttp\Subscriber\Mock;
15
- use GuzzleHttp\Url;
16
- use GuzzleHttp\Utils;
17
- use React\Promise\Deferred;
18
-
19
- /**
20
- * @covers GuzzleHttp\Client
21
- */
22
- class ClientTest extends \PHPUnit_Framework_TestCase
23
- {
24
- /** @callable */
25
- private $ma;
26
-
27
- public function setup()
28
- {
29
- $this->ma = function () {
30
- throw new \RuntimeException('Should not have been called.');
31
- };
32
- }
33
-
34
- public function testUsesDefaultDefaultOptions()
35
- {
36
- $client = new Client();
37
- $this->assertTrue($client->getDefaultOption('allow_redirects'));
38
- $this->assertTrue($client->getDefaultOption('exceptions'));
39
- $this->assertTrue($client->getDefaultOption('verify'));
40
- }
41
-
42
- public function testUsesProvidedDefaultOptions()
43
- {
44
- $client = new Client([
45
- 'defaults' => [
46
- 'allow_redirects' => false,
47
- 'query' => ['foo' => 'bar']
48
- ]
49
- ]);
50
- $this->assertFalse($client->getDefaultOption('allow_redirects'));
51
- $this->assertTrue($client->getDefaultOption('exceptions'));
52
- $this->assertTrue($client->getDefaultOption('verify'));
53
- $this->assertEquals(['foo' => 'bar'], $client->getDefaultOption('query'));
54
- }
55
-
56
- public function testCanSpecifyBaseUrl()
57
- {
58
- $this->assertSame('', (new Client())->getBaseUrl());
59
- $this->assertEquals('http://foo', (new Client([
60
- 'base_url' => 'http://foo'
61
- ]))->getBaseUrl());
62
- }
63
-
64
- public function testCanSpecifyBaseUrlUriTemplate()
65
- {
66
- $client = new Client(['base_url' => ['http://foo.com/{var}/', ['var' => 'baz']]]);
67
- $this->assertEquals('http://foo.com/baz/', $client->getBaseUrl());
68
- }
69
-
70
- /**
71
- * @expectedException \InvalidArgumentException
72
- */
73
- public function testValidatesUriTemplateValue()
74
- {
75
- new Client(['base_url' => ['http://foo.com/']]);
76
- }
77
-
78
- /**
79
- * @expectedException \Exception
80
- * @expectedExceptionMessage Foo
81
- */
82
- public function testCanSpecifyHandler()
83
- {
84
- $client = new Client(['handler' => function () {
85
- throw new \Exception('Foo');
86
- }]);
87
- $client->get('http://httpbin.org');
88
- }
89
-
90
- /**
91
- * @expectedException \Exception
92
- * @expectedExceptionMessage Foo
93
- */
94
- public function testCanSpecifyHandlerAsAdapter()
95
- {
96
- $client = new Client(['adapter' => function () {
97
- throw new \Exception('Foo');
98
- }]);
99
- $client->get('http://httpbin.org');
100
- }
101
-
102
- /**
103
- * @expectedException \Exception
104
- * @expectedExceptionMessage Foo
105
- */
106
- public function testCanSpecifyMessageFactory()
107
- {
108
- $factory = $this->getMockBuilder('GuzzleHttp\Message\MessageFactoryInterface')
109
- ->setMethods(['createRequest'])
110
- ->getMockForAbstractClass();
111
- $factory->expects($this->once())
112
- ->method('createRequest')
113
- ->will($this->throwException(new \Exception('Foo')));
114
- $client = new Client(['message_factory' => $factory]);
115
- $client->get();
116
- }
117
-
118
- public function testCanSpecifyEmitter()
119
- {
120
- $emitter = $this->getMockBuilder('GuzzleHttp\Event\EmitterInterface')
121
- ->setMethods(['listeners'])
122
- ->getMockForAbstractClass();
123
- $emitter->expects($this->once())
124
- ->method('listeners')
125
- ->will($this->returnValue('foo'));
126
-
127
- $client = new Client(['emitter' => $emitter]);
128
- $this->assertEquals('foo', $client->getEmitter()->listeners());
129
- }
130
-
131
- public function testAddsDefaultUserAgentHeaderWithDefaultOptions()
132
- {
133
- $client = new Client(['defaults' => ['allow_redirects' => false]]);
134
- $this->assertFalse($client->getDefaultOption('allow_redirects'));
135
- $this->assertEquals(
136
- ['User-Agent' => Utils::getDefaultUserAgent()],
137
- $client->getDefaultOption('headers')
138
- );
139
- }
140
-
141
- public function testAddsDefaultUserAgentHeaderWithoutDefaultOptions()
142
- {
143
- $client = new Client();
144
- $this->assertEquals(
145
- ['User-Agent' => Utils::getDefaultUserAgent()],
146
- $client->getDefaultOption('headers')
147
- );
148
- }
149
-
150
- private function getRequestClient()
151
- {
152
- $client = $this->getMockBuilder('GuzzleHttp\Client')
153
- ->setMethods(['send'])
154
- ->getMock();
155
- $client->expects($this->once())
156
- ->method('send')
157
- ->will($this->returnArgument(0));
158
-
159
- return $client;
160
- }
161
-
162
- public function requestMethodProvider()
163
- {
164
- return [
165
- ['GET', false],
166
- ['HEAD', false],
167
- ['DELETE', false],
168
- ['OPTIONS', false],
169
- ['POST', 'foo'],
170
- ['PUT', 'foo'],
171
- ['PATCH', 'foo']
172
- ];
173
- }
174
-
175
- /**
176
- * @dataProvider requestMethodProvider
177
- */
178
- public function testClientProvidesMethodShortcut($method, $body)
179
- {
180
- $client = $this->getRequestClient();
181
- if ($body) {
182
- $request = $client->{$method}('http://foo.com', [
183
- 'headers' => ['X-Baz' => 'Bar'],
184
- 'body' => $body,
185
- 'query' => ['a' => 'b']
186
- ]);
187
- } else {
188
- $request = $client->{$method}('http://foo.com', [
189
- 'headers' => ['X-Baz' => 'Bar'],
190
- 'query' => ['a' => 'b']
191
- ]);
192
- }
193
- $this->assertEquals($method, $request->getMethod());
194
- $this->assertEquals('Bar', $request->getHeader('X-Baz'));
195
- $this->assertEquals('a=b', $request->getQuery());
196
- if ($body) {
197
- $this->assertEquals($body, $request->getBody());
198
- }
199
- }
200
-
201
- public function testClientMergesDefaultOptionsWithRequestOptions()
202
- {
203
- $f = $this->getMockBuilder('GuzzleHttp\Message\MessageFactoryInterface')
204
- ->setMethods(array('createRequest'))
205
- ->getMockForAbstractClass();
206
-
207
- $o = null;
208
- // Intercept the creation
209
- $f->expects($this->once())
210
- ->method('createRequest')
211
- ->will($this->returnCallback(
212
- function ($method, $url, array $options = []) use (&$o) {
213
- $o = $options;
214
- return (new MessageFactory())->createRequest($method, $url, $options);
215
- }
216
- ));
217
-
218
- $client = new Client([
219
- 'message_factory' => $f,
220
- 'defaults' => [
221
- 'headers' => ['Foo' => 'Bar'],
222
- 'query' => ['baz' => 'bam'],
223
- 'exceptions' => false
224
- ]
225
- ]);
226
-
227
- $request = $client->createRequest('GET', 'http://foo.com?a=b', [
228
- 'headers' => ['Hi' => 'there', '1' => 'one'],
229
- 'allow_redirects' => false,
230
- 'query' => ['t' => 1]
231
- ]);
232
-
233
- $this->assertFalse($o['allow_redirects']);
234
- $this->assertFalse($o['exceptions']);
235
- $this->assertEquals('Bar', $request->getHeader('Foo'));
236
- $this->assertEquals('there', $request->getHeader('Hi'));
237
- $this->assertEquals('one', $request->getHeader('1'));
238
- $this->assertEquals('a=b&baz=bam&t=1', $request->getQuery());
239
- }
240
-
241
- public function testClientMergesDefaultHeadersCaseInsensitively()
242
- {
243
- $client = new Client(['defaults' => ['headers' => ['Foo' => 'Bar']]]);
244
- $request = $client->createRequest('GET', 'http://foo.com?a=b', [
245
- 'headers' => ['foo' => 'custom', 'user-agent' => 'test']
246
- ]);
247
- $this->assertEquals('test', $request->getHeader('User-Agent'));
248
- $this->assertEquals('custom', $request->getHeader('Foo'));
249
- }
250
-
251
- public function testCanOverrideDefaultOptionWithNull()
252
- {
253
- $client = new Client(['defaults' => ['proxy' => 'invalid!']]);
254
- $request = $client->createRequest('GET', 'http://foo.com?a=b', [
255
- 'proxy' => null
256
- ]);
257
- $this->assertFalse($request->getConfig()->hasKey('proxy'));
258
- }
259
-
260
- public function testDoesNotOverwriteExistingUA()
261
- {
262
- $client = new Client(['defaults' => [
263
- 'headers' => ['User-Agent' => 'test']
264
- ]]);
265
- $this->assertEquals(
266
- ['User-Agent' => 'test'],
267
- $client->getDefaultOption('headers')
268
- );
269
- }
270
-
271
- public function testUsesBaseUrlWhenNoUrlIsSet()
272
- {
273
- $client = new Client(['base_url' => 'http://www.foo.com/baz?bam=bar']);
274
- $this->assertEquals(
275
- 'http://www.foo.com/baz?bam=bar',
276
- $client->createRequest('GET')->getUrl()
277
- );
278
- }
279
-
280
- public function testUsesBaseUrlCombinedWithProvidedUrl()
281
- {
282
- $client = new Client(['base_url' => 'http://www.foo.com/baz?bam=bar']);
283
- $this->assertEquals(
284
- 'http://www.foo.com/bar/bam',
285
- $client->createRequest('GET', 'bar/bam')->getUrl()
286
- );
287
- }
288
-
289
- public function testFalsyPathsAreCombinedWithBaseUrl()
290
- {
291
- $client = new Client(['base_url' => 'http://www.foo.com/baz?bam=bar']);
292
- $this->assertEquals(
293
- 'http://www.foo.com/0',
294
- $client->createRequest('GET', '0')->getUrl()
295
- );
296
- }
297
-
298
- public function testUsesBaseUrlCombinedWithProvidedUrlViaUriTemplate()
299
- {
300
- $client = new Client(['base_url' => 'http://www.foo.com/baz?bam=bar']);
301
- $this->assertEquals(
302
- 'http://www.foo.com/bar/123',
303
- $client->createRequest('GET', ['bar/{bam}', ['bam' => '123']])->getUrl()
304
- );
305
- }
306
-
307
- public function testSettingAbsoluteUrlOverridesBaseUrl()
308
- {
309
- $client = new Client(['base_url' => 'http://www.foo.com/baz?bam=bar']);
310
- $this->assertEquals(
311
- 'http://www.foo.com/foo',
312
- $client->createRequest('GET', '/foo')->getUrl()
313
- );
314
- }
315
-
316
- public function testSettingAbsoluteUriTemplateOverridesBaseUrl()
317
- {
318
- $client = new Client(['base_url' => 'http://www.foo.com/baz?bam=bar']);
319
- $this->assertEquals(
320
- 'http://goo.com/1',
321
- $client->createRequest(
322
- 'GET',
323
- ['http://goo.com/{bar}', ['bar' => '1']]
324
- )->getUrl()
325
- );
326
- }
327
-
328
- public function testCanSetRelativeUrlStartingWithHttp()
329
- {
330
- $client = new Client(['base_url' => 'http://www.foo.com']);
331
- $this->assertEquals(
332
- 'http://www.foo.com/httpfoo',
333
- $client->createRequest('GET', 'httpfoo')->getUrl()
334
- );
335
- }
336
-
337
- /**
338
- * Test that base URLs ending with a slash are resolved as per RFC3986.
339
- *
340
- * @link http://tools.ietf.org/html/rfc3986#section-5.2.3
341
- */
342
- public function testMultipleSubdirectoryWithSlash()
343
- {
344
- $client = new Client(['base_url' => 'http://www.foo.com/bar/bam/']);
345
- $this->assertEquals(
346
- 'http://www.foo.com/bar/bam/httpfoo',
347
- $client->createRequest('GET', 'httpfoo')->getUrl()
348
- );
349
- }
350
-
351
- /**
352
- * Test that base URLs ending without a slash are resolved as per RFC3986.
353
- *
354
- * @link http://tools.ietf.org/html/rfc3986#section-5.2.3
355
- */
356
- public function testMultipleSubdirectoryNoSlash()
357
- {
358
- $client = new Client(['base_url' => 'http://www.foo.com/bar/bam']);
359
- $this->assertEquals(
360
- 'http://www.foo.com/bar/httpfoo',
361
- $client->createRequest('GET', 'httpfoo')->getUrl()
362
- );
363
- }
364
-
365
- public function testClientSendsRequests()
366
- {
367
- $mock = new MockHandler(['status' => 200, 'headers' => []]);
368
- $client = new Client(['handler' => $mock]);
369
- $response = $client->get('http://test.com');
370
- $this->assertEquals(200, $response->getStatusCode());
371
- $this->assertEquals('http://test.com', $response->getEffectiveUrl());
372
- }
373
-
374
- public function testSendingRequestCanBeIntercepted()
375
- {
376
- $response = new Response(200);
377
- $client = new Client(['handler' => $this->ma]);
378
- $client->getEmitter()->on(
379
- 'before',
380
- function (BeforeEvent $e) use ($response) {
381
- $e->intercept($response);
382
- }
383
- );
384
- $this->assertSame($response, $client->get('http://test.com'));
385
- $this->assertEquals('http://test.com', $response->getEffectiveUrl());
386
- }
387
-
388
- /**
389
- * @expectedException \GuzzleHttp\Exception\RequestException
390
- * @expectedExceptionMessage Argument 1 passed to GuzzleHttp\Message\FutureResponse::proxy() must implement interface GuzzleHttp\Ring\Future\FutureInterface
391
- */
392
- public function testEnsuresResponseIsPresentAfterSending()
393
- {
394
- $handler = function () {};
395
- $client = new Client(['handler' => $handler]);
396
- $client->get('http://httpbin.org');
397
- }
398
-
399
- /**
400
- * @expectedException \GuzzleHttp\Exception\RequestException
401
- * @expectedExceptionMessage Waiting did not resolve future
402
- */
403
- public function testEnsuresResponseIsPresentAfterDereferencing()
404
- {
405
- $deferred = new Deferred();
406
- $handler = new MockHandler(function () use ($deferred) {
407
- return new FutureArray(
408
- $deferred->promise(),
409
- function () {}
410
- );
411
- });
412
- $client = new Client(['handler' => $handler]);
413
- $response = $client->get('http://httpbin.org');
414
- $response->wait();
415
- }
416
-
417
- public function testClientHandlesErrorsDuringBeforeSend()
418
- {
419
- $client = new Client();
420
- $client->getEmitter()->on('before', function ($e) {
421
- throw new \Exception('foo');
422
- });
423
- $client->getEmitter()->on('error', function (ErrorEvent $e) {
424
- $e->intercept(new Response(200));
425
- });
426
- $this->assertEquals(
427
- 200,
428
- $client->get('http://test.com')->getStatusCode()
429
- );
430
- }
431
-
432
- /**
433
- * @expectedException \GuzzleHttp\Exception\RequestException
434
- * @expectedExceptionMessage foo
435
- */
436
- public function testClientHandlesErrorsDuringBeforeSendAndThrowsIfUnhandled()
437
- {
438
- $client = new Client();
439
- $client->getEmitter()->on('before', function (BeforeEvent $e) {
440
- throw new RequestException('foo', $e->getRequest());
441
- });
442
- $client->get('http://httpbin.org');
443
- }
444
-
445
- /**
446
- * @expectedException \GuzzleHttp\Exception\RequestException
447
- * @expectedExceptionMessage foo
448
- */
449
- public function testClientWrapsExceptions()
450
- {
451
- $client = new Client();
452
- $client->getEmitter()->on('before', function (BeforeEvent $e) {
453
- throw new \Exception('foo');
454
- });
455
- $client->get('http://httpbin.org');
456
- }
457
-
458
- public function testCanInjectResponseForFutureError()
459
- {
460
- $calledFuture = false;
461
- $deferred = new Deferred();
462
- $future = new FutureArray(
463
- $deferred->promise(),
464
- function () use ($deferred, &$calledFuture) {
465
- $calledFuture = true;
466
- $deferred->resolve(['error' => new \Exception('Noo!')]);
467
- }
468
- );
469
- $mock = new MockHandler($future);
470
- $client = new Client(['handler' => $mock]);
471
- $called = 0;
472
- $response = $client->get('http://localhost:123/foo', [
473
- 'future' => true,
474
- 'events' => [
475
- 'error' => function (ErrorEvent $e) use (&$called) {
476
- $called++;
477
- $e->intercept(new Response(200));
478
- }
479
- ]
480
- ]);
481
- $this->assertEquals(0, $called);
482
- $this->assertInstanceOf('GuzzleHttp\Message\FutureResponse', $response);
483
- $this->assertEquals(200, $response->getStatusCode());
484
- $this->assertTrue($calledFuture);
485
- $this->assertEquals(1, $called);
486
- }
487
-
488
- public function testCanReturnFutureResults()
489
- {
490
- $called = false;
491
- $deferred = new Deferred();
492
- $future = new FutureArray(
493
- $deferred->promise(),
494
- function () use ($deferred, &$called) {
495
- $called = true;
496
- $deferred->resolve(['status' => 201, 'headers' => []]);
497
- }
498
- );
499
- $mock = new MockHandler($future);
500
- $client = new Client(['handler' => $mock]);
501
- $response = $client->get('http://localhost:123/foo', ['future' => true]);
502
- $this->assertFalse($called);
503
- $this->assertInstanceOf('GuzzleHttp\Message\FutureResponse', $response);
504
- $this->assertEquals(201, $response->getStatusCode());
505
- $this->assertTrue($called);
506
- }
507
-
508
- public function testThrowsExceptionsWhenDereferenced()
509
- {
510
- $calledFuture = false;
511
- $deferred = new Deferred();
512
- $future = new FutureArray(
513
- $deferred->promise(),
514
- function () use ($deferred, &$calledFuture) {
515
- $calledFuture = true;
516
- $deferred->resolve(['error' => new \Exception('Noop!')]);
517
- }
518
- );
519
- $client = new Client(['handler' => new MockHandler($future)]);
520
- try {
521
- $res = $client->get('http://localhost:123/foo', ['future' => true]);
522
- $res->wait();
523
- $this->fail('Did not throw');
524
- } catch (RequestException $e) {
525
- $this->assertEquals(1, $calledFuture);
526
- }
527
- }
528
-
529
- /**
530
- * @expectedExceptionMessage Noo!
531
- * @expectedException \GuzzleHttp\Exception\RequestException
532
- */
533
- public function testThrowsExceptionsSynchronously()
534
- {
535
- $client = new Client([
536
- 'handler' => new MockHandler(['error' => new \Exception('Noo!')])
537
- ]);
538
- $client->get('http://localhost:123/foo');
539
- }
540
-
541
- public function testCanSetDefaultValues()
542
- {
543
- $client = new Client(['foo' => 'bar']);
544
- $client->setDefaultOption('headers/foo', 'bar');
545
- $this->assertNull($client->getDefaultOption('foo'));
546
- $this->assertEquals('bar', $client->getDefaultOption('headers/foo'));
547
- }
548
-
549
- public function testSendsAllInParallel()
550
- {
551
- $client = new Client();
552
- $client->getEmitter()->attach(new Mock([
553
- new Response(200),
554
- new Response(201),
555
- new Response(202),
556
- ]));
557
- $history = new History();
558
- $client->getEmitter()->attach($history);
559
-
560
- $requests = [
561
- $client->createRequest('GET', 'http://test.com'),
562
- $client->createRequest('POST', 'http://test.com'),
563
- $client->createRequest('PUT', 'http://test.com')
564
- ];
565
-
566
- $client->sendAll($requests);
567
- $requests = array_map(function($r) {
568
- return $r->getMethod();
569
- }, $history->getRequests());
570
- $this->assertContains('GET', $requests);
571
- $this->assertContains('POST', $requests);
572
- $this->assertContains('PUT', $requests);
573
- }
574
-
575
- public function testCanDisableAuthPerRequest()
576
- {
577
- $client = new Client(['defaults' => ['auth' => 'foo']]);
578
- $request = $client->createRequest('GET', 'http://test.com');
579
- $this->assertEquals('foo', $request->getConfig()['auth']);
580
- $request = $client->createRequest('GET', 'http://test.com', ['auth' => null]);
581
- $this->assertFalse($request->getConfig()->hasKey('auth'));
582
- }
583
-
584
- public function testUsesProxyEnvironmentVariables()
585
- {
586
- $http = getenv('HTTP_PROXY');
587
- $https = getenv('HTTPS_PROXY');
588
-
589
- $client = new Client();
590
- $this->assertNull($client->getDefaultOption('proxy'));
591
-
592
- putenv('HTTP_PROXY=127.0.0.1');
593
- $client = new Client();
594
- $this->assertEquals(
595
- ['http' => '127.0.0.1'],
596
- $client->getDefaultOption('proxy')
597
- );
598
-
599
- putenv('HTTPS_PROXY=127.0.0.2');
600
- $client = new Client();
601
- $this->assertEquals(
602
- ['http' => '127.0.0.1', 'https' => '127.0.0.2'],
603
- $client->getDefaultOption('proxy')
604
- );
605
-
606
- putenv("HTTP_PROXY=$http");
607
- putenv("HTTPS_PROXY=$https");
608
- }
609
-
610
- public function testReturnsFutureForErrorWhenRequested()
611
- {
612
- $client = new Client(['handler' => new MockHandler(['status' => 404])]);
613
- $request = $client->createRequest('GET', 'http://localhost:123/foo', [
614
- 'future' => true
615
- ]);
616
- $res = $client->send($request);
617
- $this->assertInstanceOf('GuzzleHttp\Message\FutureResponse', $res);
618
- try {
619
- $res->wait();
620
- $this->fail('did not throw');
621
- } catch (RequestException $e) {
622
- $this->assertContains('404', $e->getMessage());
623
- }
624
- }
625
-
626
- public function testReturnsFutureForResponseWhenRequested()
627
- {
628
- $client = new Client(['handler' => new MockHandler(['status' => 200])]);
629
- $request = $client->createRequest('GET', 'http://localhost:123/foo', [
630
- 'future' => true
631
- ]);
632
- $res = $client->send($request);
633
- $this->assertInstanceOf('GuzzleHttp\Message\FutureResponse', $res);
634
- $this->assertEquals(200, $res->getStatusCode());
635
- }
636
-
637
- public function testCanUseUrlWithCustomQuery()
638
- {
639
- $client = new Client();
640
- $url = Url::fromString('http://foo.com/bar');
641
- $query = new Query(['baz' => '123%20']);
642
- $query->setEncodingType(false);
643
- $url->setQuery($query);
644
- $r = $client->createRequest('GET', $url);
645
- $this->assertEquals('http://foo.com/bar?baz=123%20', $r->getUrl());
646
- }
647
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/CollectionTest.php DELETED
@@ -1,416 +0,0 @@
1
- <?php
2
-
3
- namespace GuzzleHttp\Tests;
4
-
5
- use GuzzleHttp\Collection;
6
-
7
- class CollectionTest extends \PHPUnit_Framework_TestCase
8
- {
9
- /** @var Collection */
10
- protected $coll;
11
-
12
- protected function setUp()
13
- {
14
- $this->coll = new Collection();
15
- }
16
-
17
- public function testConstructorCanBeCalledWithNoParams()
18
- {
19
- $this->coll = new Collection();
20
- $p = $this->coll->toArray();
21
- $this->assertEmpty($p, '-> Collection must be empty when no data is passed');
22
- }
23
-
24
- public function testConstructorCanBeCalledWithParams()
25
- {
26
- $testData = array(
27
- 'test' => 'value',
28
- 'test_2' => 'value2'
29
- );
30
- $this->coll = new Collection($testData);
31
- $this->assertEquals($this->coll->toArray(), $testData);
32
- $this->assertEquals($this->coll->toArray(), $this->coll->toArray());
33
- }
34
-
35
- public function testImplementsIteratorAggregate()
36
- {
37
- $this->coll->set('key', 'value');
38
- $this->assertInstanceOf('ArrayIterator', $this->coll->getIterator());
39
- $this->assertEquals(1, count($this->coll));
40
- $total = 0;
41
- foreach ($this->coll as $key => $value) {
42
- $this->assertEquals('key', $key);
43
- $this->assertEquals('value', $value);
44
- $total++;
45
- }
46
- $this->assertEquals(1, $total);
47
- }
48
-
49
- public function testCanAddValuesToExistingKeysByUsingArray()
50
- {
51
- $this->coll->add('test', 'value1');
52
- $this->assertEquals($this->coll->toArray(), array('test' => 'value1'));
53
- $this->coll->add('test', 'value2');
54
- $this->assertEquals($this->coll->toArray(), array('test' => array('value1', 'value2')));
55
- $this->coll->add('test', 'value3');
56
- $this->assertEquals($this->coll->toArray(), array('test' => array('value1', 'value2', 'value3')));
57
- }
58
-
59
- public function testHandlesMergingInDisparateDataSources()
60
- {
61
- $params = array(
62
- 'test' => 'value1',
63
- 'test2' => 'value2',
64
- 'test3' => array('value3', 'value4')
65
- );
66
- $this->coll->merge($params);
67
- $this->assertEquals($this->coll->toArray(), $params);
68
- $this->coll->merge(new Collection(['test4' => 'hi']));
69
- $this->assertEquals(
70
- $this->coll->toArray(),
71
- $params + ['test4' => 'hi']
72
- );
73
- }
74
-
75
- public function testCanClearAllDataOrSpecificKeys()
76
- {
77
- $this->coll->merge(array(
78
- 'test' => 'value1',
79
- 'test2' => 'value2'
80
- ));
81
-
82
- // Clear a specific parameter by name
83
- $this->coll->remove('test');
84
-
85
- $this->assertEquals($this->coll->toArray(), array(
86
- 'test2' => 'value2'
87
- ));
88
-
89
- // Clear all parameters
90
- $this->coll->clear();
91
-
92
- $this->assertEquals($this->coll->toArray(), array());
93
- }
94
-
95
- public function testProvidesKeys()
96
- {
97
- $this->assertEquals(array(), $this->coll->getKeys());
98
- $this->coll->merge(array(
99
- 'test1' => 'value1',
100
- 'test2' => 'value2'
101
- ));
102
- $this->assertEquals(array('test1', 'test2'), $this->coll->getKeys());
103
- // Returns the cached array previously returned
104
- $this->assertEquals(array('test1', 'test2'), $this->coll->getKeys());
105
- $this->coll->remove('test1');
106
- $this->assertEquals(array('test2'), $this->coll->getKeys());
107
- $this->coll->add('test3', 'value3');
108
- $this->assertEquals(array('test2', 'test3'), $this->coll->getKeys());
109
- }
110
-
111
- public function testChecksIfHasKey()
112
- {
113
- $this->assertFalse($this->coll->hasKey('test'));
114
- $this->coll->add('test', 'value');
115
- $this->assertEquals(true, $this->coll->hasKey('test'));
116
- $this->coll->add('test2', 'value2');
117
- $this->assertEquals(true, $this->coll->hasKey('test'));
118
- $this->assertEquals(true, $this->coll->hasKey('test2'));
119
- $this->assertFalse($this->coll->hasKey('testing'));
120
- $this->assertEquals(false, $this->coll->hasKey('AB-C', 'junk'));
121
- }
122
-
123
- public function testChecksIfHasValue()
124
- {
125
- $this->assertFalse($this->coll->hasValue('value'));
126
- $this->coll->add('test', 'value');
127
- $this->assertEquals('test', $this->coll->hasValue('value'));
128
- $this->coll->add('test2', 'value2');
129
- $this->assertEquals('test', $this->coll->hasValue('value'));
130
- $this->assertEquals('test2', $this->coll->hasValue('value2'));
131
- $this->assertFalse($this->coll->hasValue('val'));
132
- }
133
-
134
- public function testImplementsCount()
135
- {
136
- $data = new Collection();
137
- $this->assertEquals(0, $data->count());
138
- $data->add('key', 'value');
139
- $this->assertEquals(1, count($data));
140
- $data->add('key', 'value2');
141
- $this->assertEquals(1, count($data));
142
- $data->add('key_2', 'value3');
143
- $this->assertEquals(2, count($data));
144
- }
145
-
146
- public function testAddParamsByMerging()
147
- {
148
- $params = array(
149
- 'test' => 'value1',
150
- 'test2' => 'value2',
151
- 'test3' => array('value3', 'value4')
152
- );
153
-
154
- // Add some parameters
155
- $this->coll->merge($params);
156
-
157
- // Add more parameters by merging them in
158
- $this->coll->merge(array(
159
- 'test' => 'another',
160
- 'different_key' => 'new value'
161
- ));
162
-
163
- $this->assertEquals(array(
164
- 'test' => array('value1', 'another'),
165
- 'test2' => 'value2',
166
- 'test3' => array('value3', 'value4'),
167
- 'different_key' => 'new value'
168
- ), $this->coll->toArray());
169
- }
170
-
171
- public function testAllowsFunctionalFilter()
172
- {
173
- $this->coll->merge(array(
174
- 'fruit' => 'apple',
175
- 'number' => 'ten',
176
- 'prepositions' => array('about', 'above', 'across', 'after'),
177
- 'same_number' => 'ten'
178
- ));
179
-
180
- $filtered = $this->coll->filter(function ($key, $value) {
181
- return $value == 'ten';
182
- });
183
-
184
- $this->assertNotSame($filtered, $this->coll);
185
-
186
- $this->assertEquals(array(
187
- 'number' => 'ten',
188
- 'same_number' => 'ten'
189
- ), $filtered->toArray());
190
- }
191
-
192
- public function testAllowsFunctionalMapping()
193
- {
194
- $this->coll->merge(array(
195
- 'number_1' => 1,
196
- 'number_2' => 2,
197
- 'number_3' => 3
198
- ));
199
-
200
- $mapped = $this->coll->map(function ($key, $value) {
201
- return $value * $value;
202
- });
203
-
204
- $this->assertNotSame($mapped, $this->coll);
205
-
206
- $this->assertEquals(array(
207
- 'number_1' => 1,
208
- 'number_2' => 4,
209
- 'number_3' => 9
210
- ), $mapped->toArray());
211
- }
212
-
213
- public function testImplementsArrayAccess()
214
- {
215
- $this->coll->merge(array(
216
- 'k1' => 'v1',
217
- 'k2' => 'v2'
218
- ));
219
-
220
- $this->assertTrue($this->coll->offsetExists('k1'));
221
- $this->assertFalse($this->coll->offsetExists('Krull'));
222
-
223
- $this->coll->offsetSet('k3', 'v3');
224
- $this->assertEquals('v3', $this->coll->offsetGet('k3'));
225
- $this->assertEquals('v3', $this->coll->get('k3'));
226
-
227
- $this->coll->offsetUnset('k1');
228
- $this->assertFalse($this->coll->offsetExists('k1'));
229
- }
230
-
231
- public function testCanReplaceAllData()
232
- {
233
- $this->coll->replace(array('a' => '123'));
234
- $this->assertEquals(array('a' => '123'), $this->coll->toArray());
235
- }
236
-
237
- public function testPreparesFromConfig()
238
- {
239
- $c = Collection::fromConfig(array(
240
- 'a' => '123',
241
- 'base_url' => 'http://www.test.com/'
242
- ), array(
243
- 'a' => 'xyz',
244
- 'b' => 'lol'
245
- ), array('a'));
246
-
247
- $this->assertInstanceOf('GuzzleHttp\Collection', $c);
248
- $this->assertEquals(array(
249
- 'a' => '123',
250
- 'b' => 'lol',
251
- 'base_url' => 'http://www.test.com/'
252
- ), $c->toArray());
253
-
254
- try {
255
- Collection::fromConfig(array(), array(), array('a'));
256
- $this->fail('Exception not throw when missing config');
257
- } catch (\InvalidArgumentException $e) {
258
- }
259
- }
260
-
261
- function falseyDataProvider()
262
- {
263
- return array(
264
- array(false, false),
265
- array(null, null),
266
- array('', ''),
267
- array(array(), array()),
268
- array(0, 0),
269
- );
270
- }
271
-
272
- /**
273
- * @dataProvider falseyDataProvider
274
- */
275
- public function testReturnsCorrectData($a, $b)
276
- {
277
- $c = new Collection(array('value' => $a));
278
- $this->assertSame($b, $c->get('value'));
279
- }
280
-
281
- public function testRetrievesNestedKeysUsingPath()
282
- {
283
- $data = array(
284
- 'foo' => 'bar',
285
- 'baz' => array(
286
- 'mesa' => array(
287
- 'jar' => 'jar'
288
- )
289
- )
290
- );
291
- $collection = new Collection($data);
292
- $this->assertEquals('bar', $collection->getPath('foo'));
293
- $this->assertEquals('jar', $collection->getPath('baz/mesa/jar'));
294
- $this->assertNull($collection->getPath('wewewf'));
295
- $this->assertNull($collection->getPath('baz/mesa/jar/jar'));
296
- }
297
-
298
- public function testFalseyKeysStillDescend()
299
- {
300
- $collection = new Collection(array(
301
- '0' => array(
302
- 'a' => 'jar'
303
- ),
304
- 1 => 'other'
305
- ));
306
- $this->assertEquals('jar', $collection->getPath('0/a'));
307
- $this->assertEquals('other', $collection->getPath('1'));
308
- }
309
-
310
- public function getPathProvider()
311
- {
312
- $data = array(
313
- 'foo' => 'bar',
314
- 'baz' => array(
315
- 'mesa' => array(
316
- 'jar' => 'jar',
317
- 'array' => array('a', 'b', 'c')
318
- ),
319
- 'bar' => array(
320
- 'baz' => 'bam',
321
- 'array' => array('d', 'e', 'f')
322
- )
323
- ),
324
- 'bam' => array(
325
- array('foo' => 1),
326
- array('foo' => 2),
327
- array('array' => array('h', 'i'))
328
- )
329
- );
330
- $c = new Collection($data);
331
-
332
- return array(
333
- // Simple path selectors
334
- array($c, 'foo', 'bar'),
335
- array($c, 'baz', $data['baz']),
336
- array($c, 'bam', $data['bam']),
337
- array($c, 'baz/mesa', $data['baz']['mesa']),
338
- array($c, 'baz/mesa/jar', 'jar'),
339
- // Does not barf on missing keys
340
- array($c, 'fefwfw', null),
341
- array($c, 'baz/mesa/array', $data['baz']['mesa']['array'])
342
- );
343
- }
344
-
345
- /**
346
- * @dataProvider getPathProvider
347
- */
348
- public function testGetPath(Collection $c, $path, $expected, $separator = '/')
349
- {
350
- $this->assertEquals($expected, $c->getPath($path, $separator));
351
- }
352
-
353
- public function testOverridesSettings()
354
- {
355
- $c = new Collection(array('foo' => 1, 'baz' => 2, 'bar' => 3));
356
- $c->overwriteWith(array('foo' => 10, 'bar' => 300));
357
- $this->assertEquals(array('foo' => 10, 'baz' => 2, 'bar' => 300), $c->toArray());
358
- }
359
-
360
- public function testOverwriteWithCollection()
361
- {
362
- $c = new Collection(array('foo' => 1, 'baz' => 2, 'bar' => 3));
363
- $b = new Collection(array('foo' => 10, 'bar' => 300));
364
- $c->overwriteWith($b);
365
- $this->assertEquals(array('foo' => 10, 'baz' => 2, 'bar' => 300), $c->toArray());
366
- }
367
-
368
- public function testOverwriteWithTraversable()
369
- {
370
- $c = new Collection(array('foo' => 1, 'baz' => 2, 'bar' => 3));
371
- $b = new Collection(array('foo' => 10, 'bar' => 300));
372
- $c->overwriteWith($b->getIterator());
373
- $this->assertEquals(array('foo' => 10, 'baz' => 2, 'bar' => 300), $c->toArray());
374
- }
375
-
376
- public function testCanSetNestedPathValueThatDoesNotExist()
377
- {
378
- $c = new Collection(array());
379
- $c->setPath('foo/bar/baz/123', 'hi');
380
- $this->assertEquals('hi', $c['foo']['bar']['baz']['123']);
381
- }
382
-
383
- public function testCanSetNestedPathValueThatExists()
384
- {
385
- $c = new Collection(array('foo' => array('bar' => 'test')));
386
- $c->setPath('foo/bar', 'hi');
387
- $this->assertEquals('hi', $c['foo']['bar']);
388
- }
389
-
390
- /**
391
- * @expectedException \RuntimeException
392
- */
393
- public function testVerifiesNestedPathIsValidAtExactLevel()
394
- {
395
- $c = new Collection(array('foo' => 'bar'));
396
- $c->setPath('foo/bar', 'hi');
397
- $this->assertEquals('hi', $c['foo']['bar']);
398
- }
399
-
400
- /**
401
- * @expectedException \RuntimeException
402
- */
403
- public function testVerifiesThatNestedPathIsValidAtAnyLevel()
404
- {
405
- $c = new Collection(array('foo' => 'bar'));
406
- $c->setPath('foo/bar/baz', 'test');
407
- }
408
-
409
- public function testCanAppendToNestedPathValues()
410
- {
411
- $c = new Collection();
412
- $c->setPath('foo/bar/[]', 'a');
413
- $c->setPath('foo/bar/[]', 'b');
414
- $this->assertEquals(['a', 'b'], $c['foo']['bar']);
415
- }
416
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Cookie/CookieJarTest.php DELETED
@@ -1,339 +0,0 @@
1
- <?php
2
-
3
- namespace GuzzleHttp\Tests\CookieJar;
4
-
5
- use GuzzleHttp\Cookie\CookieJar;
6
- use GuzzleHttp\Cookie\SetCookie;
7
- use GuzzleHttp\Message\Request;
8
- use GuzzleHttp\Message\Response;
9
-
10
- /**
11
- * @covers GuzzleHttp\Cookie\CookieJar
12
- */
13
- class CookieJarTest extends \PHPUnit_Framework_TestCase
14
- {
15
- /** @var CookieJar */
16
- private $jar;
17
-
18
- public function setUp()
19
- {
20
- $this->jar = new CookieJar();
21
- }
22
-
23
- protected function getTestCookies()
24
- {
25
- return [
26
- new SetCookie(['Name' => 'foo', 'Value' => 'bar', 'Domain' => 'foo.com', 'Path' => '/', 'Discard' => true]),
27
- new SetCookie(['Name' => 'test', 'Value' => '123', 'Domain' => 'baz.com', 'Path' => '/foo', 'Expires' => 2]),
28
- new SetCookie(['Name' => 'you', 'Value' => '123', 'Domain' => 'bar.com', 'Path' => '/boo', 'Expires' => time() + 1000])
29
- ];
30
- }
31
-
32
- public function testQuotesBadCookieValues()
33
- {
34
- $this->assertEquals('foo', CookieJar::getCookieValue('foo'));
35
- $this->assertEquals('"foo,bar"', CookieJar::getCookieValue('foo,bar'));
36
- }
37
-
38
- public function testCreatesFromArray()
39
- {
40
- $jar = CookieJar::fromArray([
41
- 'foo' => 'bar',
42
- 'baz' => 'bam'
43
- ], 'example.com');
44
- $this->assertCount(2, $jar);
45
- }
46
-
47
- /**
48
- * Provides test data for cookie cookieJar retrieval
49
- */
50
- public function getCookiesDataProvider()
51
- {
52
- return [
53
- [['foo', 'baz', 'test', 'muppet', 'googoo'], '', '', '', false],
54
- [['foo', 'baz', 'muppet', 'googoo'], '', '', '', true],
55
- [['googoo'], 'www.example.com', '', '', false],
56
- [['muppet', 'googoo'], 'test.y.example.com', '', '', false],
57
- [['foo', 'baz'], 'example.com', '', '', false],
58
- [['muppet'], 'x.y.example.com', '/acme/', '', false],
59
- [['muppet'], 'x.y.example.com', '/acme/test/', '', false],
60
- [['googoo'], 'x.y.example.com', '/test/acme/test/', '', false],
61
- [['foo', 'baz'], 'example.com', '', '', false],
62
- [['baz'], 'example.com', '', 'baz', false],
63
- ];
64
- }
65
-
66
- public function testStoresAndRetrievesCookies()
67
- {
68
- $cookies = $this->getTestCookies();
69
- foreach ($cookies as $cookie) {
70
- $this->assertTrue($this->jar->setCookie($cookie));
71
- }
72
-
73
- $this->assertEquals(3, count($this->jar));
74
- $this->assertEquals(3, count($this->jar->getIterator()));
75
- $this->assertEquals($cookies, $this->jar->getIterator()->getArrayCopy());
76
- }
77
-
78
- public function testRemovesTemporaryCookies()
79
- {
80
- $cookies = $this->getTestCookies();
81
- foreach ($this->getTestCookies() as $cookie) {
82
- $this->jar->setCookie($cookie);
83
- }
84
- $this->jar->clearSessionCookies();
85
- $this->assertEquals(
86
- [$cookies[1], $cookies[2]],
87
- $this->jar->getIterator()->getArrayCopy()
88
- );
89
- }
90
-
91
- public function testRemovesSelectively()
92
- {
93
- foreach ($this->getTestCookies() as $cookie) {
94
- $this->jar->setCookie($cookie);
95
- }
96
-
97
- // Remove foo.com cookies
98
- $this->jar->clear('foo.com');
99
- $this->assertEquals(2, count($this->jar));
100
- // Try again, removing no further cookies
101
- $this->jar->clear('foo.com');
102
- $this->assertEquals(2, count($this->jar));
103
-
104
- // Remove bar.com cookies with path of /boo
105
- $this->jar->clear('bar.com', '/boo');
106
- $this->assertEquals(1, count($this->jar));
107
-
108
- // Remove cookie by name
109
- $this->jar->clear(null, null, 'test');
110
- $this->assertEquals(0, count($this->jar));
111
- }
112
-
113
- public function testDoesNotAddIncompleteCookies()
114
- {
115
- $this->assertEquals(false, $this->jar->setCookie(new SetCookie()));
116
- $this->assertFalse($this->jar->setCookie(new SetCookie(array(
117
- 'Name' => 'foo'
118
- ))));
119
- $this->assertFalse($this->jar->setCookie(new SetCookie(array(
120
- 'Name' => false
121
- ))));
122
- $this->assertFalse($this->jar->setCookie(new SetCookie(array(
123
- 'Name' => true
124
- ))));
125
- $this->assertFalse($this->jar->setCookie(new SetCookie(array(
126
- 'Name' => 'foo',
127
- 'Domain' => 'foo.com'
128
- ))));
129
- }
130
-
131
- public function testDoesAddValidCookies()
132
- {
133
- $this->assertTrue($this->jar->setCookie(new SetCookie(array(
134
- 'Name' => 'foo',
135
- 'Domain' => 'foo.com',
136
- 'Value' => 0
137
- ))));
138
- $this->assertTrue($this->jar->setCookie(new SetCookie(array(
139
- 'Name' => 'foo',
140
- 'Domain' => 'foo.com',
141
- 'Value' => 0.0
142
- ))));
143
- $this->assertTrue($this->jar->setCookie(new SetCookie(array(
144
- 'Name' => 'foo',
145
- 'Domain' => 'foo.com',
146
- 'Value' => '0'
147
- ))));
148
- }
149
-
150
- public function testOverwritesCookiesThatAreOlderOrDiscardable()
151
- {
152
- $t = time() + 1000;
153
- $data = array(
154
- 'Name' => 'foo',
155
- 'Value' => 'bar',
156
- 'Domain' => '.example.com',
157
- 'Path' => '/',
158
- 'Max-Age' => '86400',
159
- 'Secure' => true,
160
- 'Discard' => true,
161
- 'Expires' => $t
162
- );
163
-
164
- // Make sure that the discard cookie is overridden with the non-discard
165
- $this->assertTrue($this->jar->setCookie(new SetCookie($data)));
166
- $this->assertEquals(1, count($this->jar));
167
-
168
- $data['Discard'] = false;
169
- $this->assertTrue($this->jar->setCookie(new SetCookie($data)));
170
- $this->assertEquals(1, count($this->jar));
171
-
172
- $c = $this->jar->getIterator()->getArrayCopy();
173
- $this->assertEquals(false, $c[0]->getDiscard());
174
-
175
- // Make sure it doesn't duplicate the cookie
176
- $this->jar->setCookie(new SetCookie($data));
177
- $this->assertEquals(1, count($this->jar));
178
-
179
- // Make sure the more future-ful expiration date supersede the other
180
- $data['Expires'] = time() + 2000;
181
- $this->assertTrue($this->jar->setCookie(new SetCookie($data)));
182
- $this->assertEquals(1, count($this->jar));
183
- $c = $this->jar->getIterator()->getArrayCopy();
184
- $this->assertNotEquals($t, $c[0]->getExpires());
185
- }
186
-
187
- public function testOverwritesCookiesThatHaveChanged()
188
- {
189
- $t = time() + 1000;
190
- $data = array(
191
- 'Name' => 'foo',
192
- 'Value' => 'bar',
193
- 'Domain' => '.example.com',
194
- 'Path' => '/',
195
- 'Max-Age' => '86400',
196
- 'Secure' => true,
197
- 'Discard' => true,
198
- 'Expires' => $t
199
- );
200
-
201
- // Make sure that the discard cookie is overridden with the non-discard
202
- $this->assertTrue($this->jar->setCookie(new SetCookie($data)));
203
-
204
- $data['Value'] = 'boo';
205
- $this->assertTrue($this->jar->setCookie(new SetCookie($data)));
206
- $this->assertEquals(1, count($this->jar));
207
-
208
- // Changing the value plus a parameter also must overwrite the existing one
209
- $data['Value'] = 'zoo';
210
- $data['Secure'] = false;
211
- $this->assertTrue($this->jar->setCookie(new SetCookie($data)));
212
- $this->assertEquals(1, count($this->jar));
213
-
214
- $c = $this->jar->getIterator()->getArrayCopy();
215
- $this->assertEquals('zoo', $c[0]->getValue());
216
- }
217
-
218
- public function testAddsCookiesFromResponseWithRequest()
219
- {
220
- $response = new Response(200, array(
221
- 'Set-Cookie' => "fpc=d=.Hm.yh4.1XmJWjJfs4orLQzKzPImxklQoxXSHOZATHUSEFciRueW_7704iYUtsXNEXq0M92Px2glMdWypmJ7HIQl6XIUvrZimWjQ3vIdeuRbI.FNQMAfcxu_XN1zSx7l.AcPdKL6guHc2V7hIQFhnjRW0rxm2oHY1P4bGQxFNz7f.tHm12ZD3DbdMDiDy7TBXsuP4DM-&v=2; expires=Fri, 02-Mar-2019 02:17:40 GMT;"
222
- ));
223
- $request = new Request('GET', 'http://www.example.com');
224
- $this->jar->extractCookies($request, $response);
225
- $this->assertEquals(1, count($this->jar));
226
- }
227
-
228
- public function getMatchingCookiesDataProvider()
229
- {
230
- return array(
231
- array('https://example.com', 'foo=bar; baz=foobar'),
232
- array('http://example.com', ''),
233
- array('https://example.com:8912', 'foo=bar; baz=foobar'),
234
- array('https://foo.example.com', 'foo=bar; baz=foobar'),
235
- array('http://foo.example.com/test/acme/', 'googoo=gaga')
236
- );
237
- }
238
-
239
- /**
240
- * @dataProvider getMatchingCookiesDataProvider
241
- */
242
- public function testReturnsCookiesMatchingRequests($url, $cookies)
243
- {
244
- $bag = [
245
- new SetCookie([
246
- 'Name' => 'foo',
247
- 'Value' => 'bar',
248
- 'Domain' => 'example.com',
249
- 'Path' => '/',
250
- 'Max-Age' => '86400',
251
- 'Secure' => true
252
- ]),
253
- new SetCookie([
254
- 'Name' => 'baz',
255
- 'Value' => 'foobar',
256
- 'Domain' => 'example.com',
257
- 'Path' => '/',
258
- 'Max-Age' => '86400',
259
- 'Secure' => true
260
- ]),
261
- new SetCookie([
262
- 'Name' => 'test',
263
- 'Value' => '123',
264
- 'Domain' => 'www.foobar.com',
265
- 'Path' => '/path/',
266
- 'Discard' => true
267
- ]),
268
- new SetCookie([
269
- 'Name' => 'muppet',
270
- 'Value' => 'cookie_monster',
271
- 'Domain' => '.y.example.com',
272
- 'Path' => '/acme/',
273
- 'Expires' => time() + 86400
274
- ]),
275
- new SetCookie([
276
- 'Name' => 'googoo',
277
- 'Value' => 'gaga',
278
- 'Domain' => '.example.com',
279
- 'Path' => '/test/acme/',
280
- 'Max-Age' => 1500
281
- ])
282
- ];
283
-
284
- foreach ($bag as $cookie) {
285
- $this->jar->setCookie($cookie);
286
- }
287
-
288
- $request = new Request('GET', $url);
289
- $this->jar->addCookieHeader($request);
290
- $this->assertEquals($cookies, $request->getHeader('Cookie'));
291
- }
292
-
293
- /**
294
- * @expectedException \RuntimeException
295
- * @expectedExceptionMessage Invalid cookie: Cookie name must not cannot invalid characters:
296
- */
297
- public function testThrowsExceptionWithStrictMode()
298
- {
299
- $a = new CookieJar(true);
300
- $a->setCookie(new SetCookie(['Name' => "abc\n", 'Value' => 'foo', 'Domain' => 'bar']));
301
- }
302
-
303
- public function testDeletesCookiesByName()
304
- {
305
- $cookies = $this->getTestCookies();
306
- $cookies[] = new SetCookie([
307
- 'Name' => 'other',
308
- 'Value' => '123',
309
- 'Domain' => 'bar.com',
310
- 'Path' => '/boo',
311
- 'Expires' => time() + 1000
312
- ]);
313
- $jar = new CookieJar();
314
- foreach ($cookies as $cookie) {
315
- $jar->setCookie($cookie);
316
- }
317
- $this->assertCount(4, $jar);
318
- $jar->clear('bar.com', '/boo', 'other');
319
- $this->assertCount(3, $jar);
320
- $names = array_map(function (SetCookie $c) {
321
- return $c->getName();
322
- }, $jar->getIterator()->getArrayCopy());
323
- $this->assertEquals(['foo', 'test', 'you'], $names);
324
- }
325
-
326
- public function testCanConvertToAndLoadFromArray()
327
- {
328
- $jar = new CookieJar(true);
329
- foreach ($this->getTestCookies() as $cookie) {
330
- $jar->setCookie($cookie);
331
- }
332
- $this->assertCount(3, $jar);
333
- $arr = $jar->toArray();
334
- $this->assertCount(3, $arr);
335
- $newCookieJar = new CookieJar(false, $arr);
336
- $this->assertCount(3, $newCookieJar);
337
- $this->assertSame($jar->toArray(), $newCookieJar->toArray());
338
- }
339
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Cookie/FileCookieJarTest.php DELETED
@@ -1,71 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\CookieJar;
3
-
4
- use GuzzleHttp\Cookie\FileCookieJar;
5
- use GuzzleHttp\Cookie\SetCookie;
6
-
7
- /**
8
- * @covers GuzzleHttp\Cookie\FileCookieJar
9
- */
10
- class FileCookieJarTest extends \PHPUnit_Framework_TestCase
11
- {
12
- private $file;
13
-
14
- public function setUp()
15
- {
16
- $this->file = tempnam('/tmp', 'file-cookies');
17
- }
18
-
19
- /**
20
- * @expectedException \RuntimeException
21
- */
22
- public function testValidatesCookieFile()
23
- {
24
- file_put_contents($this->file, 'true');
25
- new FileCookieJar($this->file);
26
- }
27
-
28
- public function testLoadsFromFileFile()
29
- {
30
- $jar = new FileCookieJar($this->file);
31
- $this->assertEquals([], $jar->getIterator()->getArrayCopy());
32
- unlink($this->file);
33
- }
34
-
35
- public function testPersistsToFileFile()
36
- {
37
- $jar = new FileCookieJar($this->file);
38
- $jar->setCookie(new SetCookie([
39
- 'Name' => 'foo',
40
- 'Value' => 'bar',
41
- 'Domain' => 'foo.com',
42
- 'Expires' => time() + 1000
43
- ]));
44
- $jar->setCookie(new SetCookie([
45
- 'Name' => 'baz',
46
- 'Value' => 'bar',
47
- 'Domain' => 'foo.com',
48
- 'Expires' => time() + 1000
49
- ]));
50
- $jar->setCookie(new SetCookie([
51
- 'Name' => 'boo',
52
- 'Value' => 'bar',
53
- 'Domain' => 'foo.com',
54
- ]));
55
-
56
- $this->assertEquals(3, count($jar));
57
- unset($jar);
58
-
59
- // Make sure it wrote to the file
60
- $contents = file_get_contents($this->file);
61
- $this->assertNotEmpty($contents);
62
-
63
- // Load the cookieJar from the file
64
- $jar = new FileCookieJar($this->file);
65
-
66
- // Weeds out temporary and session cookies
67
- $this->assertEquals(2, count($jar));
68
- unset($jar);
69
- unlink($this->file);
70
- }
71
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Cookie/SessionCookieJarTest.php DELETED
@@ -1,76 +0,0 @@
1
- <?php
2
-
3
- namespace GuzzleHttp\Tests\CookieJar;
4
-
5
- use GuzzleHttp\Cookie\SessionCookieJar;
6
- use GuzzleHttp\Cookie\SetCookie;
7
-
8
- /**
9
- * @covers GuzzleHttp\Cookie\SessionCookieJar
10
- */
11
- class SessionCookieJarTest extends \PHPUnit_Framework_TestCase
12
- {
13
- private $sessionVar;
14
-
15
- public function setUp()
16
- {
17
- $this->sessionVar = 'sessionKey';
18
-
19
- if (!isset($_SESSION)) {
20
- $_SESSION = array();
21
- }
22
- }
23
-
24
- /**
25
- * @expectedException \RuntimeException
26
- */
27
- public function testValidatesCookieSession()
28
- {
29
- $_SESSION[$this->sessionVar] = 'true';
30
- new SessionCookieJar($this->sessionVar);
31
- }
32
-
33
- public function testLoadsFromSession()
34
- {
35
- $jar = new SessionCookieJar($this->sessionVar);
36
- $this->assertEquals([], $jar->getIterator()->getArrayCopy());
37
- unset($_SESSION[$this->sessionVar]);
38
- }
39
-
40
- public function testPersistsToSession()
41
- {
42
- $jar = new SessionCookieJar($this->sessionVar);
43
- $jar->setCookie(new SetCookie([
44
- 'Name' => 'foo',
45
- 'Value' => 'bar',
46
- 'Domain' => 'foo.com',
47
- 'Expires' => time() + 1000
48
- ]));
49
- $jar->setCookie(new SetCookie([
50
- 'Name' => 'baz',
51
- 'Value' => 'bar',
52
- 'Domain' => 'foo.com',
53
- 'Expires' => time() + 1000
54
- ]));
55
- $jar->setCookie(new SetCookie([
56
- 'Name' => 'boo',
57
- 'Value' => 'bar',
58
- 'Domain' => 'foo.com',
59
- ]));
60
-
61
- $this->assertEquals(3, count($jar));
62
- unset($jar);
63
-
64
- // Make sure it wrote to the sessionVar in $_SESSION
65
- $contents = $_SESSION[$this->sessionVar];
66
- $this->assertNotEmpty($contents);
67
-
68
- // Load the cookieJar from the file
69
- $jar = new SessionCookieJar($this->sessionVar);
70
-
71
- // Weeds out temporary and session cookies
72
- $this->assertEquals(2, count($jar));
73
- unset($jar);
74
- unset($_SESSION[$this->sessionVar]);
75
- }
76
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Cookie/SetCookieTest.php DELETED
@@ -1,364 +0,0 @@
1
- <?php
2
-
3
- namespace GuzzleHttp\Tests\CookieJar;
4
-
5
- use GuzzleHttp\Cookie\SetCookie;
6
-
7
- /**
8
- * @covers GuzzleHttp\Cookie\SetCookie
9
- */
10
- class SetCookieTest extends \PHPUnit_Framework_TestCase
11
- {
12
- public function testInitializesDefaultValues()
13
- {
14
- $cookie = new SetCookie();
15
- $this->assertEquals('/', $cookie->getPath());
16
- }
17
-
18
- public function testConvertsDateTimeMaxAgeToUnixTimestamp()
19
- {
20
- $cookie = new SetCookie(['Expires' => 'November 20, 1984']);
21
- $this->assertInternalType('integer', $cookie->getExpires());
22
- }
23
-
24
- public function testAddsExpiresBasedOnMaxAge()
25
- {
26
- $t = time();
27
- $cookie = new SetCookie(['Max-Age' => 100]);
28
- $this->assertEquals($t + 100, $cookie->getExpires());
29
- }
30
-
31
- public function testHoldsValues()
32
- {
33
- $t = time();
34
- $data = array(
35
- 'Name' => 'foo',
36
- 'Value' => 'baz',
37
- 'Path' => '/bar',
38
- 'Domain' => 'baz.com',
39
- 'Expires' => $t,
40
- 'Max-Age' => 100,
41
- 'Secure' => true,
42
- 'Discard' => true,
43
- 'HttpOnly' => true,
44
- 'foo' => 'baz',
45
- 'bar' => 'bam'
46
- );
47
-
48
- $cookie = new SetCookie($data);
49
- $this->assertEquals($data, $cookie->toArray());
50
-
51
- $this->assertEquals('foo', $cookie->getName());
52
- $this->assertEquals('baz', $cookie->getValue());
53
- $this->assertEquals('baz.com', $cookie->getDomain());
54
- $this->assertEquals('/bar', $cookie->getPath());
55
- $this->assertEquals($t, $cookie->getExpires());
56
- $this->assertEquals(100, $cookie->getMaxAge());
57
- $this->assertTrue($cookie->getSecure());
58
- $this->assertTrue($cookie->getDiscard());
59
- $this->assertTrue($cookie->getHttpOnly());
60
- $this->assertEquals('baz', $cookie->toArray()['foo']);
61
- $this->assertEquals('bam', $cookie->toArray()['bar']);
62
-
63
- $cookie->setName('a');
64
- $cookie->setValue('b');
65
- $cookie->setPath('c');
66
- $cookie->setDomain('bar.com');
67
- $cookie->setExpires(10);
68
- $cookie->setMaxAge(200);
69
- $cookie->setSecure(false);
70
- $cookie->setHttpOnly(false);
71
- $cookie->setDiscard(false);
72
-
73
- $this->assertEquals('a', $cookie->getName());
74
- $this->assertEquals('b', $cookie->getValue());
75
- $this->assertEquals('c', $cookie->getPath());
76
- $this->assertEquals('bar.com', $cookie->getDomain());
77
- $this->assertEquals(10, $cookie->getExpires());
78
- $this->assertEquals(200, $cookie->getMaxAge());
79
- $this->assertFalse($cookie->getSecure());
80
- $this->assertFalse($cookie->getDiscard());
81
- $this->assertFalse($cookie->getHttpOnly());
82
- }
83
-
84
- public function testDeterminesIfExpired()
85
- {
86
- $c = new SetCookie();
87
- $c->setExpires(10);
88
- $this->assertTrue($c->isExpired());
89
- $c->setExpires(time() + 10000);
90
- $this->assertFalse($c->isExpired());
91
- }
92
-
93
- public function testMatchesDomain()
94
- {
95
- $cookie = new SetCookie();
96
- $this->assertTrue($cookie->matchesDomain('baz.com'));
97
-
98
- $cookie->setDomain('baz.com');
99
- $this->assertTrue($cookie->matchesDomain('baz.com'));
100
- $this->assertFalse($cookie->matchesDomain('bar.com'));
101
-
102
- $cookie->setDomain('.baz.com');
103
- $this->assertTrue($cookie->matchesDomain('.baz.com'));
104
- $this->assertTrue($cookie->matchesDomain('foo.baz.com'));
105
- $this->assertFalse($cookie->matchesDomain('baz.bar.com'));
106
- $this->assertTrue($cookie->matchesDomain('baz.com'));
107
-
108
- $cookie->setDomain('.127.0.0.1');
109
- $this->assertTrue($cookie->matchesDomain('127.0.0.1'));
110
-
111
- $cookie->setDomain('127.0.0.1');
112
- $this->assertTrue($cookie->matchesDomain('127.0.0.1'));
113
-
114
- $cookie->setDomain('.com.');
115
- $this->assertFalse($cookie->matchesDomain('baz.com'));
116
-
117
- $cookie->setDomain('.local');
118
- $this->assertTrue($cookie->matchesDomain('example.local'));
119
- }
120
-
121
- public function testMatchesPath()
122
- {
123
- $cookie = new SetCookie();
124
- $this->assertTrue($cookie->matchesPath('/foo'));
125
-
126
- $cookie->setPath('/foo');
127
- $this->assertTrue($cookie->matchesPath('/foo'));
128
- $this->assertTrue($cookie->matchesPath('/foo/bar'));
129
- $this->assertFalse($cookie->matchesPath('/bar'));
130
- }
131
-
132
- public function cookieValidateProvider()
133
- {
134
- return array(
135
- array('foo', 'baz', 'bar', true),
136
- array('0', '0', '0', true),
137
- array('', 'baz', 'bar', 'The cookie name must not be empty'),
138
- array('foo', '', 'bar', 'The cookie value must not be empty'),
139
- array('foo', 'baz', '', 'The cookie domain must not be empty'),
140
- array("foo\r", 'baz', '0', 'Cookie name must not cannot invalid characters: =,; \t\r\n\013\014'),
141
- );
142
- }
143
-
144
- /**
145
- * @dataProvider cookieValidateProvider
146
- */
147
- public function testValidatesCookies($name, $value, $domain, $result)
148
- {
149
- $cookie = new SetCookie(array(
150
- 'Name' => $name,
151
- 'Value' => $value,
152
- 'Domain' => $domain
153
- ));
154
- $this->assertSame($result, $cookie->validate());
155
- }
156
-
157
- public function testDoesNotMatchIp()
158
- {
159
- $cookie = new SetCookie(['Domain' => '192.168.16.']);
160
- $this->assertFalse($cookie->matchesDomain('192.168.16.121'));
161
- }
162
-
163
- public function testConvertsToString()
164
- {
165
- $t = 1382916008;
166
- $cookie = new SetCookie([
167
- 'Name' => 'test',
168
- 'Value' => '123',
169
- 'Domain' => 'foo.com',
170
- 'Expires' => $t,
171
- 'Path' => '/abc',
172
- 'HttpOnly' => true,
173
- 'Secure' => true
174
- ]);
175
- $this->assertEquals(
176
- 'test=123; Domain=foo.com; Path=/abc; Expires=Sun, 27 Oct 2013 23:20:08 GMT; Secure; HttpOnly',
177
- (string) $cookie
178
- );
179
- }
180
-
181
- /**
182
- * Provides the parsed information from a cookie
183
- *
184
- * @return array
185
- */
186
- public function cookieParserDataProvider()
187
- {
188
- return array(
189
- array(
190
- 'ASIHTTPRequestTestCookie=This+is+the+value; expires=Sat, 26-Jul-2008 17:00:42 GMT; path=/tests; domain=allseeing-i.com; PHPSESSID=6c951590e7a9359bcedde25cda73e43c; path=/";',
191
- array(
192
- 'Domain' => 'allseeing-i.com',
193
- 'Path' => '/',
194
- 'PHPSESSID' => '6c951590e7a9359bcedde25cda73e43c',
195
- 'Max-Age' => NULL,
196
- 'Expires' => 'Sat, 26-Jul-2008 17:00:42 GMT',
197
- 'Secure' => NULL,
198
- 'Discard' => NULL,
199
- 'Name' => 'ASIHTTPRequestTestCookie',
200
- 'Value' => 'This+is+the+value',
201
- 'HttpOnly' => false
202
- )
203
- ),
204
- array('', []),
205
- array('foo', []),
206
- // Test setting a blank value for a cookie
207
- array(array(
208
- 'foo=', 'foo =', 'foo =;', 'foo= ;', 'foo =', 'foo= '),
209
- array(
210
- 'Name' => 'foo',
211
- 'Value' => '',
212
- 'Discard' => null,
213
- 'Domain' => null,
214
- 'Expires' => null,
215
- 'Max-Age' => null,
216
- 'Path' => '/',
217
- 'Secure' => null,
218
- 'HttpOnly' => false
219
- )
220
- ),
221
- // Test setting a value and removing quotes
222
- array(array(
223
- 'foo=1', 'foo =1', 'foo =1;', 'foo=1 ;', 'foo =1', 'foo= 1', 'foo = 1 ;', 'foo="1"', 'foo="1";', 'foo= "1";'),
224
- array(
225
- 'Name' => 'foo',
226
- 'Value' => '1',
227
- 'Discard' => null,
228
- 'Domain' => null,
229
- 'Expires' => null,
230
- 'Max-Age' => null,
231
- 'Path' => '/',
232
- 'Secure' => null,
233
- 'HttpOnly' => false
234
- )
235
- ),
236
- // Some of the following tests are based on http://framework.zend.com/svn/framework/standard/trunk/tests/Zend/Http/CookieTest.php
237
- array(
238
- 'justacookie=foo; domain=example.com',
239
- array(
240
- 'Name' => 'justacookie',
241
- 'Value' => 'foo',
242
- 'Domain' => 'example.com',
243
- 'Discard' => null,
244
- 'Expires' => null,
245
- 'Max-Age' => null,
246
- 'Path' => '/',
247
- 'Secure' => null,
248
- 'HttpOnly' => false
249
- )
250
- ),
251
- array(
252
- 'expires=tomorrow; secure; path=/Space Out/; expires=Tue, 21-Nov-2006 08:33:44 GMT; domain=.example.com',
253
- array(
254
- 'Name' => 'expires',
255
- 'Value' => 'tomorrow',
256
- 'Domain' => '.example.com',
257
- 'Path' => '/Space Out/',
258
- 'Expires' => 'Tue, 21-Nov-2006 08:33:44 GMT',
259
- 'Discard' => null,
260
- 'Secure' => true,
261
- 'Max-Age' => null,
262
- 'HttpOnly' => false
263
- )
264
- ),
265
- array(
266
- 'domain=unittests; expires=Tue, 21-Nov-2006 08:33:44 GMT; domain=example.com; path=/some value/',
267
- array(
268
- 'Name' => 'domain',
269
- 'Value' => 'unittests',
270
- 'Domain' => 'example.com',
271
- 'Path' => '/some value/',
272
- 'Expires' => 'Tue, 21-Nov-2006 08:33:44 GMT',
273
- 'Secure' => false,
274
- 'Discard' => null,
275
- 'Max-Age' => null,
276
- 'HttpOnly' => false
277
- )
278
- ),
279
- array(
280
- 'path=indexAction; path=/; domain=.foo.com; expires=Tue, 21-Nov-2006 08:33:44 GMT',
281
- array(
282
- 'Name' => 'path',
283
- 'Value' => 'indexAction',
284
- 'Domain' => '.foo.com',
285
- 'Path' => '/',
286
- 'Expires' => 'Tue, 21-Nov-2006 08:33:44 GMT',
287
- 'Secure' => false,
288
- 'Discard' => null,
289
- 'Max-Age' => null,
290
- 'HttpOnly' => false
291
- )
292
- ),
293
- array(
294
- 'secure=sha1; secure; SECURE; domain=some.really.deep.domain.com; version=1; Max-Age=86400',
295
- array(
296
- 'Name' => 'secure',
297
- 'Value' => 'sha1',
298
- 'Domain' => 'some.really.deep.domain.com',
299
- 'Path' => '/',
300
- 'Secure' => true,
301
- 'Discard' => null,
302
- 'Expires' => time() + 86400,
303
- 'Max-Age' => 86400,
304
- 'HttpOnly' => false,
305
- 'version' => '1'
306
- )
307
- ),
308
- array(
309
- 'PHPSESSID=123456789+abcd%2Cef; secure; discard; domain=.localdomain; path=/foo/baz; expires=Tue, 21-Nov-2006 08:33:44 GMT;',
310
- array(
311
- 'Name' => 'PHPSESSID',
312
- 'Value' => '123456789+abcd%2Cef',
313
- 'Domain' => '.localdomain',
314
- 'Path' => '/foo/baz',
315
- 'Expires' => 'Tue, 21-Nov-2006 08:33:44 GMT',
316
- 'Secure' => true,
317
- 'Discard' => true,
318
- 'Max-Age' => null,
319
- 'HttpOnly' => false
320
- )
321
- ),
322
- );
323
- }
324
-
325
- /**
326
- * @dataProvider cookieParserDataProvider
327
- */
328
- public function testParseCookie($cookie, $parsed)
329
- {
330
- foreach ((array) $cookie as $v) {
331
- $c = SetCookie::fromString($v);
332
- $p = $c->toArray();
333
-
334
- if (isset($p['Expires'])) {
335
- // Remove expires values from the assertion if they are relatively equal
336
- if (abs($p['Expires'] != strtotime($parsed['Expires'])) < 40) {
337
- unset($p['Expires']);
338
- unset($parsed['Expires']);
339
- }
340
- }
341
-
342
- if (!empty($parsed)) {
343
- foreach ($parsed as $key => $value) {
344
- $this->assertEquals($parsed[$key], $p[$key], 'Comparing ' . $key . ' ' . var_export($value, true) . ' : ' . var_export($parsed, true) . ' | ' . var_export($p, true));
345
- }
346
- foreach ($p as $key => $value) {
347
- $this->assertEquals($p[$key], $parsed[$key], 'Comparing ' . $key . ' ' . var_export($value, true) . ' : ' . var_export($parsed, true) . ' | ' . var_export($p, true));
348
- }
349
- } else {
350
- $this->assertEquals([
351
- 'Name' => null,
352
- 'Value' => null,
353
- 'Domain' => null,
354
- 'Path' => '/',
355
- 'Max-Age' => null,
356
- 'Expires' => null,
357
- 'Secure' => false,
358
- 'Discard' => false,
359
- 'HttpOnly' => false,
360
- ], $p);
361
- }
362
- }
363
- }
364
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Event/AbstractEventTest.php DELETED
@@ -1,14 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Event;
3
-
4
- class AbstractEventTest extends \PHPUnit_Framework_TestCase
5
- {
6
- public function testStopsPropagation()
7
- {
8
- $e = $this->getMockBuilder('GuzzleHttp\Event\AbstractEvent')
9
- ->getMockForAbstractClass();
10
- $this->assertFalse($e->isPropagationStopped());
11
- $e->stopPropagation();
12
- $this->assertTrue($e->isPropagationStopped());
13
- }
14
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Event/AbstractRequestEventTest.php DELETED
@@ -1,33 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Event;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Transaction;
6
- use GuzzleHttp\Message\Request;
7
-
8
- /**
9
- * @covers GuzzleHttp\Event\AbstractRequestEvent
10
- */
11
- class AbstractRequestEventTest extends \PHPUnit_Framework_TestCase
12
- {
13
- public function testHasTransactionMethods()
14
- {
15
- $t = new Transaction(new Client(), new Request('GET', '/'));
16
- $e = $this->getMockBuilder('GuzzleHttp\Event\AbstractRequestEvent')
17
- ->setConstructorArgs([$t])
18
- ->getMockForAbstractClass();
19
- $this->assertSame($t->client, $e->getClient());
20
- $this->assertSame($t->request, $e->getRequest());
21
- }
22
-
23
- public function testHasTransaction()
24
- {
25
- $t = new Transaction(new Client(), new Request('GET', '/'));
26
- $e = $this->getMockBuilder('GuzzleHttp\Event\AbstractRequestEvent')
27
- ->setConstructorArgs([$t])
28
- ->getMockForAbstractClass();
29
- $r = new \ReflectionMethod($e, 'getTransaction');
30
- $r->setAccessible(true);
31
- $this->assertSame($t, $r->invoke($e));
32
- }
33
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Event/AbstractRetryableEventTest.php DELETED
@@ -1,37 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Event;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Transaction;
6
- use GuzzleHttp\Message\Request;
7
-
8
- /**
9
- * @covers GuzzleHttp\Event\AbstractRetryableEvent
10
- */
11
- class AbstractRetryableEventTest extends \PHPUnit_Framework_TestCase
12
- {
13
- public function testCanRetry()
14
- {
15
- $t = new Transaction(new Client(), new Request('GET', '/'));
16
- $t->transferInfo = ['foo' => 'bar'];
17
- $e = $this->getMockBuilder('GuzzleHttp\Event\AbstractRetryableEvent')
18
- ->setConstructorArgs([$t])
19
- ->getMockForAbstractClass();
20
- $e->retry();
21
- $this->assertTrue($e->isPropagationStopped());
22
- $this->assertEquals('retry', $t->state);
23
- }
24
-
25
- public function testCanRetryAfterDelay()
26
- {
27
- $t = new Transaction(new Client(), new Request('GET', '/'));
28
- $t->transferInfo = ['foo' => 'bar'];
29
- $e = $this->getMockBuilder('GuzzleHttp\Event\AbstractRetryableEvent')
30
- ->setConstructorArgs([$t])
31
- ->getMockForAbstractClass();
32
- $e->retry(10);
33
- $this->assertTrue($e->isPropagationStopped());
34
- $this->assertEquals('retry', $t->state);
35
- $this->assertEquals(10, $t->request->getConfig()->get('delay'));
36
- }
37
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Event/AbstractTransferEventTest.php DELETED
@@ -1,59 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Event;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Message\Response;
6
- use GuzzleHttp\Transaction;
7
- use GuzzleHttp\Message\Request;
8
-
9
- /**
10
- * @covers GuzzleHttp\Event\AbstractTransferEvent
11
- */
12
- class AbstractTransferEventTest extends \PHPUnit_Framework_TestCase
13
- {
14
- public function testHasStats()
15
- {
16
- $t = new Transaction(new Client(), new Request('GET', '/'));
17
- $t->transferInfo = ['foo' => 'bar'];
18
- $e = $this->getMockBuilder('GuzzleHttp\Event\AbstractTransferEvent')
19
- ->setConstructorArgs([$t])
20
- ->getMockForAbstractClass();
21
- $this->assertNull($e->getTransferInfo('baz'));
22
- $this->assertEquals('bar', $e->getTransferInfo('foo'));
23
- $this->assertEquals($t->transferInfo, $e->getTransferInfo());
24
- }
25
-
26
- public function testHasResponse()
27
- {
28
- $t = new Transaction(new Client(), new Request('GET', '/'));
29
- $t->response = new Response(200);
30
- $e = $this->getMockBuilder('GuzzleHttp\Event\AbstractTransferEvent')
31
- ->setConstructorArgs([$t])
32
- ->getMockForAbstractClass();
33
- $this->assertTrue($e->hasResponse());
34
- $this->assertSame($t->response, $e->getResponse());
35
- }
36
-
37
- public function testCanInterceptWithResponse()
38
- {
39
- $t = new Transaction(new Client(), new Request('GET', '/'));
40
- $r = new Response(200);
41
- $e = $this->getMockBuilder('GuzzleHttp\Event\AbstractTransferEvent')
42
- ->setConstructorArgs([$t])
43
- ->getMockForAbstractClass();
44
- $e->intercept($r);
45
- $this->assertSame($t->response, $r);
46
- $this->assertSame($t->response, $e->getResponse());
47
- $this->assertTrue($e->isPropagationStopped());
48
- }
49
-
50
- public function testReturnsNumberOfRetries()
51
- {
52
- $t = new Transaction(new Client(), new Request('GET', '/'));
53
- $t->retries = 2;
54
- $e = $this->getMockBuilder('GuzzleHttp\Event\AbstractTransferEvent')
55
- ->setConstructorArgs([$t])
56
- ->getMockForAbstractClass();
57
- $this->assertEquals(2, $e->getRetryCount());
58
- }
59
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Event/BeforeEventTest.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Event;
3
-
4
- use GuzzleHttp\Transaction;
5
- use GuzzleHttp\Client;
6
- use GuzzleHttp\Event\BeforeEvent;
7
- use GuzzleHttp\Message\Request;
8
- use GuzzleHttp\Message\Response;
9
-
10
- /**
11
- * @covers GuzzleHttp\Event\BeforeEvent
12
- */
13
- class BeforeEventTest extends \PHPUnit_Framework_TestCase
14
- {
15
- public function testInterceptsWithEvent()
16
- {
17
- $t = new Transaction(new Client(), new Request('GET', '/'));
18
- $t->exception = new \Exception('foo');
19
- $e = new BeforeEvent($t);
20
- $response = new Response(200);
21
- $e->intercept($response);
22
- $this->assertTrue($e->isPropagationStopped());
23
- $this->assertSame($t->response, $response);
24
- $this->assertNull($t->exception);
25
- }
26
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Event/EmitterTest.php DELETED
@@ -1,363 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Event;
3
-
4
- use GuzzleHttp\Event\Emitter;
5
- use GuzzleHttp\Event\EventInterface;
6
- use GuzzleHttp\Event\SubscriberInterface;
7
-
8
- /**
9
- * @link https://github.com/symfony/symfony/blob/master/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php Based on this test.
10
- */
11
- class EmitterTest extends \PHPUnit_Framework_TestCase
12
- {
13
- /* Some pseudo events */
14
- const preFoo = 'pre.foo';
15
- const postFoo = 'post.foo';
16
- const preBar = 'pre.bar';
17
- const postBar = 'post.bar';
18
-
19
- /** @var Emitter */
20
- private $emitter;
21
- private $listener;
22
-
23
- protected function setUp()
24
- {
25
- $this->emitter = new Emitter();
26
- $this->listener = new TestEventListener();
27
- }
28
-
29
- protected function tearDown()
30
- {
31
- $this->emitter = null;
32
- $this->listener = null;
33
- }
34
-
35
- public function testInitialState()
36
- {
37
- $this->assertEquals(array(), $this->emitter->listeners());
38
- }
39
-
40
- public function testAddListener()
41
- {
42
- $this->emitter->on('pre.foo', array($this->listener, 'preFoo'));
43
- $this->emitter->on('post.foo', array($this->listener, 'postFoo'));
44
- $this->assertTrue($this->emitter->hasListeners(self::preFoo));
45
- $this->assertTrue($this->emitter->hasListeners(self::preFoo));
46
- $this->assertCount(1, $this->emitter->listeners(self::postFoo));
47
- $this->assertCount(1, $this->emitter->listeners(self::postFoo));
48
- $this->assertCount(2, $this->emitter->listeners());
49
- }
50
-
51
- public function testGetListenersSortsByPriority()
52
- {
53
- $listener1 = new TestEventListener();
54
- $listener2 = new TestEventListener();
55
- $listener3 = new TestEventListener();
56
- $listener1->name = '1';
57
- $listener2->name = '2';
58
- $listener3->name = '3';
59
-
60
- $this->emitter->on('pre.foo', array($listener1, 'preFoo'), -10);
61
- $this->emitter->on('pre.foo', array($listener2, 'preFoo'), 10);
62
- $this->emitter->on('pre.foo', array($listener3, 'preFoo'));
63
-
64
- $expected = array(
65
- array($listener2, 'preFoo'),
66
- array($listener3, 'preFoo'),
67
- array($listener1, 'preFoo'),
68
- );
69
-
70
- $this->assertSame($expected, $this->emitter->listeners('pre.foo'));
71
- }
72
-
73
- public function testGetAllListenersSortsByPriority()
74
- {
75
- $listener1 = new TestEventListener();
76
- $listener2 = new TestEventListener();
77
- $listener3 = new TestEventListener();
78
- $listener4 = new TestEventListener();
79
- $listener5 = new TestEventListener();
80
- $listener6 = new TestEventListener();
81
-
82
- $this->emitter->on('pre.foo', [$listener1, 'preFoo'], -10);
83
- $this->emitter->on('pre.foo', [$listener2, 'preFoo']);
84
- $this->emitter->on('pre.foo', [$listener3, 'preFoo'], 10);
85
- $this->emitter->on('post.foo', [$listener4, 'preFoo'], -10);
86
- $this->emitter->on('post.foo', [$listener5, 'preFoo']);
87
- $this->emitter->on('post.foo', [$listener6, 'preFoo'], 10);
88
-
89
- $expected = [
90
- 'pre.foo' => [[$listener3, 'preFoo'], [$listener2, 'preFoo'], [$listener1, 'preFoo']],
91
- 'post.foo' => [[$listener6, 'preFoo'], [$listener5, 'preFoo'], [$listener4, 'preFoo']],
92
- ];
93
-
94
- $this->assertSame($expected, $this->emitter->listeners());
95
- }
96
-
97
- public function testDispatch()
98
- {
99
- $this->emitter->on('pre.foo', array($this->listener, 'preFoo'));
100
- $this->emitter->on('post.foo', array($this->listener, 'postFoo'));
101
- $this->emitter->emit(self::preFoo, $this->getEvent());
102
- $this->assertTrue($this->listener->preFooInvoked);
103
- $this->assertFalse($this->listener->postFooInvoked);
104
- $this->assertInstanceOf('GuzzleHttp\Event\EventInterface', $this->emitter->emit(self::preFoo, $this->getEvent()));
105
- $event = $this->getEvent();
106
- $return = $this->emitter->emit(self::preFoo, $event);
107
- $this->assertSame($event, $return);
108
- }
109
-
110
- public function testDispatchForClosure()
111
- {
112
- $invoked = 0;
113
- $listener = function () use (&$invoked) {
114
- $invoked++;
115
- };
116
- $this->emitter->on('pre.foo', $listener);
117
- $this->emitter->on('post.foo', $listener);
118
- $this->emitter->emit(self::preFoo, $this->getEvent());
119
- $this->assertEquals(1, $invoked);
120
- }
121
-
122
- public function testStopEventPropagation()
123
- {
124
- $otherListener = new TestEventListener();
125
-
126
- // postFoo() stops the propagation, so only one listener should
127
- // be executed
128
- // Manually set priority to enforce $this->listener to be called first
129
- $this->emitter->on('post.foo', array($this->listener, 'postFoo'), 10);
130
- $this->emitter->on('post.foo', array($otherListener, 'preFoo'));
131
- $this->emitter->emit(self::postFoo, $this->getEvent());
132
- $this->assertTrue($this->listener->postFooInvoked);
133
- $this->assertFalse($otherListener->postFooInvoked);
134
- }
135
-
136
- public function testDispatchByPriority()
137
- {
138
- $invoked = array();
139
- $listener1 = function () use (&$invoked) {
140
- $invoked[] = '1';
141
- };
142
- $listener2 = function () use (&$invoked) {
143
- $invoked[] = '2';
144
- };
145
- $listener3 = function () use (&$invoked) {
146
- $invoked[] = '3';
147
- };
148
- $this->emitter->on('pre.foo', $listener1, -10);
149
- $this->emitter->on('pre.foo', $listener2);
150
- $this->emitter->on('pre.foo', $listener3, 10);
151
- $this->emitter->emit(self::preFoo, $this->getEvent());
152
- $this->assertEquals(array('3', '2', '1'), $invoked);
153
- }
154
-
155
- public function testRemoveListener()
156
- {
157
- $this->emitter->on('pre.bar', [$this->listener, 'preFoo']);
158
- $this->assertNotEmpty($this->emitter->listeners(self::preBar));
159
- $this->emitter->removeListener('pre.bar', [$this->listener, 'preFoo']);
160
- $this->assertEmpty($this->emitter->listeners(self::preBar));
161
- $this->emitter->removeListener('notExists', [$this->listener, 'preFoo']);
162
- }
163
-
164
- public function testAddSubscriber()
165
- {
166
- $eventSubscriber = new TestEventSubscriber();
167
- $this->emitter->attach($eventSubscriber);
168
- $this->assertNotEmpty($this->emitter->listeners(self::preFoo));
169
- $this->assertNotEmpty($this->emitter->listeners(self::postFoo));
170
- }
171
-
172
- public function testAddSubscriberWithMultiple()
173
- {
174
- $eventSubscriber = new TestEventSubscriberWithMultiple();
175
- $this->emitter->attach($eventSubscriber);
176
- $listeners = $this->emitter->listeners('pre.foo');
177
- $this->assertNotEmpty($this->emitter->listeners(self::preFoo));
178
- $this->assertCount(2, $listeners);
179
- }
180
-
181
- public function testAddSubscriberWithPriorities()
182
- {
183
- $eventSubscriber = new TestEventSubscriber();
184
- $this->emitter->attach($eventSubscriber);
185
-
186
- $eventSubscriber = new TestEventSubscriberWithPriorities();
187
- $this->emitter->attach($eventSubscriber);
188
-
189
- $listeners = $this->emitter->listeners('pre.foo');
190
- $this->assertNotEmpty($this->emitter->listeners(self::preFoo));
191
- $this->assertCount(2, $listeners);
192
- $this->assertInstanceOf('GuzzleHttp\Tests\Event\TestEventSubscriberWithPriorities', $listeners[0][0]);
193
- }
194
-
195
- public function testdetach()
196
- {
197
- $eventSubscriber = new TestEventSubscriber();
198
- $this->emitter->attach($eventSubscriber);
199
- $this->assertNotEmpty($this->emitter->listeners(self::preFoo));
200
- $this->assertNotEmpty($this->emitter->listeners(self::postFoo));
201
- $this->emitter->detach($eventSubscriber);
202
- $this->assertEmpty($this->emitter->listeners(self::preFoo));
203
- $this->assertEmpty($this->emitter->listeners(self::postFoo));
204
- }
205
-
206
- public function testdetachWithPriorities()
207
- {
208
- $eventSubscriber = new TestEventSubscriberWithPriorities();
209
- $this->emitter->attach($eventSubscriber);
210
- $this->assertNotEmpty($this->emitter->listeners(self::preFoo));
211
- $this->assertNotEmpty($this->emitter->listeners(self::postFoo));
212
- $this->emitter->detach($eventSubscriber);
213
- $this->assertEmpty($this->emitter->listeners(self::preFoo));
214
- $this->assertEmpty($this->emitter->listeners(self::postFoo));
215
- }
216
-
217
- public function testEventReceivesEventNameAsArgument()
218
- {
219
- $listener = new TestWithDispatcher();
220
- $this->emitter->on('test', array($listener, 'foo'));
221
- $this->assertNull($listener->name);
222
- $this->emitter->emit('test', $this->getEvent());
223
- $this->assertEquals('test', $listener->name);
224
- }
225
-
226
- /**
227
- * @see https://bugs.php.net/bug.php?id=62976
228
- *
229
- * This bug affects:
230
- * - The PHP 5.3 branch for versions < 5.3.18
231
- * - The PHP 5.4 branch for versions < 5.4.8
232
- * - The PHP 5.5 branch is not affected
233
- */
234
- public function testWorkaroundForPhpBug62976()
235
- {
236
- $dispatcher = new Emitter();
237
- $dispatcher->on('bug.62976', new CallableClass());
238
- $dispatcher->removeListener('bug.62976', function () {});
239
- $this->assertNotEmpty($dispatcher->listeners('bug.62976'));
240
- }
241
-
242
- public function testRegistersEventsOnce()
243
- {
244
- $this->emitter->once('pre.foo', array($this->listener, 'preFoo'));
245
- $this->emitter->on('pre.foo', array($this->listener, 'preFoo'));
246
- $this->assertCount(2, $this->emitter->listeners(self::preFoo));
247
- $this->emitter->emit(self::preFoo, $this->getEvent());
248
- $this->assertTrue($this->listener->preFooInvoked);
249
- $this->assertCount(1, $this->emitter->listeners(self::preFoo));
250
- }
251
-
252
- public function testReturnsEmptyArrayForNonExistentEvent()
253
- {
254
- $this->assertEquals([], $this->emitter->listeners('doesnotexist'));
255
- }
256
-
257
- public function testCanAddFirstAndLastListeners()
258
- {
259
- $b = '';
260
- $this->emitter->on('foo', function () use (&$b) { $b .= 'a'; }, 'first'); // 1
261
- $this->emitter->on('foo', function () use (&$b) { $b .= 'b'; }, 'last'); // 0
262
- $this->emitter->on('foo', function () use (&$b) { $b .= 'c'; }, 'first'); // 2
263
- $this->emitter->on('foo', function () use (&$b) { $b .= 'd'; }, 'first'); // 3
264
- $this->emitter->on('foo', function () use (&$b) { $b .= 'e'; }, 'first'); // 4
265
- $this->emitter->on('foo', function () use (&$b) { $b .= 'f'; }); // 0
266
- $this->emitter->emit('foo', $this->getEvent());
267
- $this->assertEquals('edcabf', $b);
268
- }
269
-
270
- /**
271
- * @return \GuzzleHttp\Event\EventInterface
272
- */
273
- private function getEvent()
274
- {
275
- return $this->getMockBuilder('GuzzleHttp\Event\AbstractEvent')
276
- ->getMockForAbstractClass();
277
- }
278
- }
279
-
280
- class CallableClass
281
- {
282
- public function __invoke()
283
- {
284
- }
285
- }
286
-
287
- class TestEventListener
288
- {
289
- public $preFooInvoked = false;
290
- public $postFooInvoked = false;
291
-
292
- /* Listener methods */
293
-
294
- public function preFoo(EventInterface $e)
295
- {
296
- $this->preFooInvoked = true;
297
- }
298
-
299
- public function postFoo(EventInterface $e)
300
- {
301
- $this->postFooInvoked = true;
302
-
303
- $e->stopPropagation();
304
- }
305
-
306
- /**
307
- * @expectedException \PHPUnit_Framework_Error_Deprecated
308
- */
309
- public function testHasDeprecatedAddListener()
310
- {
311
- $emitter = new Emitter();
312
- $emitter->addListener('foo', function () {});
313
- }
314
-
315
- /**
316
- * @expectedException \PHPUnit_Framework_Error_Deprecated
317
- */
318
- public function testHasDeprecatedAddSubscriber()
319
- {
320
- $emitter = new Emitter();
321
- $emitter->addSubscriber('foo', new TestEventSubscriber());
322
- }
323
- }
324
-
325
- class TestWithDispatcher
326
- {
327
- public $name;
328
-
329
- public function foo(EventInterface $e, $name)
330
- {
331
- $this->name = $name;
332
- }
333
- }
334
-
335
- class TestEventSubscriber extends TestEventListener implements SubscriberInterface
336
- {
337
- public function getEvents()
338
- {
339
- return [
340
- 'pre.foo' => ['preFoo'],
341
- 'post.foo' => ['postFoo']
342
- ];
343
- }
344
- }
345
-
346
- class TestEventSubscriberWithPriorities extends TestEventListener implements SubscriberInterface
347
- {
348
- public function getEvents()
349
- {
350
- return [
351
- 'pre.foo' => ['preFoo', 10],
352
- 'post.foo' => ['postFoo']
353
- ];
354
- }
355
- }
356
-
357
- class TestEventSubscriberWithMultiple extends TestEventListener implements SubscriberInterface
358
- {
359
- public function getEvents()
360
- {
361
- return ['pre.foo' => [['preFoo', 10],['preFoo', 20]]];
362
- }
363
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Event/ErrorEventTest.php DELETED
@@ -1,23 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Event;
3
-
4
- use GuzzleHttp\Transaction;
5
- use GuzzleHttp\Client;
6
- use GuzzleHttp\Event\ErrorEvent;
7
- use GuzzleHttp\Exception\RequestException;
8
- use GuzzleHttp\Message\Request;
9
-
10
- /**
11
- * @covers GuzzleHttp\Event\ErrorEvent
12
- */
13
- class ErrorEventTest extends \PHPUnit_Framework_TestCase
14
- {
15
- public function testInterceptsWithEvent()
16
- {
17
- $t = new Transaction(new Client(), new Request('GET', '/'));
18
- $except = new RequestException('foo', $t->request);
19
- $t->exception = $except;
20
- $e = new ErrorEvent($t);
21
- $this->assertSame($e->getException(), $t->exception);
22
- }
23
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Event/HasEmitterTraitTest.php DELETED
@@ -1,27 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Event;
3
-
4
- use GuzzleHttp\Event\HasEmitterInterface;
5
- use GuzzleHttp\Event\HasEmitterTrait;
6
-
7
- class AbstractHasEmitter implements HasEmitterInterface
8
- {
9
- use HasEmitterTrait;
10
- }
11
-
12
- /**
13
- * @covers GuzzleHttp\Event\HasEmitterTrait
14
- */
15
- class HasEmitterTraitTest extends \PHPUnit_Framework_TestCase
16
- {
17
- public function testHelperAttachesSubscribers()
18
- {
19
- $mock = $this->getMockBuilder('GuzzleHttp\Tests\Event\AbstractHasEmitter')
20
- ->getMockForAbstractClass();
21
-
22
- $result = $mock->getEmitter();
23
- $this->assertInstanceOf('GuzzleHttp\Event\EmitterInterface', $result);
24
- $result2 = $mock->getEmitter();
25
- $this->assertSame($result, $result2);
26
- }
27
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Event/ListenerAttacherTraitTest.php DELETED
@@ -1,92 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Event;
3
-
4
- use GuzzleHttp\Event\HasEmitterInterface;
5
- use GuzzleHttp\Event\HasEmitterTrait;
6
- use GuzzleHttp\Event\ListenerAttacherTrait;
7
-
8
- class ObjectWithEvents implements HasEmitterInterface
9
- {
10
- use HasEmitterTrait, ListenerAttacherTrait;
11
-
12
- public $listeners = [];
13
-
14
- public function __construct(array $args = [])
15
- {
16
- $this->listeners = $this->prepareListeners($args, ['foo', 'bar']);
17
- $this->attachListeners($this, $this->listeners);
18
- }
19
- }
20
-
21
- class ListenerAttacherTraitTest extends \PHPUnit_Framework_TestCase
22
- {
23
- public function testRegistersEvents()
24
- {
25
- $fn = function () {};
26
- $o = new ObjectWithEvents([
27
- 'foo' => $fn,
28
- 'bar' => $fn,
29
- ]);
30
-
31
- $this->assertEquals([
32
- ['name' => 'foo', 'fn' => $fn, 'priority' => 0, 'once' => false],
33
- ['name' => 'bar', 'fn' => $fn, 'priority' => 0, 'once' => false],
34
- ], $o->listeners);
35
-
36
- $this->assertCount(1, $o->getEmitter()->listeners('foo'));
37
- $this->assertCount(1, $o->getEmitter()->listeners('bar'));
38
- }
39
-
40
- public function testRegistersEventsWithPriorities()
41
- {
42
- $fn = function () {};
43
- $o = new ObjectWithEvents([
44
- 'foo' => ['fn' => $fn, 'priority' => 99, 'once' => true],
45
- 'bar' => ['fn' => $fn, 'priority' => 50],
46
- ]);
47
-
48
- $this->assertEquals([
49
- ['name' => 'foo', 'fn' => $fn, 'priority' => 99, 'once' => true],
50
- ['name' => 'bar', 'fn' => $fn, 'priority' => 50, 'once' => false],
51
- ], $o->listeners);
52
- }
53
-
54
- public function testRegistersMultipleEvents()
55
- {
56
- $fn = function () {};
57
- $eventArray = [['fn' => $fn], ['fn' => $fn]];
58
- $o = new ObjectWithEvents([
59
- 'foo' => $eventArray,
60
- 'bar' => $eventArray,
61
- ]);
62
-
63
- $this->assertEquals([
64
- ['name' => 'foo', 'fn' => $fn, 'priority' => 0, 'once' => false],
65
- ['name' => 'foo', 'fn' => $fn, 'priority' => 0, 'once' => false],
66
- ['name' => 'bar', 'fn' => $fn, 'priority' => 0, 'once' => false],
67
- ['name' => 'bar', 'fn' => $fn, 'priority' => 0, 'once' => false],
68
- ], $o->listeners);
69
-
70
- $this->assertCount(2, $o->getEmitter()->listeners('foo'));
71
- $this->assertCount(2, $o->getEmitter()->listeners('bar'));
72
- }
73
-
74
- public function testRegistersEventsWithOnce()
75
- {
76
- $called = 0;
77
- $fn = function () use (&$called) { $called++; };
78
- $o = new ObjectWithEvents(['foo' => ['fn' => $fn, 'once' => true]]);
79
- $ev = $this->getMock('GuzzleHttp\Event\EventInterface');
80
- $o->getEmitter()->emit('foo', $ev);
81
- $o->getEmitter()->emit('foo', $ev);
82
- $this->assertEquals(1, $called);
83
- }
84
-
85
- /**
86
- * @expectedException \InvalidArgumentException
87
- */
88
- public function testValidatesEvents()
89
- {
90
- new ObjectWithEvents(['foo' => 'bar']);
91
- }
92
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Event/ProgressEventTest.php DELETED
@@ -1,25 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Event;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Event\ProgressEvent;
6
- use GuzzleHttp\Message\Request;
7
- use GuzzleHttp\Transaction;
8
-
9
- /**
10
- * @covers GuzzleHttp\Event\ProgressEvent
11
- */
12
- class ProgressEventTest extends \PHPUnit_Framework_TestCase
13
- {
14
- public function testContainsNumbers()
15
- {
16
- $t = new Transaction(new Client(), new Request('GET', 'http://a.com'));
17
- $p = new ProgressEvent($t, 2, 1, 3, 0);
18
- $this->assertSame($t->request, $p->getRequest());
19
- $this->assertSame($t->client, $p->getClient());
20
- $this->assertEquals(2, $p->downloadSize);
21
- $this->assertEquals(1, $p->downloaded);
22
- $this->assertEquals(3, $p->uploadSize);
23
- $this->assertEquals(0, $p->uploaded);
24
- }
25
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Event/RequestEventsTest.php DELETED
@@ -1,74 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Event;
3
-
4
- use GuzzleHttp\Event\RequestEvents;
5
-
6
- /**
7
- * @covers GuzzleHttp\Event\RequestEvents
8
- */
9
- class RequestEventsTest extends \PHPUnit_Framework_TestCase
10
- {
11
- public function prepareEventProvider()
12
- {
13
- $cb = function () {};
14
-
15
- return [
16
- [[], ['complete'], $cb, ['complete' => [$cb]]],
17
- [
18
- ['complete' => $cb],
19
- ['complete'],
20
- $cb,
21
- ['complete' => [$cb, $cb]]
22
- ],
23
- [
24
- ['prepare' => []],
25
- ['error', 'foo'],
26
- $cb,
27
- [
28
- 'prepare' => [],
29
- 'error' => [$cb],
30
- 'foo' => [$cb]
31
- ]
32
- ],
33
- [
34
- ['prepare' => []],
35
- ['prepare'],
36
- $cb,
37
- [
38
- 'prepare' => [$cb]
39
- ]
40
- ],
41
- [
42
- ['prepare' => ['fn' => $cb]],
43
- ['prepare'], $cb,
44
- [
45
- 'prepare' => [
46
- ['fn' => $cb],
47
- $cb
48
- ]
49
- ]
50
- ],
51
- ];
52
- }
53
-
54
- /**
55
- * @dataProvider prepareEventProvider
56
- */
57
- public function testConvertsEventArrays(
58
- array $in,
59
- array $events,
60
- $add,
61
- array $out
62
- ) {
63
- $result = RequestEvents::convertEventArray($in, $events, $add);
64
- $this->assertEquals($out, $result);
65
- }
66
-
67
- /**
68
- * @expectedException \InvalidArgumentException
69
- */
70
- public function testValidatesEventFormat()
71
- {
72
- RequestEvents::convertEventArray(['foo' => false], ['foo'], []);
73
- }
74
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Exception/ParseExceptionTest.php DELETED
@@ -1,20 +0,0 @@
1
- <?php
2
-
3
- namespace GuzzleHttp\Tests\Event;
4
-
5
- use GuzzleHttp\Exception\ParseException;
6
- use GuzzleHttp\Message\Response;
7
-
8
- /**
9
- * @covers GuzzleHttp\Exception\ParseException
10
- */
11
- class ParseExceptionTest extends \PHPUnit_Framework_TestCase
12
- {
13
- public function testHasResponse()
14
- {
15
- $res = new Response(200);
16
- $e = new ParseException('foo', $res);
17
- $this->assertSame($res, $e->getResponse());
18
- $this->assertEquals('foo', $e->getMessage());
19
- }
20
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Exception/RequestExceptionTest.php DELETED
@@ -1,83 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Event;
3
-
4
- use GuzzleHttp\Exception\RequestException;
5
- use GuzzleHttp\Message\Request;
6
- use GuzzleHttp\Message\Response;
7
- use GuzzleHttp\Ring\Exception\ConnectException;
8
-
9
- /**
10
- * @covers GuzzleHttp\Exception\RequestException
11
- */
12
- class RequestExceptionTest extends \PHPUnit_Framework_TestCase
13
- {
14
- public function testHasRequestAndResponse()
15
- {
16
- $req = new Request('GET', '/');
17
- $res = new Response(200);
18
- $e = new RequestException('foo', $req, $res);
19
- $this->assertSame($req, $e->getRequest());
20
- $this->assertSame($res, $e->getResponse());
21
- $this->assertTrue($e->hasResponse());
22
- $this->assertEquals('foo', $e->getMessage());
23
- }
24
-
25
- public function testCreatesGenerateException()
26
- {
27
- $e = RequestException::create(new Request('GET', '/'));
28
- $this->assertEquals('Error completing request', $e->getMessage());
29
- $this->assertInstanceOf('GuzzleHttp\Exception\RequestException', $e);
30
- }
31
-
32
- public function testCreatesClientErrorResponseException()
33
- {
34
- $e = RequestException::create(new Request('GET', '/'), new Response(400));
35
- $this->assertEquals(
36
- 'Client error response [url] / [status code] 400 [reason phrase] Bad Request',
37
- $e->getMessage()
38
- );
39
- $this->assertInstanceOf('GuzzleHttp\Exception\ClientException', $e);
40
- }
41
-
42
- public function testCreatesServerErrorResponseException()
43
- {
44
- $e = RequestException::create(new Request('GET', '/'), new Response(500));
45
- $this->assertEquals(
46
- 'Server error response [url] / [status code] 500 [reason phrase] Internal Server Error',
47
- $e->getMessage()
48
- );
49
- $this->assertInstanceOf('GuzzleHttp\Exception\ServerException', $e);
50
- }
51
-
52
- public function testCreatesGenericErrorResponseException()
53
- {
54
- $e = RequestException::create(new Request('GET', '/'), new Response(600));
55
- $this->assertEquals(
56
- 'Unsuccessful response [url] / [status code] 600 [reason phrase] ',
57
- $e->getMessage()
58
- );
59
- $this->assertInstanceOf('GuzzleHttp\Exception\RequestException', $e);
60
- }
61
-
62
- public function testHasStatusCodeAsExceptionCode() {
63
- $e = RequestException::create(new Request('GET', '/'), new Response(442));
64
- $this->assertEquals(442, $e->getCode());
65
- }
66
-
67
- public function testWrapsRequestExceptions()
68
- {
69
- $e = new \Exception('foo');
70
- $r = new Request('GET', 'http://www.oo.com');
71
- $ex = RequestException::wrapException($r, $e);
72
- $this->assertInstanceOf('GuzzleHttp\Exception\RequestException', $ex);
73
- $this->assertSame($e, $ex->getPrevious());
74
- }
75
-
76
- public function testWrapsConnectExceptions()
77
- {
78
- $e = new ConnectException('foo');
79
- $r = new Request('GET', 'http://www.oo.com');
80
- $ex = RequestException::wrapException($r, $e);
81
- $this->assertInstanceOf('GuzzleHttp\Exception\ConnectException', $ex);
82
- }
83
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Exception/XmlParseExceptionTest.php DELETED
@@ -1,19 +0,0 @@
1
- <?php
2
-
3
- namespace GuzzleHttp\tests\Exception;
4
-
5
- use GuzzleHttp\Exception\XmlParseException;
6
-
7
- /**
8
- * @covers GuzzleHttp\Exception\XmlParseException
9
- */
10
- class XmlParseExceptionTest extends \PHPUnit_Framework_TestCase
11
- {
12
- public function testHasError()
13
- {
14
- $error = new \LibXMLError();
15
- $e = new XmlParseException('foo', null, null, $error);
16
- $this->assertSame($error, $e->getError());
17
- $this->assertEquals('foo', $e->getMessage());
18
- }
19
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/IntegrationTest.php DELETED
@@ -1,123 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Event\AbstractTransferEvent;
6
- use GuzzleHttp\Event\CompleteEvent;
7
- use GuzzleHttp\Event\EndEvent;
8
- use GuzzleHttp\Event\ErrorEvent;
9
- use GuzzleHttp\Exception\RequestException;
10
- use GuzzleHttp\Message\Response;
11
- use GuzzleHttp\Pool;
12
-
13
- class IntegrationTest extends \PHPUnit_Framework_TestCase
14
- {
15
- /**
16
- * @issue https://github.com/guzzle/guzzle/issues/867
17
- */
18
- public function testDoesNotFailInEventSystemForNetworkError()
19
- {
20
- $c = new Client();
21
- $r = $c->createRequest(
22
- 'GET',
23
- Server::$url,
24
- [
25
- 'timeout' => 1,
26
- 'connect_timeout' => 1,
27
- 'proxy' => 'http://127.0.0.1:123/foo'
28
- ]
29
- );
30
-
31
- $events = [];
32
- $fn = function(AbstractTransferEvent $event) use (&$events) {
33
- $events[] = [
34
- get_class($event),
35
- $event->hasResponse(),
36
- $event->getResponse()
37
- ];
38
- };
39
-
40
- $pool = new Pool($c, [$r], [
41
- 'error' => $fn,
42
- 'end' => $fn
43
- ]);
44
-
45
- $pool->wait();
46
-
47
- $this->assertCount(2, $events);
48
- $this->assertEquals('GuzzleHttp\Event\ErrorEvent', $events[0][0]);
49
- $this->assertFalse($events[0][1]);
50
- $this->assertNull($events[0][2]);
51
-
52
- $this->assertEquals('GuzzleHttp\Event\EndEvent', $events[1][0]);
53
- $this->assertFalse($events[1][1]);
54
- $this->assertNull($events[1][2]);
55
- }
56
-
57
- /**
58
- * @issue https://github.com/guzzle/guzzle/issues/866
59
- */
60
- public function testProperyGetsTransferStats()
61
- {
62
- $transfer = [];
63
- Server::enqueue([new Response(200)]);
64
- $c = new Client();
65
- $response = $c->get(Server::$url . '/foo', [
66
- 'events' => [
67
- 'end' => function (EndEvent $e) use (&$transfer) {
68
- $transfer = $e->getTransferInfo();
69
- }
70
- ]
71
- ]);
72
- $this->assertEquals(Server::$url . '/foo', $response->getEffectiveUrl());
73
- $this->assertNotEmpty($transfer);
74
- $this->assertArrayHasKey('url', $transfer);
75
- }
76
-
77
- public function testNestedFutureResponsesAreResolvedWhenSending()
78
- {
79
- $c = new Client();
80
- $total = 3;
81
- Server::enqueue([
82
- new Response(200),
83
- new Response(201),
84
- new Response(202)
85
- ]);
86
- $c->getEmitter()->on(
87
- 'complete',
88
- function (CompleteEvent $e) use (&$total) {
89
- if (--$total) {
90
- $e->retry();
91
- }
92
- }
93
- );
94
- $response = $c->get(Server::$url);
95
- $this->assertEquals(202, $response->getStatusCode());
96
- $this->assertEquals('GuzzleHttp\Message\Response', get_class($response));
97
- }
98
-
99
- public function testNestedFutureErrorsAreResolvedWhenSending()
100
- {
101
- $c = new Client();
102
- $total = 3;
103
- Server::enqueue([
104
- new Response(500),
105
- new Response(501),
106
- new Response(502)
107
- ]);
108
- $c->getEmitter()->on(
109
- 'error',
110
- function (ErrorEvent $e) use (&$total) {
111
- if (--$total) {
112
- $e->retry();
113
- }
114
- }
115
- );
116
- try {
117
- $c->get(Server::$url);
118
- $this->fail('Did not throw!');
119
- } catch (RequestException $e) {
120
- $this->assertEquals(502, $e->getResponse()->getStatusCode());
121
- }
122
- }
123
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Message/AbstractMessageTest.php DELETED
@@ -1,269 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Message;
3
-
4
- use GuzzleHttp\Message\AbstractMessage;
5
- use GuzzleHttp\Message\Request;
6
- use GuzzleHttp\Message\Response;
7
- use GuzzleHttp\Stream\Stream;
8
-
9
- /**
10
- * @covers \GuzzleHttp\Message\AbstractMessage
11
- */
12
- class AbstractMessageTest extends \PHPUnit_Framework_TestCase
13
- {
14
- public function testHasProtocolVersion()
15
- {
16
- $m = new Request('GET', '/');
17
- $this->assertEquals(1.1, $m->getProtocolVersion());
18
- }
19
-
20
- public function testHasHeaders()
21
- {
22
- $m = new Request('GET', 'http://foo.com');
23
- $this->assertFalse($m->hasHeader('foo'));
24
- $m->addHeader('foo', 'bar');
25
- $this->assertTrue($m->hasHeader('foo'));
26
- }
27
-
28
- public function testInitializesMessageWithProtocolVersionOption()
29
- {
30
- $m = new Request('GET', '/', [], null, [
31
- 'protocol_version' => '10'
32
- ]);
33
- $this->assertEquals(10, $m->getProtocolVersion());
34
- }
35
-
36
- public function testHasBody()
37
- {
38
- $m = new Request('GET', 'http://foo.com');
39
- $this->assertNull($m->getBody());
40
- $s = Stream::factory('test');
41
- $m->setBody($s);
42
- $this->assertSame($s, $m->getBody());
43
- $this->assertFalse($m->hasHeader('Content-Length'));
44
- }
45
-
46
- public function testCanRemoveBodyBySettingToNullAndRemovesCommonBodyHeaders()
47
- {
48
- $m = new Request('GET', 'http://foo.com');
49
- $m->setBody(Stream::factory('foo'));
50
- $m->setHeader('Content-Length', 3);
51
- $m->setHeader('Transfer-Encoding', 'chunked');
52
- $m->setBody(null);
53
- $this->assertNull($m->getBody());
54
- $this->assertFalse($m->hasHeader('Content-Length'));
55
- $this->assertFalse($m->hasHeader('Transfer-Encoding'));
56
- }
57
-
58
- public function testCastsToString()
59
- {
60
- $m = new Request('GET', 'http://foo.com');
61
- $m->setHeader('foo', 'bar');
62
- $m->setBody(Stream::factory('baz'));
63
- $this->assertEquals("GET / HTTP/1.1\r\nHost: foo.com\r\nfoo: bar\r\n\r\nbaz", (string) $m);
64
- }
65
-
66
- public function parseParamsProvider()
67
- {
68
- $res1 = array(
69
- array(
70
- '<http:/.../front.jpeg>',
71
- 'rel' => 'front',
72
- 'type' => 'image/jpeg',
73
- ),
74
- array(
75
- '<http://.../back.jpeg>',
76
- 'rel' => 'back',
77
- 'type' => 'image/jpeg',
78
- ),
79
- );
80
-
81
- return array(
82
- array(
83
- '<http:/.../front.jpeg>; rel="front"; type="image/jpeg", <http://.../back.jpeg>; rel=back; type="image/jpeg"',
84
- $res1
85
- ),
86
- array(
87
- '<http:/.../front.jpeg>; rel="front"; type="image/jpeg",<http://.../back.jpeg>; rel=back; type="image/jpeg"',
88
- $res1
89
- ),
90
- array(
91
- 'foo="baz"; bar=123, boo, test="123", foobar="foo;bar"',
92
- array(
93
- array('foo' => 'baz', 'bar' => '123'),
94
- array('boo'),
95
- array('test' => '123'),
96
- array('foobar' => 'foo;bar')
97
- )
98
- ),
99
- array(
100
- '<http://.../side.jpeg?test=1>; rel="side"; type="image/jpeg",<http://.../side.jpeg?test=2>; rel=side; type="image/jpeg"',
101
- array(
102
- array('<http://.../side.jpeg?test=1>', 'rel' => 'side', 'type' => 'image/jpeg'),
103
- array('<http://.../side.jpeg?test=2>', 'rel' => 'side', 'type' => 'image/jpeg')
104
- )
105
- ),
106
- array(
107
- '',
108
- array()
109
- )
110
- );
111
- }
112
-
113
- /**
114
- * @dataProvider parseParamsProvider
115
- */
116
- public function testParseParams($header, $result)
117
- {
118
- $request = new Request('GET', '/', ['foo' => $header]);
119
- $this->assertEquals($result, Request::parseHeader($request, 'foo'));
120
- }
121
-
122
- public function testAddsHeadersWhenNotPresent()
123
- {
124
- $h = new Request('GET', 'http://foo.com');
125
- $h->addHeader('foo', 'bar');
126
- $this->assertInternalType('string', $h->getHeader('foo'));
127
- $this->assertEquals('bar', $h->getHeader('foo'));
128
- }
129
-
130
- public function testAddsHeadersWhenPresentSameCase()
131
- {
132
- $h = new Request('GET', 'http://foo.com');
133
- $h->addHeader('foo', 'bar');
134
- $h->addHeader('foo', 'baz');
135
- $this->assertEquals('bar, baz', $h->getHeader('foo'));
136
- $this->assertEquals(['bar', 'baz'], $h->getHeaderAsArray('foo'));
137
- }
138
-
139
- public function testAddsMultipleHeaders()
140
- {
141
- $h = new Request('GET', 'http://foo.com');
142
- $h->addHeaders([
143
- 'foo' => ' bar',
144
- 'baz' => [' bam ', 'boo']
145
- ]);
146
- $this->assertEquals([
147
- 'foo' => ['bar'],
148
- 'baz' => ['bam', 'boo'],
149
- 'Host' => ['foo.com']
150
- ], $h->getHeaders());
151
- }
152
-
153
- public function testAddsHeadersWhenPresentDifferentCase()
154
- {
155
- $h = new Request('GET', 'http://foo.com');
156
- $h->addHeader('Foo', 'bar');
157
- $h->addHeader('fOO', 'baz');
158
- $this->assertEquals('bar, baz', $h->getHeader('foo'));
159
- }
160
-
161
- public function testAddsHeadersWithArray()
162
- {
163
- $h = new Request('GET', 'http://foo.com');
164
- $h->addHeader('Foo', ['bar', 'baz']);
165
- $this->assertEquals('bar, baz', $h->getHeader('foo'));
166
- }
167
-
168
- public function testGetHeadersReturnsAnArrayOfOverTheWireHeaderValues()
169
- {
170
- $h = new Request('GET', 'http://foo.com');
171
- $h->addHeader('foo', 'bar');
172
- $h->addHeader('Foo', 'baz');
173
- $h->addHeader('boO', 'test');
174
- $result = $h->getHeaders();
175
- $this->assertInternalType('array', $result);
176
- $this->assertArrayHasKey('Foo', $result);
177
- $this->assertArrayNotHasKey('foo', $result);
178
- $this->assertArrayHasKey('boO', $result);
179
- $this->assertEquals(['bar', 'baz'], $result['Foo']);
180
- $this->assertEquals(['test'], $result['boO']);
181
- }
182
-
183
- public function testSetHeaderOverwritesExistingValues()
184
- {
185
- $h = new Request('GET', 'http://foo.com');
186
- $h->setHeader('foo', 'bar');
187
- $this->assertEquals('bar', $h->getHeader('foo'));
188
- $h->setHeader('Foo', 'baz');
189
- $this->assertEquals('baz', $h->getHeader('foo'));
190
- $this->assertArrayHasKey('Foo', $h->getHeaders());
191
- }
192
-
193
- public function testSetHeaderOverwritesExistingValuesUsingHeaderArray()
194
- {
195
- $h = new Request('GET', 'http://foo.com');
196
- $h->setHeader('foo', ['bar']);
197
- $this->assertEquals('bar', $h->getHeader('foo'));
198
- }
199
-
200
- public function testSetHeaderOverwritesExistingValuesUsingArray()
201
- {
202
- $h = new Request('GET', 'http://foo.com');
203
- $h->setHeader('foo', ['bar']);
204
- $this->assertEquals('bar', $h->getHeader('foo'));
205
- }
206
-
207
- public function testSetHeadersOverwritesAllHeaders()
208
- {
209
- $h = new Request('GET', 'http://foo.com');
210
- $h->setHeader('foo', 'bar');
211
- $h->setHeaders(['foo' => 'a', 'boo' => 'b']);
212
- $this->assertEquals(['foo' => ['a'], 'boo' => ['b']], $h->getHeaders());
213
- }
214
-
215
- public function testChecksIfCaseInsensitiveHeaderIsPresent()
216
- {
217
- $h = new Request('GET', 'http://foo.com');
218
- $h->setHeader('foo', 'bar');
219
- $this->assertTrue($h->hasHeader('foo'));
220
- $this->assertTrue($h->hasHeader('Foo'));
221
- $h->setHeader('fOo', 'bar');
222
- $this->assertTrue($h->hasHeader('Foo'));
223
- }
224
-
225
- public function testRemovesHeaders()
226
- {
227
- $h = new Request('GET', 'http://foo.com');
228
- $h->setHeader('foo', 'bar');
229
- $h->removeHeader('foo');
230
- $this->assertFalse($h->hasHeader('foo'));
231
- $h->setHeader('Foo', 'bar');
232
- $h->removeHeader('FOO');
233
- $this->assertFalse($h->hasHeader('foo'));
234
- }
235
-
236
- public function testReturnsCorrectTypeWhenMissing()
237
- {
238
- $h = new Request('GET', 'http://foo.com');
239
- $this->assertInternalType('string', $h->getHeader('foo'));
240
- $this->assertInternalType('array', $h->getHeaderAsArray('foo'));
241
- }
242
-
243
- public function testSetsIntegersAndFloatsAsHeaders()
244
- {
245
- $h = new Request('GET', 'http://foo.com');
246
- $h->setHeader('foo', 10);
247
- $h->setHeader('bar', 10.5);
248
- $h->addHeader('foo', 10);
249
- $h->addHeader('bar', 10.5);
250
- $this->assertSame('10, 10', $h->getHeader('foo'));
251
- $this->assertSame('10.5, 10.5', $h->getHeader('bar'));
252
- }
253
-
254
- public function testGetsResponseStartLine()
255
- {
256
- $m = new Response(200);
257
- $this->assertEquals('HTTP/1.1 200 OK', Response::getStartLine($m));
258
- }
259
-
260
- /**
261
- * @expectedException \InvalidArgumentException
262
- */
263
- public function testThrowsWhenMessageIsUnknown()
264
- {
265
- $m = $this->getMockBuilder('GuzzleHttp\Message\AbstractMessage')
266
- ->getMockForAbstractClass();
267
- AbstractMessage::getStartLine($m);
268
- }
269
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Message/FutureResponseTest.php DELETED
@@ -1,160 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Message;
3
-
4
- use GuzzleHttp\Message\FutureResponse;
5
- use GuzzleHttp\Message\Response;
6
- use GuzzleHttp\Stream\Stream;
7
- use React\Promise\Deferred;
8
- use GuzzleHttp\Tests\Subscriber\MockTest;
9
-
10
- class FutureResponseTest extends \PHPUnit_Framework_TestCase
11
- {
12
- /**
13
- * @expectedException \RuntimeException
14
- * @expectedExceptionMessage Class has no foo property
15
- */
16
- public function testValidatesMagicMethod()
17
- {
18
- $f = MockTest::createFuture(function () {});
19
- $f->foo;
20
- }
21
-
22
- public function testDoesTheSameAsResponseWhenDereferenced()
23
- {
24
- $str = Stream::factory('foo');
25
- $response = new Response(200, ['Foo' => 'bar'], $str);
26
- $future = MockTest::createFuture(function () use ($response) {
27
- return $response;
28
- });
29
- $this->assertFalse($this->readAttribute($future, 'isRealized'));
30
- $this->assertEquals(200, $future->getStatusCode());
31
- $this->assertTrue($this->readAttribute($future, 'isRealized'));
32
- // Deref again does nothing.
33
- $future->wait();
34
- $this->assertTrue($this->readAttribute($future, 'isRealized'));
35
- $this->assertEquals('bar', $future->getHeader('Foo'));
36
- $this->assertEquals(['bar'], $future->getHeaderAsarray('Foo'));
37
- $this->assertSame($response->getHeaders(), $future->getHeaders());
38
- $this->assertSame(
39
- $response->getBody(),
40
- $future->getBody()
41
- );
42
- $this->assertSame(
43
- $response->getProtocolVersion(),
44
- $future->getProtocolVersion()
45
- );
46
- $this->assertSame(
47
- $response->getEffectiveUrl(),
48
- $future->getEffectiveUrl()
49
- );
50
- $future->setEffectiveUrl('foo');
51
- $this->assertEquals('foo', $response->getEffectiveUrl());
52
- $this->assertSame(
53
- $response->getReasonPhrase(),
54
- $future->getReasonPhrase()
55
- );
56
-
57
- $this->assertTrue($future->hasHeader('foo'));
58
-
59
- $future->removeHeader('Foo');
60
- $this->assertFalse($future->hasHeader('foo'));
61
- $this->assertFalse($response->hasHeader('foo'));
62
-
63
- $future->setBody(Stream::factory('true'));
64
- $this->assertEquals('true', (string) $response->getBody());
65
- $this->assertTrue($future->json());
66
- $this->assertSame((string) $response, (string) $future);
67
-
68
- $future->setBody(Stream::factory('<a><b>c</b></a>'));
69
- $this->assertEquals('c', (string) $future->xml()->b);
70
-
71
- $future->addHeader('a', 'b');
72
- $this->assertEquals('b', $future->getHeader('a'));
73
-
74
- $future->addHeaders(['a' => '2']);
75
- $this->assertEquals('b, 2', $future->getHeader('a'));
76
-
77
- $future->setHeader('a', '2');
78
- $this->assertEquals('2', $future->getHeader('a'));
79
-
80
- $future->setHeaders(['a' => '3']);
81
- $this->assertEquals(['a' => ['3']], $future->getHeaders());
82
- }
83
-
84
- public function testCanDereferenceManually()
85
- {
86
- $response = new Response(200, ['Foo' => 'bar']);
87
- $future = MockTest::createFuture(function () use ($response) {
88
- return $response;
89
- });
90
- $this->assertSame($response, $future->wait());
91
- $this->assertTrue($this->readAttribute($future, 'isRealized'));
92
- }
93
-
94
- public function testCanCancel()
95
- {
96
- $c = false;
97
- $deferred = new Deferred();
98
- $future = new FutureResponse(
99
- $deferred->promise(),
100
- function () {},
101
- function () use (&$c) {
102
- $c = true;
103
- return true;
104
- }
105
- );
106
-
107
- $this->assertFalse($this->readAttribute($future, 'isRealized'));
108
- $future->cancel();
109
- $this->assertTrue($this->readAttribute($future, 'isRealized'));
110
- $future->cancel();
111
- }
112
-
113
- public function testCanCancelButReturnsFalseForNoCancelFunction()
114
- {
115
- $future = MockTest::createFuture(function () {});
116
- $future->cancel();
117
- $this->assertTrue($this->readAttribute($future, 'isRealized'));
118
- }
119
-
120
- /**
121
- * @expectedException \GuzzleHttp\Ring\Exception\CancelledFutureAccessException
122
- */
123
- public function testAccessingCancelledResponseThrows()
124
- {
125
- $future = MockTest::createFuture(function () {});
126
- $future->cancel();
127
- $future->getStatusCode();
128
- }
129
-
130
- public function testExceptionInToStringTriggersError()
131
- {
132
- $future = MockTest::createFuture(function () {
133
- throw new \Exception('foo');
134
- });
135
- $err = '';
136
- set_error_handler(function () use (&$err) {
137
- $err = func_get_args()[1];
138
- });
139
- echo $future;
140
- restore_error_handler();
141
- $this->assertContains('foo', $err);
142
- }
143
-
144
- public function testProxiesSetters()
145
- {
146
- $str = Stream::factory('foo');
147
- $response = new Response(200, ['Foo' => 'bar'], $str);
148
- $future = MockTest::createFuture(function () use ($response) {
149
- return $response;
150
- });
151
-
152
- $future->setStatusCode(202);
153
- $this->assertEquals(202, $future->getStatusCode());
154
- $this->assertEquals(202, $response->getStatusCode());
155
-
156
- $future->setReasonPhrase('foo');
157
- $this->assertEquals('foo', $future->getReasonPhrase());
158
- $this->assertEquals('foo', $response->getReasonPhrase());
159
- }
160
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Message/MessageFactoryTest.php DELETED
@@ -1,601 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Message;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Message\RequestInterface;
6
- use GuzzleHttp\Post\PostFile;
7
- use GuzzleHttp\Message\Response;
8
- use GuzzleHttp\Message\MessageFactory;
9
- use GuzzleHttp\Subscriber\Cookie;
10
- use GuzzleHttp\Cookie\CookieJar;
11
- use GuzzleHttp\Query;
12
- use GuzzleHttp\Stream\Stream;
13
- use GuzzleHttp\Subscriber\History;
14
- use GuzzleHttp\Subscriber\Mock;
15
-
16
- /**
17
- * @covers GuzzleHttp\Message\MessageFactory
18
- */
19
- class MessageFactoryTest extends \PHPUnit_Framework_TestCase
20
- {
21
- public function testCreatesResponses()
22
- {
23
- $f = new MessageFactory();
24
- $response = $f->createResponse(200, ['foo' => 'bar'], 'test', [
25
- 'protocol_version' => 1.0
26
- ]);
27
- $this->assertEquals(200, $response->getStatusCode());
28
- $this->assertEquals(['foo' => ['bar']], $response->getHeaders());
29
- $this->assertEquals('test', $response->getBody());
30
- $this->assertEquals(1.0, $response->getProtocolVersion());
31
- }
32
-
33
- public function testCreatesRequestFromMessage()
34
- {
35
- $f = new MessageFactory();
36
- $req = $f->fromMessage("GET / HTTP/1.1\r\nBaz: foo\r\n\r\n");
37
- $this->assertEquals('GET', $req->getMethod());
38
- $this->assertEquals('/', $req->getPath());
39
- $this->assertEquals('foo', $req->getHeader('Baz'));
40
- $this->assertNull($req->getBody());
41
- }
42
-
43
- public function testCreatesRequestFromMessageWithBody()
44
- {
45
- $req = (new MessageFactory())->fromMessage("GET / HTTP/1.1\r\nBaz: foo\r\n\r\ntest");
46
- $this->assertEquals('test', $req->getBody());
47
- }
48
-
49
- public function testCreatesRequestWithPostBody()
50
- {
51
- $req = (new MessageFactory())->createRequest('GET', 'http://www.foo.com', ['body' => ['abc' => '123']]);
52
- $this->assertEquals('abc=123', $req->getBody());
53
- }
54
-
55
- public function testCreatesRequestWithPostBodyScalars()
56
- {
57
- $req = (new MessageFactory())->createRequest(
58
- 'GET',
59
- 'http://www.foo.com',
60
- ['body' => [
61
- 'abc' => true,
62
- '123' => false,
63
- 'foo' => null,
64
- 'baz' => 10,
65
- 'bam' => 1.5,
66
- 'boo' => [1]]
67
- ]
68
- );
69
- $this->assertEquals(
70
- 'abc=1&123=&foo&baz=10&bam=1.5&boo%5B0%5D=1',
71
- (string) $req->getBody()
72
- );
73
- }
74
-
75
- public function testCreatesRequestWithPostBodyAndPostFiles()
76
- {
77
- $pf = fopen(__FILE__, 'r');
78
- $pfi = new PostFile('ghi', 'abc', __FILE__);
79
- $req = (new MessageFactory())->createRequest('GET', 'http://www.foo.com', [
80
- 'body' => [
81
- 'abc' => '123',
82
- 'def' => $pf,
83
- 'ghi' => $pfi
84
- ]
85
- ]);
86
- $this->assertInstanceOf('GuzzleHttp\Post\PostBody', $req->getBody());
87
- $s = (string) $req;
88
- $this->assertContains('testCreatesRequestWithPostBodyAndPostFiles', $s);
89
- $this->assertContains('multipart/form-data', $s);
90
- $this->assertTrue(in_array($pfi, $req->getBody()->getFiles(), true));
91
- }
92
-
93
- public function testCreatesResponseFromMessage()
94
- {
95
- $response = (new MessageFactory())->fromMessage("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ntest");
96
- $this->assertEquals(200, $response->getStatusCode());
97
- $this->assertEquals('OK', $response->getReasonPhrase());
98
- $this->assertEquals('4', $response->getHeader('Content-Length'));
99
- $this->assertEquals('test', $response->getBody(true));
100
- }
101
-
102
- public function testCanCreateHeadResponses()
103
- {
104
- $response = (new MessageFactory())->fromMessage("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\n");
105
- $this->assertEquals(200, $response->getStatusCode());
106
- $this->assertEquals('OK', $response->getReasonPhrase());
107
- $this->assertEquals(null, $response->getBody());
108
- $this->assertEquals('4', $response->getHeader('Content-Length'));
109
- }
110
-
111
- /**
112
- * @expectedException \InvalidArgumentException
113
- */
114
- public function testFactoryRequiresMessageForRequest()
115
- {
116
- (new MessageFactory())->fromMessage('');
117
- }
118
-
119
- /**
120
- * @expectedException \InvalidArgumentException
121
- * @expectedExceptionMessage foo
122
- */
123
- public function testValidatesOptionsAreImplemented()
124
- {
125
- (new MessageFactory())->createRequest('GET', 'http://test.com', ['foo' => 'bar']);
126
- }
127
-
128
- public function testOptionsAddsRequestOptions()
129
- {
130
- $request = (new MessageFactory())->createRequest(
131
- 'GET', 'http://test.com', ['config' => ['baz' => 'bar']]
132
- );
133
- $this->assertEquals('bar', $request->getConfig()->get('baz'));
134
- }
135
-
136
- public function testCanDisableRedirects()
137
- {
138
- $request = (new MessageFactory())->createRequest('GET', '/', ['allow_redirects' => false]);
139
- $this->assertEmpty($request->getEmitter()->listeners('complete'));
140
- }
141
-
142
- /**
143
- * @expectedException \InvalidArgumentException
144
- */
145
- public function testValidatesRedirects()
146
- {
147
- (new MessageFactory())->createRequest('GET', '/', ['allow_redirects' => 'foo']);
148
- }
149
-
150
- public function testCanEnableStrictRedirectsAndSpecifyMax()
151
- {
152
- $request = (new MessageFactory())->createRequest('GET', '/', [
153
- 'allow_redirects' => ['max' => 10, 'strict' => true]
154
- ]);
155
- $this->assertTrue($request->getConfig()['redirect']['strict']);
156
- $this->assertEquals(10, $request->getConfig()['redirect']['max']);
157
- }
158
-
159
- public function testCanAddCookiesFromHash()
160
- {
161
- $request = (new MessageFactory())->createRequest('GET', 'http://www.test.com/', [
162
- 'cookies' => ['Foo' => 'Bar']
163
- ]);
164
- $cookies = null;
165
- foreach ($request->getEmitter()->listeners('before') as $l) {
166
- if ($l[0] instanceof Cookie) {
167
- $cookies = $l[0];
168
- break;
169
- }
170
- }
171
- if (!$cookies) {
172
- $this->fail('Did not add cookie listener');
173
- } else {
174
- $this->assertCount(1, $cookies->getCookieJar());
175
- }
176
- }
177
-
178
- public function testAddsCookieUsingTrue()
179
- {
180
- $factory = new MessageFactory();
181
- $request1 = $factory->createRequest('GET', '/', ['cookies' => true]);
182
- $request2 = $factory->createRequest('GET', '/', ['cookies' => true]);
183
- $listeners = function ($r) {
184
- return array_filter($r->getEmitter()->listeners('before'), function ($l) {
185
- return $l[0] instanceof Cookie;
186
- });
187
- };
188
- $this->assertSame($listeners($request1), $listeners($request2));
189
- }
190
-
191
- public function testAddsCookieFromCookieJar()
192
- {
193
- $jar = new CookieJar();
194
- $request = (new MessageFactory())->createRequest('GET', '/', ['cookies' => $jar]);
195
- foreach ($request->getEmitter()->listeners('before') as $l) {
196
- if ($l[0] instanceof Cookie) {
197
- $this->assertSame($jar, $l[0]->getCookieJar());
198
- }
199
- }
200
- }
201
-
202
- /**
203
- * @expectedException \InvalidArgumentException
204
- */
205
- public function testValidatesCookies()
206
- {
207
- (new MessageFactory())->createRequest('GET', '/', ['cookies' => 'baz']);
208
- }
209
-
210
- public function testCanAddQuery()
211
- {
212
- $request = (new MessageFactory())->createRequest('GET', 'http://foo.com', [
213
- 'query' => ['Foo' => 'Bar']
214
- ]);
215
- $this->assertEquals('Bar', $request->getQuery()->get('Foo'));
216
- }
217
-
218
- /**
219
- * @expectedException \InvalidArgumentException
220
- */
221
- public function testValidatesQuery()
222
- {
223
- (new MessageFactory())->createRequest('GET', 'http://foo.com', [
224
- 'query' => 'foo'
225
- ]);
226
- }
227
-
228
- public function testCanSetDefaultQuery()
229
- {
230
- $request = (new MessageFactory())->createRequest('GET', 'http://foo.com?test=abc', [
231
- 'query' => ['Foo' => 'Bar', 'test' => 'def']
232
- ]);
233
- $this->assertEquals('Bar', $request->getQuery()->get('Foo'));
234
- $this->assertEquals('abc', $request->getQuery()->get('test'));
235
- }
236
-
237
- public function testCanSetDefaultQueryWithObject()
238
- {
239
- $request = (new MessageFactory)->createRequest(
240
- 'GET',
241
- 'http://foo.com?test=abc', [
242
- 'query' => new Query(['Foo' => 'Bar', 'test' => 'def'])
243
- ]
244
- );
245
- $this->assertEquals('Bar', $request->getQuery()->get('Foo'));
246
- $this->assertEquals('abc', $request->getQuery()->get('test'));
247
- }
248
-
249
- public function testCanAddBasicAuth()
250
- {
251
- $request = (new MessageFactory())->createRequest('GET', 'http://foo.com', [
252
- 'auth' => ['michael', 'test']
253
- ]);
254
- $this->assertTrue($request->hasHeader('Authorization'));
255
- }
256
-
257
- public function testCanAddDigestAuth()
258
- {
259
- $request = (new MessageFactory())->createRequest('GET', 'http://foo.com', [
260
- 'auth' => ['michael', 'test', 'digest']
261
- ]);
262
- $this->assertEquals('michael:test', $request->getConfig()->getPath('curl/' . CURLOPT_USERPWD));
263
- $this->assertEquals(CURLAUTH_DIGEST, $request->getConfig()->getPath('curl/' . CURLOPT_HTTPAUTH));
264
- }
265
-
266
- public function testCanDisableAuth()
267
- {
268
- $request = (new MessageFactory())->createRequest('GET', 'http://foo.com', [
269
- 'auth' => false
270
- ]);
271
- $this->assertFalse($request->hasHeader('Authorization'));
272
- }
273
-
274
- public function testCanSetCustomAuth()
275
- {
276
- $request = (new MessageFactory())->createRequest('GET', 'http://foo.com', [
277
- 'auth' => 'foo'
278
- ]);
279
- $this->assertEquals('foo', $request->getConfig()['auth']);
280
- }
281
-
282
- public function testCanAddEvents()
283
- {
284
- $foo = null;
285
- $client = new Client();
286
- $client->getEmitter()->attach(new Mock([new Response(200)]));
287
- $client->get('http://test.com', [
288
- 'events' => [
289
- 'before' => function () use (&$foo) { $foo = true; }
290
- ]
291
- ]);
292
- $this->assertTrue($foo);
293
- }
294
-
295
- public function testCanAddEventsWithPriority()
296
- {
297
- $foo = null;
298
- $client = new Client();
299
- $client->getEmitter()->attach(new Mock(array(new Response(200))));
300
- $request = $client->createRequest('GET', 'http://test.com', [
301
- 'events' => [
302
- 'before' => [
303
- 'fn' => function () use (&$foo) { $foo = true; },
304
- 'priority' => 123
305
- ]
306
- ]
307
- ]);
308
- $client->send($request);
309
- $this->assertTrue($foo);
310
- $l = $this->readAttribute($request->getEmitter(), 'listeners');
311
- $this->assertArrayHasKey(123, $l['before']);
312
- }
313
-
314
- public function testCanAddEventsOnce()
315
- {
316
- $foo = 0;
317
- $client = new Client();
318
- $client->getEmitter()->attach(new Mock([
319
- new Response(200),
320
- new Response(200),
321
- ]));
322
- $fn = function () use (&$foo) { ++$foo; };
323
- $request = $client->createRequest('GET', 'http://test.com', [
324
- 'events' => ['before' => ['fn' => $fn, 'once' => true]]
325
- ]);
326
- $client->send($request);
327
- $this->assertEquals(1, $foo);
328
- $client->send($request);
329
- $this->assertEquals(1, $foo);
330
- }
331
-
332
- /**
333
- * @expectedException \InvalidArgumentException
334
- */
335
- public function testValidatesEventContainsFn()
336
- {
337
- $client = new Client(['base_url' => 'http://test.com']);
338
- $client->createRequest('GET', '/', ['events' => ['before' => ['foo' => 'bar']]]);
339
- }
340
-
341
- /**
342
- * @expectedException \InvalidArgumentException
343
- */
344
- public function testValidatesEventIsArray()
345
- {
346
- $client = new Client(['base_url' => 'http://test.com']);
347
- $client->createRequest('GET', '/', ['events' => ['before' => '123']]);
348
- }
349
-
350
- public function testCanAddSubscribers()
351
- {
352
- $mock = new Mock([new Response(200)]);
353
- $client = new Client();
354
- $client->getEmitter()->attach($mock);
355
- $client->get('http://test.com', ['subscribers' => [$mock]]);
356
- }
357
-
358
- public function testCanDisableExceptions()
359
- {
360
- $client = new Client();
361
- $this->assertEquals(500, $client->get('http://test.com', [
362
- 'subscribers' => [new Mock([new Response(500)])],
363
- 'exceptions' => false
364
- ])->getStatusCode());
365
- }
366
-
367
- public function testCanChangeSaveToLocation()
368
- {
369
- $saveTo = Stream::factory();
370
- $request = (new MessageFactory())->createRequest('GET', '/', ['save_to' => $saveTo]);
371
- $this->assertSame($saveTo, $request->getConfig()->get('save_to'));
372
- }
373
-
374
- public function testCanSetProxy()
375
- {
376
- $request = (new MessageFactory())->createRequest('GET', '/', ['proxy' => '192.168.16.121']);
377
- $this->assertEquals('192.168.16.121', $request->getConfig()->get('proxy'));
378
- }
379
-
380
- public function testCanSetHeadersOption()
381
- {
382
- $request = (new MessageFactory())->createRequest('GET', '/', ['headers' => ['Foo' => 'Bar']]);
383
- $this->assertEquals('Bar', (string) $request->getHeader('Foo'));
384
- }
385
-
386
- public function testCanSetHeaders()
387
- {
388
- $request = (new MessageFactory())->createRequest('GET', '/', [
389
- 'headers' => ['Foo' => ['Baz', 'Bar'], 'Test' => '123']
390
- ]);
391
- $this->assertEquals('Baz, Bar', $request->getHeader('Foo'));
392
- $this->assertEquals('123', $request->getHeader('Test'));
393
- }
394
-
395
- public function testCanSetTimeoutOption()
396
- {
397
- $request = (new MessageFactory())->createRequest('GET', '/', ['timeout' => 1.5]);
398
- $this->assertEquals(1.5, $request->getConfig()->get('timeout'));
399
- }
400
-
401
- public function testCanSetConnectTimeoutOption()
402
- {
403
- $request = (new MessageFactory())->createRequest('GET', '/', ['connect_timeout' => 1.5]);
404
- $this->assertEquals(1.5, $request->getConfig()->get('connect_timeout'));
405
- }
406
-
407
- public function testCanSetDebug()
408
- {
409
- $request = (new MessageFactory())->createRequest('GET', '/', ['debug' => true]);
410
- $this->assertTrue($request->getConfig()->get('debug'));
411
- }
412
-
413
- public function testCanSetVerifyToOff()
414
- {
415
- $request = (new MessageFactory())->createRequest('GET', '/', ['verify' => false]);
416
- $this->assertFalse($request->getConfig()->get('verify'));
417
- }
418
-
419
- public function testCanSetVerifyToOn()
420
- {
421
- $request = (new MessageFactory())->createRequest('GET', '/', ['verify' => true]);
422
- $this->assertTrue($request->getConfig()->get('verify'));
423
- }
424
-
425
- public function testCanSetVerifyToPath()
426
- {
427
- $request = (new MessageFactory())->createRequest('GET', '/', ['verify' => '/foo.pem']);
428
- $this->assertEquals('/foo.pem', $request->getConfig()->get('verify'));
429
- }
430
-
431
- public function inputValidation()
432
- {
433
- return array_map(function ($option) { return array($option); }, array(
434
- 'headers', 'events', 'subscribers', 'params'
435
- ));
436
- }
437
-
438
- /**
439
- * @dataProvider inputValidation
440
- * @expectedException \InvalidArgumentException
441
- */
442
- public function testValidatesInput($option)
443
- {
444
- (new MessageFactory())->createRequest('GET', '/', [$option => 'foo']);
445
- }
446
-
447
- public function testCanAddSslKey()
448
- {
449
- $request = (new MessageFactory())->createRequest('GET', '/', ['ssl_key' => '/foo.pem']);
450
- $this->assertEquals('/foo.pem', $request->getConfig()->get('ssl_key'));
451
- }
452
-
453
- public function testCanAddSslKeyPassword()
454
- {
455
- $request = (new MessageFactory())->createRequest('GET', '/', ['ssl_key' => ['/foo.pem', 'bar']]);
456
- $this->assertEquals(['/foo.pem', 'bar'], $request->getConfig()->get('ssl_key'));
457
- }
458
-
459
- public function testCanAddSslCert()
460
- {
461
- $request = (new MessageFactory())->createRequest('GET', '/', ['cert' => '/foo.pem']);
462
- $this->assertEquals('/foo.pem', $request->getConfig()->get('cert'));
463
- }
464
-
465
- public function testCanAddSslCertPassword()
466
- {
467
- $request = (new MessageFactory())->createRequest('GET', '/', ['cert' => ['/foo.pem', 'bar']]);
468
- $this->assertEquals(['/foo.pem', 'bar'], $request->getConfig()->get('cert'));
469
- }
470
-
471
- public function testCreatesBodyWithoutZeroString()
472
- {
473
- $request = (new MessageFactory())->createRequest('PUT', 'http://test.com', ['body' => '0']);
474
- $this->assertSame('0', (string) $request->getBody());
475
- }
476
-
477
- public function testCanSetProtocolVersion()
478
- {
479
- $request = (new MessageFactory())->createRequest('GET', 'http://t.com', ['version' => 1.0]);
480
- $this->assertEquals(1.0, $request->getProtocolVersion());
481
- }
482
-
483
- public function testCanAddJsonData()
484
- {
485
- $request = (new MessageFactory())->createRequest('PUT', 'http://f.com', [
486
- 'json' => ['foo' => 'bar']
487
- ]);
488
- $this->assertEquals(
489
- 'application/json',
490
- $request->getHeader('Content-Type')
491
- );
492
- $this->assertEquals('{"foo":"bar"}', (string) $request->getBody());
493
- }
494
-
495
- public function testCanAddJsonDataToAPostRequest()
496
- {
497
- $request = (new MessageFactory())->createRequest('POST', 'http://f.com', [
498
- 'json' => ['foo' => 'bar']
499
- ]);
500
- $this->assertEquals(
501
- 'application/json',
502
- $request->getHeader('Content-Type')
503
- );
504
- $this->assertEquals('{"foo":"bar"}', (string) $request->getBody());
505
- }
506
-
507
- public function testCanAddJsonDataAndNotOverwriteContentType()
508
- {
509
- $request = (new MessageFactory())->createRequest('PUT', 'http://f.com', [
510
- 'headers' => ['Content-Type' => 'foo'],
511
- 'json' => null
512
- ]);
513
- $this->assertEquals('foo', $request->getHeader('Content-Type'));
514
- $this->assertEquals('null', (string) $request->getBody());
515
- }
516
-
517
- public function testCanUseCustomRequestOptions()
518
- {
519
- $c = false;
520
- $f = new MessageFactory([
521
- 'foo' => function (RequestInterface $request, $value) use (&$c) {
522
- $c = true;
523
- $this->assertEquals('bar', $value);
524
- }
525
- ]);
526
-
527
- $f->createRequest('PUT', 'http://f.com', [
528
- 'headers' => ['Content-Type' => 'foo'],
529
- 'foo' => 'bar'
530
- ]);
531
-
532
- $this->assertTrue($c);
533
- }
534
-
535
- /**
536
- * @ticket https://github.com/guzzle/guzzle/issues/706
537
- */
538
- public function testDoesNotApplyPostBodyRightAway()
539
- {
540
- $request = (new MessageFactory())->createRequest('POST', 'http://f.cn', [
541
- 'body' => ['foo' => ['bar', 'baz']]
542
- ]);
543
- $this->assertEquals('', $request->getHeader('Content-Type'));
544
- $this->assertEquals('', $request->getHeader('Content-Length'));
545
- $request->getBody()->setAggregator(Query::duplicateAggregator());
546
- $request->getBody()->applyRequestHeaders($request);
547
- $this->assertEquals('foo=bar&foo=baz', $request->getBody());
548
- }
549
-
550
- public function testCanForceMultipartUploadWithContentType()
551
- {
552
- $client = new Client();
553
- $client->getEmitter()->attach(new Mock([new Response(200)]));
554
- $history = new History();
555
- $client->getEmitter()->attach($history);
556
- $client->post('http://foo.com', [
557
- 'headers' => ['Content-Type' => 'multipart/form-data'],
558
- 'body' => ['foo' => 'bar']
559
- ]);
560
- $this->assertContains(
561
- 'multipart/form-data; boundary=',
562
- $history->getLastRequest()->getHeader('Content-Type')
563
- );
564
- $this->assertContains(
565
- "Content-Disposition: form-data; name=\"foo\"\r\n\r\nbar",
566
- (string) $history->getLastRequest()->getBody()
567
- );
568
- }
569
-
570
- public function testDecodeDoesNotForceAcceptHeader()
571
- {
572
- $request = (new MessageFactory())->createRequest('POST', 'http://f.cn', [
573
- 'decode_content' => true
574
- ]);
575
- $this->assertEquals('', $request->getHeader('Accept-Encoding'));
576
- $this->assertTrue($request->getConfig()->get('decode_content'));
577
- }
578
-
579
- public function testDecodeCanAddAcceptHeader()
580
- {
581
- $request = (new MessageFactory())->createRequest('POST', 'http://f.cn', [
582
- 'decode_content' => 'gzip'
583
- ]);
584
- $this->assertEquals('gzip', $request->getHeader('Accept-Encoding'));
585
- $this->assertTrue($request->getConfig()->get('decode_content'));
586
- }
587
-
588
- public function testCanDisableDecoding()
589
- {
590
- $request = (new MessageFactory())->createRequest('POST', 'http://f.cn', [
591
- 'decode_content' => false
592
- ]);
593
- $this->assertEquals('', $request->getHeader('Accept-Encoding'));
594
- $this->assertNull($request->getConfig()->get('decode_content'));
595
- }
596
- }
597
-
598
- class ExtendedFactory extends MessageFactory
599
- {
600
- protected function add_foo() {}
601
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Message/MessageParserTest.php DELETED
@@ -1,276 +0,0 @@
1
- <?php
2
-
3
- namespace GuzzleHttp\Tests\Message;
4
-
5
- use GuzzleHttp\Message\MessageParser;
6
-
7
- /**
8
- * @covers \GuzzleHttp\Message\MessageParser
9
- */
10
- class MessageParserTest extends \PHPUnit_Framework_TestCase
11
- {
12
- /**
13
- * @dataProvider requestProvider
14
- */
15
- public function testParsesRequests($message, $parts)
16
- {
17
- $parser = new MessageParser();
18
- $this->compareRequestResults($parts, $parser->parseRequest($message));
19
- }
20
-
21
- /**
22
- * @dataProvider responseProvider
23
- */
24
- public function testParsesResponses($message, $parts)
25
- {
26
- $parser = new MessageParser();
27
- $this->compareResponseResults($parts, $parser->parseResponse($message));
28
- }
29
-
30
- public function testParsesRequestsWithMissingProtocol()
31
- {
32
- $parser = new MessageParser();
33
- $parts = $parser->parseRequest("GET /\r\nHost: Foo.com\r\n\r\n");
34
- $this->assertEquals('GET', $parts['method']);
35
- $this->assertEquals('HTTP', $parts['protocol']);
36
- $this->assertEquals('1.1', $parts['protocol_version']);
37
- }
38
-
39
- public function testParsesRequestsWithMissingVersion()
40
- {
41
- $parser = new MessageParser();
42
- $parts = $parser->parseRequest("GET / HTTP\r\nHost: Foo.com\r\n\r\n");
43
- $this->assertEquals('GET', $parts['method']);
44
- $this->assertEquals('HTTP', $parts['protocol']);
45
- $this->assertEquals('1.1', $parts['protocol_version']);
46
- }
47
-
48
- public function testParsesResponsesWithMissingReasonPhrase()
49
- {
50
- $parser = new MessageParser();
51
- $parts = $parser->parseResponse("HTTP/1.1 200\r\n\r\n");
52
- $this->assertEquals('200', $parts['code']);
53
- $this->assertEquals('', $parts['reason_phrase']);
54
- $this->assertEquals('HTTP', $parts['protocol']);
55
- $this->assertEquals('1.1', $parts['protocol_version']);
56
- }
57
-
58
- public function requestProvider()
59
- {
60
- $auth = base64_encode('michael:foo');
61
-
62
- return array(
63
-
64
- // Empty request
65
- array('', false),
66
-
67
- // Converts casing of request. Does not require host header.
68
- array("GET / HTTP/1.1\r\n\r\n", array(
69
- 'method' => 'GET',
70
- 'protocol' => 'HTTP',
71
- 'protocol_version' => '1.1',
72
- 'request_url' => array(
73
- 'scheme' => 'http',
74
- 'host' => '',
75
- 'port' => '',
76
- 'path' => '/',
77
- 'query' => ''
78
- ),
79
- 'headers' => array(),
80
- 'body' => ''
81
- )),
82
- // Path and query string, multiple header values per header and case sensitive storage
83
- array("HEAD /path?query=foo HTTP/1.0\r\nHost: example.com\r\nX-Foo: foo\r\nx-foo: Bar\r\nX-Foo: foo\r\nX-Foo: Baz\r\n\r\n", array(
84
- 'method' => 'HEAD',
85
- 'protocol' => 'HTTP',
86
- 'protocol_version' => '1.0',
87
- 'request_url' => array(
88
- 'scheme' => 'http',
89
- 'host' => 'example.com',
90
- 'port' => '',
91
- 'path' => '/path',
92
- 'query' => 'query=foo'
93
- ),
94
- 'headers' => array(
95
- 'Host' => 'example.com',
96
- 'X-Foo' => array('foo', 'foo', 'Baz'),
97
- 'x-foo' => 'Bar'
98
- ),
99
- 'body' => ''
100
- )),
101
- // Includes a body
102
- array("PUT / HTTP/1.0\r\nhost: example.com:443\r\nContent-Length: 4\r\n\r\ntest", array(
103
- 'method' => 'PUT',
104
- 'protocol' => 'HTTP',
105
- 'protocol_version' => '1.0',
106
- 'request_url' => array(
107
- 'scheme' => 'https',
108
- 'host' => 'example.com',
109
- 'port' => '443',
110
- 'path' => '/',
111
- 'query' => ''
112
- ),
113
- 'headers' => array(
114
- 'host' => 'example.com:443',
115
- 'Content-Length' => '4'
116
- ),
117
- 'body' => 'test'
118
- )),
119
- // Includes Authorization headers
120
- array("GET / HTTP/1.1\r\nHost: example.com:8080\r\nAuthorization: Basic {$auth}\r\n\r\n", array(
121
- 'method' => 'GET',
122
- 'protocol' => 'HTTP',
123
- 'protocol_version' => '1.1',
124
- 'request_url' => array(
125
- 'scheme' => 'http',
126
- 'host' => 'example.com',
127
- 'port' => '8080',
128
- 'path' => '/',
129
- 'query' => ''
130
- ),
131
- 'headers' => array(
132
- 'Host' => 'example.com:8080',
133
- 'Authorization' => "Basic {$auth}"
134
- ),
135
- 'body' => ''
136
- )),
137
- // Include authorization header
138
- array("GET / HTTP/1.1\r\nHost: example.com:8080\r\nauthorization: Basic {$auth}\r\n\r\n", array(
139
- 'method' => 'GET',
140
- 'protocol' => 'HTTP',
141
- 'protocol_version' => '1.1',
142
- 'request_url' => array(
143
- 'scheme' => 'http',
144
- 'host' => 'example.com',
145
- 'port' => '8080',
146
- 'path' => '/',
147
- 'query' => ''
148
- ),
149
- 'headers' => array(
150
- 'Host' => 'example.com:8080',
151
- 'authorization' => "Basic {$auth}"
152
- ),
153
- 'body' => ''
154
- )),
155
- );
156
- }
157
-
158
- public function responseProvider()
159
- {
160
- return array(
161
- // Empty request
162
- array('', false),
163
-
164
- array("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", array(
165
- 'protocol' => 'HTTP',
166
- 'protocol_version' => '1.1',
167
- 'code' => '200',
168
- 'reason_phrase' => 'OK',
169
- 'headers' => array(
170
- 'Content-Length' => 0
171
- ),
172
- 'body' => ''
173
- )),
174
- array("HTTP/1.0 400 Bad Request\r\nContent-Length: 0\r\n\r\n", array(
175
- 'protocol' => 'HTTP',
176
- 'protocol_version' => '1.0',
177
- 'code' => '400',
178
- 'reason_phrase' => 'Bad Request',
179
- 'headers' => array(
180
- 'Content-Length' => 0
181
- ),
182
- 'body' => ''
183
- )),
184
- array("HTTP/1.0 100 Continue\r\n\r\n", array(
185
- 'protocol' => 'HTTP',
186
- 'protocol_version' => '1.0',
187
- 'code' => '100',
188
- 'reason_phrase' => 'Continue',
189
- 'headers' => array(),
190
- 'body' => ''
191
- )),
192
- array("HTTP/1.1 204 No Content\r\nX-Foo: foo\r\nx-foo: Bar\r\nX-Foo: foo\r\n\r\n", array(
193
- 'protocol' => 'HTTP',
194
- 'protocol_version' => '1.1',
195
- 'code' => '204',
196
- 'reason_phrase' => 'No Content',
197
- 'headers' => array(
198
- 'X-Foo' => array('foo', 'foo'),
199
- 'x-foo' => 'Bar'
200
- ),
201
- 'body' => ''
202
- )),
203
- array("HTTP/1.1 200 Ok that is great!\r\nContent-Length: 4\r\n\r\nTest", array(
204
- 'protocol' => 'HTTP',
205
- 'protocol_version' => '1.1',
206
- 'code' => '200',
207
- 'reason_phrase' => 'Ok that is great!',
208
- 'headers' => array(
209
- 'Content-Length' => 4
210
- ),
211
- 'body' => 'Test'
212
- )),
213
- );
214
- }
215
-
216
- public function compareRequestResults($result, $expected)
217
- {
218
- if (!$result) {
219
- $this->assertFalse($expected);
220
- return;
221
- }
222
-
223
- $this->assertEquals($result['method'], $expected['method']);
224
- $this->assertEquals($result['protocol'], $expected['protocol']);
225
- $this->assertEquals($result['protocol_version'], $expected['protocol_version']);
226
- $this->assertEquals($result['request_url'], $expected['request_url']);
227
- $this->assertEquals($result['body'], $expected['body']);
228
- $this->compareHttpHeaders($result['headers'], $expected['headers']);
229
- }
230
-
231
- public function compareResponseResults($result, $expected)
232
- {
233
- if (!$result) {
234
- $this->assertFalse($expected);
235
- return;
236
- }
237
-
238
- $this->assertEquals($result['protocol'], $expected['protocol']);
239
- $this->assertEquals($result['protocol_version'], $expected['protocol_version']);
240
- $this->assertEquals($result['code'], $expected['code']);
241
- $this->assertEquals($result['reason_phrase'], $expected['reason_phrase']);
242
- $this->assertEquals($result['body'], $expected['body']);
243
- $this->compareHttpHeaders($result['headers'], $expected['headers']);
244
- }
245
-
246
- protected function normalizeHeaders($headers)
247
- {
248
- $normalized = array();
249
- foreach ($headers as $key => $value) {
250
- $key = strtolower($key);
251
- if (!isset($normalized[$key])) {
252
- $normalized[$key] = $value;
253
- } elseif (!is_array($normalized[$key])) {
254
- $normalized[$key] = array($value);
255
- } else {
256
- $normalized[$key][] = $value;
257
- }
258
- }
259
-
260
- foreach ($normalized as $key => &$value) {
261
- if (is_array($value)) {
262
- sort($value);
263
- }
264
- }
265
-
266
- return $normalized;
267
- }
268
-
269
- public function compareHttpHeaders($result, $expected)
270
- {
271
- // Aggregate all headers case-insensitively
272
- $result = $this->normalizeHeaders($result);
273
- $expected = $this->normalizeHeaders($expected);
274
- $this->assertEquals($result, $expected);
275
- }
276
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Message/RequestTest.php DELETED
@@ -1,144 +0,0 @@
1
- <?php
2
-
3
- namespace GuzzleHttp\Tests\Message;
4
-
5
- use GuzzleHttp\Event\Emitter;
6
- use GuzzleHttp\Message\Request;
7
- use GuzzleHttp\Query;
8
- use GuzzleHttp\Stream\Stream;
9
-
10
- /**
11
- * @covers GuzzleHttp\Message\Request
12
- */
13
- class RequestTest extends \PHPUnit_Framework_TestCase
14
- {
15
- public function testConstructorInitializesMessage()
16
- {
17
- $r = new Request('PUT', '/test', ['test' => '123'], Stream::factory('foo'));
18
- $this->assertEquals('PUT', $r->getMethod());
19
- $this->assertEquals('/test', $r->getUrl());
20
- $this->assertEquals('123', $r->getHeader('test'));
21
- $this->assertEquals('foo', $r->getBody());
22
- }
23
-
24
- public function testConstructorInitializesMessageWithMixedCaseHeaders()
25
- {
26
- $r = new Request('GET', '/test', [
27
- 'Set-Cookie' => 'foo=bar, baz=bam',
28
- 'Set-cookie' => 'hi=there',
29
- 'other' => ['1', '2']
30
- ]);
31
-
32
- $this->assertEquals('foo=bar, baz=bam, hi=there', $r->getHeader('Set-Cookie'));
33
- $this->assertEquals('1, 2', $r->getHeader('other'));
34
- }
35
-
36
- public function testConstructorInitializesMessageWithProtocolVersion()
37
- {
38
- $r = new Request('GET', '', [], null, ['protocol_version' => 10]);
39
- $this->assertEquals(10, $r->getProtocolVersion());
40
- }
41
-
42
- public function testConstructorInitializesMessageWithEmitter()
43
- {
44
- $e = new Emitter();
45
- $r = new Request('GET', '', [], null, ['emitter' => $e]);
46
- $this->assertSame($r->getEmitter(), $e);
47
- }
48
-
49
- public function testCloneIsDeep()
50
- {
51
- $r = new Request('GET', '/test', ['foo' => 'baz'], Stream::factory('foo'));
52
- $r2 = clone $r;
53
-
54
- $this->assertNotSame($r->getEmitter(), $r2->getEmitter());
55
- $this->assertEquals('foo', $r2->getBody());
56
-
57
- $r->getConfig()->set('test', 123);
58
- $this->assertFalse($r2->getConfig()->hasKey('test'));
59
-
60
- $r->setPath('/abc');
61
- $this->assertEquals('/test', $r2->getPath());
62
- }
63
-
64
- public function testCastsToString()
65
- {
66
- $r = new Request('GET', 'http://test.com/test', ['foo' => 'baz'], Stream::factory('body'));
67
- $s = explode("\r\n", (string) $r);
68
- $this->assertEquals("GET /test HTTP/1.1", $s[0]);
69
- $this->assertContains('Host: test.com', $s);
70
- $this->assertContains('foo: baz', $s);
71
- $this->assertContains('', $s);
72
- $this->assertContains('body', $s);
73
- }
74
-
75
- public function testSettingUrlOverridesHostHeaders()
76
- {
77
- $r = new Request('GET', 'http://test.com/test');
78
- $r->setUrl('https://baz.com/bar');
79
- $this->assertEquals('baz.com', $r->getHost());
80
- $this->assertEquals('baz.com', $r->getHeader('Host'));
81
- $this->assertEquals('/bar', $r->getPath());
82
- $this->assertEquals('https', $r->getScheme());
83
- }
84
-
85
- public function testQueryIsMutable()
86
- {
87
- $r = new Request('GET', 'http://www.foo.com?baz=bar');
88
- $this->assertEquals('baz=bar', $r->getQuery());
89
- $this->assertInstanceOf('GuzzleHttp\Query', $r->getQuery());
90
- $r->getQuery()->set('hi', 'there');
91
- $this->assertEquals('/?baz=bar&hi=there', $r->getResource());
92
- }
93
-
94
- public function testQueryCanChange()
95
- {
96
- $r = new Request('GET', 'http://www.foo.com?baz=bar');
97
- $r->setQuery(new Query(['foo' => 'bar']));
98
- $this->assertEquals('foo=bar', $r->getQuery());
99
- }
100
-
101
- public function testCanChangeMethod()
102
- {
103
- $r = new Request('GET', 'http://www.foo.com');
104
- $r->setMethod('put');
105
- $this->assertEquals('PUT', $r->getMethod());
106
- }
107
-
108
- public function testCanChangeSchemeWithPort()
109
- {
110
- $r = new Request('GET', 'http://www.foo.com:80');
111
- $r->setScheme('https');
112
- $this->assertEquals('https://www.foo.com', $r->getUrl());
113
- }
114
-
115
- public function testCanChangeScheme()
116
- {
117
- $r = new Request('GET', 'http://www.foo.com');
118
- $r->setScheme('https');
119
- $this->assertEquals('https://www.foo.com', $r->getUrl());
120
- }
121
-
122
- public function testCanChangeHost()
123
- {
124
- $r = new Request('GET', 'http://www.foo.com:222');
125
- $r->setHost('goo');
126
- $this->assertEquals('http://goo:222', $r->getUrl());
127
- $this->assertEquals('goo:222', $r->getHeader('host'));
128
- $r->setHost('goo:80');
129
- $this->assertEquals('http://goo', $r->getUrl());
130
- $this->assertEquals('goo', $r->getHeader('host'));
131
- }
132
-
133
- public function testCanChangePort()
134
- {
135
- $r = new Request('GET', 'http://www.foo.com:222');
136
- $this->assertSame(222, $r->getPort());
137
- $this->assertEquals('www.foo.com', $r->getHost());
138
- $this->assertEquals('www.foo.com:222', $r->getHeader('host'));
139
- $r->setPort(80);
140
- $this->assertSame(80, $r->getPort());
141
- $this->assertEquals('www.foo.com', $r->getHost());
142
- $this->assertEquals('www.foo.com', $r->getHeader('host'));
143
- }
144
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Message/ResponseTest.php DELETED
@@ -1,120 +0,0 @@
1
- <?php
2
-
3
- namespace GuzzleHttp\Tests\Message;
4
-
5
- use GuzzleHttp\Exception\XmlParseException;
6
- use GuzzleHttp\Message\Response;
7
- use GuzzleHttp\Stream\Stream;
8
-
9
- /**
10
- * @covers GuzzleHttp\Message\Response
11
- */
12
- class ResponseTest extends \PHPUnit_Framework_TestCase
13
- {
14
- public function testCanProvideCustomStatusCodeAndReasonPhrase()
15
- {
16
- $response = new Response(999, [], null, ['reason_phrase' => 'hi!']);
17
- $this->assertEquals(999, $response->getStatusCode());
18
- $this->assertEquals('hi!', $response->getReasonPhrase());
19
- }
20
-
21
- public function testConvertsToString()
22
- {
23
- $response = new Response(200);
24
- $this->assertEquals("HTTP/1.1 200 OK\r\n\r\n", (string) $response);
25
- // Add another header
26
- $response = new Response(200, ['X-Test' => 'Guzzle']);
27
- $this->assertEquals("HTTP/1.1 200 OK\r\nX-Test: Guzzle\r\n\r\n", (string) $response);
28
- $response = new Response(200, ['Content-Length' => 4], Stream::factory('test'));
29
- $this->assertEquals("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ntest", (string) $response);
30
- }
31
-
32
- public function testConvertsToStringAndSeeksToByteZero()
33
- {
34
- $response = new Response(200);
35
- $s = Stream::factory('foo');
36
- $s->read(1);
37
- $response->setBody($s);
38
- $this->assertEquals("HTTP/1.1 200 OK\r\n\r\nfoo", (string) $response);
39
- }
40
-
41
- public function testParsesJsonResponses()
42
- {
43
- $json = '{"foo": "bar"}';
44
- $response = new Response(200, [], Stream::factory($json));
45
- $this->assertEquals(['foo' => 'bar'], $response->json());
46
- $this->assertEquals(json_decode($json), $response->json(['object' => true]));
47
-
48
- $response = new Response(200);
49
- $this->assertEquals(null, $response->json());
50
- }
51
-
52
- /**
53
- * @expectedException \GuzzleHttp\Exception\ParseException
54
- * @expectedExceptionMessage Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, malformed JSON
55
- */
56
- public function testThrowsExceptionWhenFailsToParseJsonResponse()
57
- {
58
- $response = new Response(200, [], Stream::factory('{"foo": "'));
59
- $response->json();
60
- }
61
-
62
- public function testParsesXmlResponses()
63
- {
64
- $response = new Response(200, [], Stream::factory('<abc><foo>bar</foo></abc>'));
65
- $this->assertEquals('bar', (string) $response->xml()->foo);
66
- // Always return a SimpleXMLElement from the xml method
67
- $response = new Response(200);
68
- $this->assertEmpty((string) $response->xml()->foo);
69
- }
70
-
71
- /**
72
- * @expectedException \GuzzleHttp\Exception\XmlParseException
73
- * @expectedExceptionMessage Unable to parse response body into XML: String could not be parsed as XML
74
- */
75
- public function testThrowsExceptionWhenFailsToParseXmlResponse()
76
- {
77
- $response = new Response(200, [], Stream::factory('<abc'));
78
- try {
79
- $response->xml();
80
- } catch (XmlParseException $e) {
81
- $xmlParseError = $e->getError();
82
- $this->assertInstanceOf('\LibXMLError', $xmlParseError);
83
- $this->assertContains("Couldn't find end of Start Tag abc line 1", $xmlParseError->message);
84
- throw $e;
85
- }
86
- }
87
-
88
- public function testHasEffectiveUrl()
89
- {
90
- $r = new Response(200);
91
- $this->assertNull($r->getEffectiveUrl());
92
- $r->setEffectiveUrl('http://www.test.com');
93
- $this->assertEquals('http://www.test.com', $r->getEffectiveUrl());
94
- }
95
-
96
- public function testPreventsComplexExternalEntities()
97
- {
98
- $xml = '<?xml version="1.0"?><!DOCTYPE scan[<!ENTITY test SYSTEM "php://filter/read=convert.base64-encode/resource=ResponseTest.php">]><scan>&test;</scan>';
99
- $response = new Response(200, [], Stream::factory($xml));
100
-
101
- $oldCwd = getcwd();
102
- chdir(__DIR__);
103
- try {
104
- $xml = $response->xml();
105
- chdir($oldCwd);
106
- $this->markTestIncomplete('Did not throw the expected exception! XML resolved as: ' . $xml->asXML());
107
- } catch (\Exception $e) {
108
- chdir($oldCwd);
109
- }
110
- }
111
-
112
- public function testStatusAndReasonAreMutable()
113
- {
114
- $response = new Response(200);
115
- $response->setStatusCode(201);
116
- $this->assertEquals(201, $response->getStatusCode());
117
- $response->setReasonPhrase('Foo');
118
- $this->assertEquals('Foo', $response->getReasonPhrase());
119
- }
120
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/MimetypesTest.php DELETED
@@ -1,31 +0,0 @@
1
- <?php
2
-
3
- namespace GuzzleHttp\Tests;
4
-
5
- use GuzzleHttp\Mimetypes;
6
-
7
- /**
8
- * @covers GuzzleHttp\Mimetypes
9
- */
10
- class MimetypesTest extends \PHPUnit_Framework_TestCase
11
- {
12
- public function testGetsFromExtension()
13
- {
14
- $this->assertEquals('text/x-php', Mimetypes::getInstance()->fromExtension('php'));
15
- }
16
-
17
- public function testGetsFromFilename()
18
- {
19
- $this->assertEquals('text/x-php', Mimetypes::getInstance()->fromFilename(__FILE__));
20
- }
21
-
22
- public function testGetsFromCaseInsensitiveFilename()
23
- {
24
- $this->assertEquals('text/x-php', Mimetypes::getInstance()->fromFilename(strtoupper(__FILE__)));
25
- }
26
-
27
- public function testReturnsNullWhenNoMatchFound()
28
- {
29
- $this->assertNull(Mimetypes::getInstance()->fromExtension('foobar'));
30
- }
31
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/PoolTest.php DELETED
@@ -1,319 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Event\RequestEvents;
6
- use GuzzleHttp\Pool;
7
- use GuzzleHttp\Ring\Client\MockHandler;
8
- use GuzzleHttp\Ring\Future\FutureArray;
9
- use GuzzleHttp\Subscriber\History;
10
- use GuzzleHttp\Event\BeforeEvent;
11
- use GuzzleHttp\Event\CompleteEvent;
12
- use GuzzleHttp\Event\ErrorEvent;
13
- use GuzzleHttp\Event\EndEvent;
14
- use GuzzleHttp\Message\Response;
15
- use GuzzleHttp\Subscriber\Mock;
16
- use React\Promise\Deferred;
17
-
18
- class PoolTest extends \PHPUnit_Framework_TestCase
19
- {
20
- /**
21
- * @expectedException \InvalidArgumentException
22
- */
23
- public function testValidatesIterable()
24
- {
25
- new Pool(new Client(), 'foo');
26
- }
27
-
28
- public function testCanControlPoolSizeAndClient()
29
- {
30
- $c = new Client();
31
- $p = new Pool($c, [], ['pool_size' => 10]);
32
- $this->assertSame($c, $this->readAttribute($p, 'client'));
33
- $this->assertEquals(10, $this->readAttribute($p, 'poolSize'));
34
- }
35
-
36
- /**
37
- * @expectedException \InvalidArgumentException
38
- */
39
- public function testValidatesEachElement()
40
- {
41
- $c = new Client();
42
- $requests = ['foo'];
43
- $p = new Pool($c, new \ArrayIterator($requests));
44
- $p->wait();
45
- }
46
-
47
- public function testSendsAndRealizesFuture()
48
- {
49
- $c = $this->getClient();
50
- $p = new Pool($c, [$c->createRequest('GET', 'http://foo.com')]);
51
- $this->assertTrue($p->wait());
52
- $this->assertFalse($p->wait());
53
- $this->assertTrue($this->readAttribute($p, 'isRealized'));
54
- $this->assertFalse($p->cancel());
55
- }
56
-
57
- public function testSendsManyRequestsInCappedPool()
58
- {
59
- $c = $this->getClient();
60
- $p = new Pool($c, [$c->createRequest('GET', 'http://foo.com')]);
61
- $this->assertTrue($p->wait());
62
- $this->assertFalse($p->wait());
63
- }
64
-
65
- public function testSendsRequestsThatHaveNotBeenRealized()
66
- {
67
- $c = $this->getClient();
68
- $p = new Pool($c, [$c->createRequest('GET', 'http://foo.com')]);
69
- $this->assertTrue($p->wait());
70
- $this->assertFalse($p->wait());
71
- $this->assertFalse($p->cancel());
72
- }
73
-
74
- public function testCancelsInFlightRequests()
75
- {
76
- $c = $this->getClient();
77
- $h = new History();
78
- $c->getEmitter()->attach($h);
79
- $p = new Pool($c, [
80
- $c->createRequest('GET', 'http://foo.com'),
81
- $c->createRequest('GET', 'http://foo.com', [
82
- 'events' => [
83
- 'before' => [
84
- 'fn' => function () use (&$p) {
85
- $this->assertTrue($p->cancel());
86
- },
87
- 'priority' => RequestEvents::EARLY
88
- ]
89
- ]
90
- ])
91
- ]);
92
- ob_start();
93
- $p->wait();
94
- $contents = ob_get_clean();
95
- $this->assertEquals(1, count($h));
96
- $this->assertEquals('Cancelling', $contents);
97
- }
98
-
99
- private function getClient()
100
- {
101
- $deferred = new Deferred();
102
- $future = new FutureArray(
103
- $deferred->promise(),
104
- function() use ($deferred) {
105
- $deferred->resolve(['status' => 200, 'headers' => []]);
106
- }, function () {
107
- echo 'Cancelling';
108
- }
109
- );
110
-
111
- return new Client(['handler' => new MockHandler($future)]);
112
- }
113
-
114
- public function testBatchesRequests()
115
- {
116
- $client = new Client(['handler' => function () {
117
- throw new \RuntimeException('No network access');
118
- }]);
119
-
120
- $responses = [
121
- new Response(301, ['Location' => 'http://foo.com/bar']),
122
- new Response(200),
123
- new Response(200),
124
- new Response(404)
125
- ];
126
-
127
- $client->getEmitter()->attach(new Mock($responses));
128
- $requests = [
129
- $client->createRequest('GET', 'http://foo.com/baz'),
130
- $client->createRequest('HEAD', 'http://httpbin.org/get'),
131
- $client->createRequest('PUT', 'http://httpbin.org/put'),
132
- ];
133
-
134
- $a = $b = $c = $d = 0;
135
- $result = Pool::batch($client, $requests, [
136
- 'before' => function (BeforeEvent $e) use (&$a) { $a++; },
137
- 'complete' => function (CompleteEvent $e) use (&$b) { $b++; },
138
- 'error' => function (ErrorEvent $e) use (&$c) { $c++; },
139
- 'end' => function (EndEvent $e) use (&$d) { $d++; }
140
- ]);
141
-
142
- $this->assertEquals(4, $a);
143
- $this->assertEquals(2, $b);
144
- $this->assertEquals(1, $c);
145
- $this->assertEquals(3, $d);
146
- $this->assertCount(3, $result);
147
- $this->assertInstanceOf('GuzzleHttp\BatchResults', $result);
148
-
149
- // The first result is actually the second (redirect) response.
150
- $this->assertSame($responses[1], $result[0]);
151
- // The second result is a 1:1 request:response map
152
- $this->assertSame($responses[2], $result[1]);
153
- // The third entry is the 404 RequestException
154
- $this->assertSame($responses[3], $result[2]->getResponse());
155
- }
156
-
157
- public function testBatchesRequestsWithDynamicPoolSize()
158
- {
159
- $client = new Client(['handler' => function () {
160
- throw new \RuntimeException('No network access');
161
- }]);
162
-
163
- $responses = [
164
- new Response(301, ['Location' => 'http://foo.com/bar']),
165
- new Response(200),
166
- new Response(200),
167
- new Response(404)
168
- ];
169
-
170
- $client->getEmitter()->attach(new Mock($responses));
171
- $requests = [
172
- $client->createRequest('GET', 'http://foo.com/baz'),
173
- $client->createRequest('HEAD', 'http://httpbin.org/get'),
174
- $client->createRequest('PUT', 'http://httpbin.org/put'),
175
- ];
176
-
177
- $a = $b = $c = $d = 0;
178
- $result = Pool::batch($client, $requests, [
179
- 'before' => function (BeforeEvent $e) use (&$a) { $a++; },
180
- 'complete' => function (CompleteEvent $e) use (&$b) { $b++; },
181
- 'error' => function (ErrorEvent $e) use (&$c) { $c++; },
182
- 'end' => function (EndEvent $e) use (&$d) { $d++; },
183
- 'pool_size' => function ($queueSize) {
184
- static $options = [1, 2, 1];
185
- static $queued = 0;
186
-
187
- $this->assertEquals(
188
- $queued,
189
- $queueSize,
190
- 'The number of queued requests should be equal to the sum of pool sizes so far.'
191
- );
192
-
193
- $next = array_shift($options);
194
- $queued += $next;
195
-
196
- return $next;
197
- }
198
- ]);
199
-
200
- $this->assertEquals(4, $a);
201
- $this->assertEquals(2, $b);
202
- $this->assertEquals(1, $c);
203
- $this->assertEquals(3, $d);
204
- $this->assertCount(3, $result);
205
- $this->assertInstanceOf('GuzzleHttp\BatchResults', $result);
206
-
207
- // The first result is actually the second (redirect) response.
208
- $this->assertSame($responses[1], $result[0]);
209
- // The second result is a 1:1 request:response map
210
- $this->assertSame($responses[2], $result[1]);
211
- // The third entry is the 404 RequestException
212
- $this->assertSame($responses[3], $result[2]->getResponse());
213
- }
214
-
215
- /**
216
- * @expectedException \InvalidArgumentException
217
- * @expectedExceptionMessage Each event listener must be a callable or
218
- */
219
- public function testBatchValidatesTheEventFormat()
220
- {
221
- $client = new Client();
222
- $requests = [$client->createRequest('GET', 'http://foo.com/baz')];
223
- Pool::batch($client, $requests, ['complete' => 'foo']);
224
- }
225
-
226
- public function testEmitsProgress()
227
- {
228
- $client = new Client(['handler' => function () {
229
- throw new \RuntimeException('No network access');
230
- }]);
231
-
232
- $responses = [new Response(200), new Response(404)];
233
- $client->getEmitter()->attach(new Mock($responses));
234
- $requests = [
235
- $client->createRequest('GET', 'http://foo.com/baz'),
236
- $client->createRequest('HEAD', 'http://httpbin.org/get')
237
- ];
238
-
239
- $pool = new Pool($client, $requests);
240
- $count = 0;
241
- $thenned = null;
242
- $pool->then(
243
- function ($value) use (&$thenned) {
244
- $thenned = $value;
245
- },
246
- null,
247
- function ($result) use (&$count, $requests) {
248
- $this->assertSame($requests[$count], $result['request']);
249
- if ($count == 0) {
250
- $this->assertNull($result['error']);
251
- $this->assertEquals(200, $result['response']->getStatusCode());
252
- } else {
253
- $this->assertInstanceOf(
254
- 'GuzzleHttp\Exception\ClientException',
255
- $result['error']
256
- );
257
- }
258
- $count++;
259
- }
260
- );
261
-
262
- $pool->wait();
263
- $this->assertEquals(2, $count);
264
- $this->assertEquals(true, $thenned);
265
- }
266
-
267
- public function testDoesNotThrowInErrorEvent()
268
- {
269
- $client = new Client();
270
- $responses = [new Response(404)];
271
- $client->getEmitter()->attach(new Mock($responses));
272
- $requests = [$client->createRequest('GET', 'http://foo.com/baz')];
273
- $result = Pool::batch($client, $requests);
274
- $this->assertCount(1, $result);
275
- $this->assertInstanceOf('GuzzleHttp\Exception\ClientException', $result[0]);
276
- }
277
-
278
- public function testHasSendMethod()
279
- {
280
- $client = new Client();
281
- $responses = [new Response(404)];
282
- $history = new History();
283
- $client->getEmitter()->attach($history);
284
- $client->getEmitter()->attach(new Mock($responses));
285
- $requests = [$client->createRequest('GET', 'http://foo.com/baz')];
286
- Pool::send($client, $requests);
287
- $this->assertCount(1, $history);
288
- }
289
-
290
- public function testDoesNotInfinitelyRecurse()
291
- {
292
- $client = new Client(['handler' => function () {
293
- throw new \RuntimeException('No network access');
294
- }]);
295
-
296
- $last = null;
297
- $client->getEmitter()->on(
298
- 'before',
299
- function (BeforeEvent $e) use (&$last) {
300
- $e->intercept(new Response(200));
301
- if (function_exists('xdebug_get_stack_depth')) {
302
- if ($last) {
303
- $this->assertEquals($last, xdebug_get_stack_depth());
304
- } else {
305
- $last = xdebug_get_stack_depth();
306
- }
307
- }
308
- }
309
- );
310
-
311
- $requests = [];
312
- for ($i = 0; $i < 100; $i++) {
313
- $requests[] = $client->createRequest('GET', 'http://foo.com');
314
- }
315
-
316
- $pool = new Pool($client, $requests);
317
- $pool->wait();
318
- }
319
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Post/MultipartBodyTest.php DELETED
@@ -1,120 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Post;
3
-
4
- use GuzzleHttp\Post\MultipartBody;
5
- use GuzzleHttp\Post\PostFile;
6
-
7
- /**
8
- * @covers GuzzleHttp\Post\MultipartBody
9
- */
10
- class MultipartBodyTest extends \PHPUnit_Framework_TestCase
11
- {
12
- protected function getTestBody()
13
- {
14
- return new MultipartBody(['foo' => 'bar'], [
15
- new PostFile('foo', 'abc', 'foo.txt')
16
- ], 'abcdef');
17
- }
18
-
19
- public function testConstructorAddsFieldsAndFiles()
20
- {
21
- $b = $this->getTestBody();
22
- $this->assertEquals('abcdef', $b->getBoundary());
23
- $c = (string) $b;
24
- $this->assertContains("--abcdef\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n", $c);
25
- $this->assertContains("--abcdef\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"foo.txt\"\r\n"
26
- . "Content-Type: text/plain\r\n\r\nabc\r\n--abcdef--", $c);
27
- }
28
-
29
- public function testDoesNotModifyFieldFormat()
30
- {
31
- $m = new MultipartBody(['foo+baz' => 'bar+bam %20 boo'], [
32
- new PostFile('foo+bar', 'abc %20 123', 'foo.txt')
33
- ], 'abcdef');
34
- $this->assertContains('name="foo+baz"', (string) $m);
35
- $this->assertContains('name="foo+bar"', (string) $m);
36
- $this->assertContains('bar+bam %20 boo', (string) $m);
37
- $this->assertContains('abc %20 123', (string) $m);
38
- }
39
-
40
- /**
41
- * @expectedException \InvalidArgumentException
42
- */
43
- public function testConstructorValidatesFiles()
44
- {
45
- new MultipartBody([], ['bar']);
46
- }
47
-
48
- public function testConstructorCanCreateBoundary()
49
- {
50
- $b = new MultipartBody();
51
- $this->assertNotNull($b->getBoundary());
52
- }
53
-
54
- public function testWrapsStreamMethods()
55
- {
56
- $b = $this->getTestBody();
57
- $this->assertFalse($b->write('foo'));
58
- $this->assertFalse($b->isWritable());
59
- $this->assertTrue($b->isReadable());
60
- $this->assertTrue($b->isSeekable());
61
- $this->assertEquals(0, $b->tell());
62
- }
63
-
64
- public function testCanDetachFieldsAndFiles()
65
- {
66
- $b = $this->getTestBody();
67
- $b->detach();
68
- $b->close();
69
- $this->assertEquals('', (string) $b);
70
- }
71
-
72
- public function testIsSeekableReturnsTrueIfAllAreSeekable()
73
- {
74
- $s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
75
- ->setMethods(['isSeekable', 'isReadable'])
76
- ->getMockForAbstractClass();
77
- $s->expects($this->once())
78
- ->method('isSeekable')
79
- ->will($this->returnValue(false));
80
- $s->expects($this->once())
81
- ->method('isReadable')
82
- ->will($this->returnValue(true));
83
- $p = new PostFile('foo', $s, 'foo.php');
84
- $b = new MultipartBody([], [$p]);
85
- $this->assertFalse($b->isSeekable());
86
- $this->assertFalse($b->seek(10));
87
- }
88
-
89
- public function testReadsFromBuffer()
90
- {
91
- $b = $this->getTestBody();
92
- $c = $b->read(1);
93
- $c .= $b->read(1);
94
- $c .= $b->read(1);
95
- $c .= $b->read(1);
96
- $c .= $b->read(1);
97
- $this->assertEquals('--abc', $c);
98
- }
99
-
100
- public function testCalculatesSize()
101
- {
102
- $b = $this->getTestBody();
103
- $this->assertEquals(strlen($b), $b->getSize());
104
- }
105
-
106
- public function testCalculatesSizeAndReturnsNullForUnknown()
107
- {
108
- $s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
109
- ->setMethods(['getSize', 'isReadable'])
110
- ->getMockForAbstractClass();
111
- $s->expects($this->once())
112
- ->method('getSize')
113
- ->will($this->returnValue(null));
114
- $s->expects($this->once())
115
- ->method('isReadable')
116
- ->will($this->returnValue(true));
117
- $b = new MultipartBody([], [new PostFile('foo', $s, 'foo.php')]);
118
- $this->assertNull($b->getSize());
119
- }
120
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Post/PostBodyTest.php DELETED
@@ -1,255 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Post;
3
-
4
- use GuzzleHttp\Message\Request;
5
- use GuzzleHttp\Post\PostBody;
6
- use GuzzleHttp\Post\PostFile;
7
- use GuzzleHttp\Query;
8
-
9
- /**
10
- * @covers GuzzleHttp\Post\PostBody
11
- */
12
- class PostBodyTest extends \PHPUnit_Framework_TestCase
13
- {
14
- public function testWrapsBasicStreamFunctionality()
15
- {
16
- $b = new PostBody();
17
- $this->assertTrue($b->isSeekable());
18
- $this->assertTrue($b->isReadable());
19
- $this->assertFalse($b->isWritable());
20
- $this->assertFalse($b->write('foo'));
21
- }
22
-
23
- public function testApplyingWithNothingDoesNothing()
24
- {
25
- $b = new PostBody();
26
- $m = new Request('POST', '/');
27
- $b->applyRequestHeaders($m);
28
- $this->assertFalse($m->hasHeader('Content-Length'));
29
- $this->assertFalse($m->hasHeader('Content-Type'));
30
- }
31
-
32
- public function testCanForceMultipartUploadsWhenApplying()
33
- {
34
- $b = new PostBody();
35
- $b->forceMultipartUpload(true);
36
- $m = new Request('POST', '/');
37
- $b->applyRequestHeaders($m);
38
- $this->assertContains(
39
- 'multipart/form-data',
40
- $m->getHeader('Content-Type')
41
- );
42
- }
43
-
44
- public function testApplyingWithFilesAddsMultipartUpload()
45
- {
46
- $b = new PostBody();
47
- $p = new PostFile('foo', fopen(__FILE__, 'r'));
48
- $b->addFile($p);
49
- $this->assertEquals([$p], $b->getFiles());
50
- $this->assertNull($b->getFile('missing'));
51
- $this->assertSame($p, $b->getFile('foo'));
52
- $m = new Request('POST', '/');
53
- $b->applyRequestHeaders($m);
54
- $this->assertContains(
55
- 'multipart/form-data',
56
- $m->getHeader('Content-Type')
57
- );
58
- $this->assertTrue($m->hasHeader('Content-Length'));
59
- }
60
-
61
- public function testApplyingWithFieldsAddsMultipartUpload()
62
- {
63
- $b = new PostBody();
64
- $b->setField('foo', 'bar');
65
- $this->assertEquals(['foo' => 'bar'], $b->getFields());
66
- $m = new Request('POST', '/');
67
- $b->applyRequestHeaders($m);
68
- $this->assertContains(
69
- 'application/x-www-form',
70
- $m->getHeader('Content-Type')
71
- );
72
- $this->assertTrue($m->hasHeader('Content-Length'));
73
- }
74
-
75
- public function testMultipartWithNestedFields()
76
- {
77
- $b = new PostBody();
78
- $b->setField('foo', ['bar' => 'baz']);
79
- $b->forceMultipartUpload(true);
80
- $this->assertEquals(['foo' => ['bar' => 'baz']], $b->getFields());
81
- $m = new Request('POST', '/');
82
- $b->applyRequestHeaders($m);
83
- $this->assertContains(
84
- 'multipart/form-data',
85
- $m->getHeader('Content-Type')
86
- );
87
- $this->assertTrue($m->hasHeader('Content-Length'));
88
- $contents = $b->getContents();
89
- $this->assertContains('name="foo[bar]"', $contents);
90
- $this->assertNotContains('name="foo"', $contents);
91
- }
92
-
93
- public function testCountProvidesFieldsAndFiles()
94
- {
95
- $b = new PostBody();
96
- $b->setField('foo', 'bar');
97
- $b->addFile(new PostFile('foo', fopen(__FILE__, 'r')));
98
- $this->assertEquals(2, count($b));
99
- $b->clearFiles();
100
- $b->removeField('foo');
101
- $this->assertEquals(0, count($b));
102
- $this->assertEquals([], $b->getFiles());
103
- $this->assertEquals([], $b->getFields());
104
- }
105
-
106
- public function testHasFields()
107
- {
108
- $b = new PostBody();
109
- $b->setField('foo', 'bar');
110
- $b->setField('baz', '123');
111
- $this->assertEquals('bar', $b->getField('foo'));
112
- $this->assertEquals('123', $b->getField('baz'));
113
- $this->assertNull($b->getField('ahh'));
114
- $this->assertTrue($b->hasField('foo'));
115
- $this->assertFalse($b->hasField('test'));
116
- $b->replaceFields(['abc' => '123']);
117
- $this->assertFalse($b->hasField('foo'));
118
- $this->assertTrue($b->hasField('abc'));
119
- }
120
-
121
- public function testConvertsFieldsToQueryStyleBody()
122
- {
123
- $b = new PostBody();
124
- $b->setField('foo', 'bar');
125
- $b->setField('baz', '123');
126
- $this->assertEquals('foo=bar&baz=123', $b);
127
- $this->assertEquals(15, $b->getSize());
128
- $b->seek(0);
129
- $this->assertEquals('foo=bar&baz=123', $b->getContents());
130
- $b->seek(0);
131
- $this->assertEquals('foo=bar&baz=123', $b->read(1000));
132
- $this->assertEquals(15, $b->tell());
133
- }
134
-
135
- public function testCanSpecifyQueryAggregator()
136
- {
137
- $b = new PostBody();
138
- $b->setField('foo', ['baz', 'bar']);
139
- $this->assertEquals('foo%5B0%5D=baz&foo%5B1%5D=bar', (string) $b);
140
- $b = new PostBody();
141
- $b->setField('foo', ['baz', 'bar']);
142
- $agg = Query::duplicateAggregator();
143
- $b->setAggregator($agg);
144
- $this->assertEquals('foo=baz&foo=bar', (string) $b);
145
- }
146
-
147
- public function testDetachesAndCloses()
148
- {
149
- $b = new PostBody();
150
- $b->setField('foo', 'bar');
151
- $b->detach();
152
- $b->close();
153
- $this->assertEquals('', $b->read(10));
154
- }
155
-
156
- public function testDetachesWhenBodyIsPresent()
157
- {
158
- $b = new PostBody();
159
- $b->setField('foo', 'bar');
160
- $b->getContents();
161
- $b->detach();
162
- }
163
-
164
- public function testFlushAndMetadataPlaceholders()
165
- {
166
- $b = new PostBody();
167
- $this->assertEquals([], $b->getMetadata());
168
- $this->assertNull($b->getMetadata('foo'));
169
- }
170
-
171
- public function testCreatesMultipartUploadWithMultiFields()
172
- {
173
- $b = new PostBody();
174
- $b->setField('testing', ['baz', 'bar']);
175
- $b->setField('other', 'hi');
176
- $b->setField('third', 'there');
177
- $b->addFile(new PostFile('foo', fopen(__FILE__, 'r')));
178
- $s = (string) $b;
179
- $this->assertContains(file_get_contents(__FILE__), $s);
180
- $this->assertContains('testing=bar', $s);
181
- $this->assertContains(
182
- 'Content-Disposition: form-data; name="third"',
183
- $s
184
- );
185
- $this->assertContains(
186
- 'Content-Disposition: form-data; name="other"',
187
- $s
188
- );
189
- }
190
-
191
- public function testMultipartWithBase64Fields()
192
- {
193
- $b = new PostBody();
194
- $b->setField('foo64', '/xA2JhWEqPcgyLRDdir9WSRi/khpb2Lh3ooqv+5VYoc=');
195
- $b->forceMultipartUpload(true);
196
- $this->assertEquals(
197
- ['foo64' => '/xA2JhWEqPcgyLRDdir9WSRi/khpb2Lh3ooqv+5VYoc='],
198
- $b->getFields()
199
- );
200
- $m = new Request('POST', '/');
201
- $b->applyRequestHeaders($m);
202
- $this->assertContains(
203
- 'multipart/form-data',
204
- $m->getHeader('Content-Type')
205
- );
206
- $this->assertTrue($m->hasHeader('Content-Length'));
207
- $contents = $b->getContents();
208
- $this->assertContains('name="foo64"', $contents);
209
- $this->assertContains(
210
- '/xA2JhWEqPcgyLRDdir9WSRi/khpb2Lh3ooqv+5VYoc=',
211
- $contents
212
- );
213
- }
214
-
215
- public function testMultipartWithAmpersandInValue()
216
- {
217
- $b = new PostBody();
218
- $b->setField('a', 'b&c=d');
219
- $b->forceMultipartUpload(true);
220
- $this->assertEquals(['a' => 'b&c=d'], $b->getFields());
221
- $m = new Request('POST', '/');
222
- $b->applyRequestHeaders($m);
223
- $this->assertContains(
224
- 'multipart/form-data',
225
- $m->getHeader('Content-Type')
226
- );
227
- $this->assertTrue($m->hasHeader('Content-Length'));
228
- $contents = $b->getContents();
229
- $this->assertContains('name="a"', $contents);
230
- $this->assertContains('b&c=d', $contents);
231
- }
232
-
233
- /**
234
- * @expectedException \GuzzleHttp\Stream\Exception\CannotAttachException
235
- */
236
- public function testCannotAttach()
237
- {
238
- $b = new PostBody();
239
- $b->attach('foo');
240
- }
241
-
242
- public function testDoesNotOverwriteExistingHeaderForUrlencoded()
243
- {
244
- $m = new Request('POST', 'http://foo.com', [
245
- 'content-type' => 'application/x-www-form-urlencoded; charset=utf-8'
246
- ]);
247
- $b = new PostBody();
248
- $b->setField('foo', 'bar');
249
- $b->applyRequestHeaders($m);
250
- $this->assertEquals(
251
- 'application/x-www-form-urlencoded; charset=utf-8',
252
- $m->getHeader('Content-Type')
253
- );
254
- }
255
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Post/PostFileTest.php DELETED
@@ -1,61 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Post;
3
-
4
- use GuzzleHttp\Post\MultipartBody;
5
- use GuzzleHttp\Post\PostFile;
6
- use GuzzleHttp\Stream\Stream;
7
-
8
- /**
9
- * @covers GuzzleHttp\Post\PostFile
10
- */
11
- class PostFileTest extends \PHPUnit_Framework_TestCase
12
- {
13
- public function testCreatesFromString()
14
- {
15
- $p = new PostFile('foo', 'hi', '/path/to/test.php');
16
- $this->assertInstanceOf('GuzzleHttp\Post\PostFileInterface', $p);
17
- $this->assertEquals('hi', $p->getContent());
18
- $this->assertEquals('foo', $p->getName());
19
- $this->assertEquals('/path/to/test.php', $p->getFilename());
20
- $this->assertEquals(
21
- 'form-data; name="foo"; filename="test.php"',
22
- $p->getHeaders()['Content-Disposition']
23
- );
24
- }
25
-
26
- public function testGetsFilenameFromMetadata()
27
- {
28
- $p = new PostFile('foo', fopen(__FILE__, 'r'));
29
- $this->assertEquals(__FILE__, $p->getFilename());
30
- }
31
-
32
- public function testDefaultsToNameWhenNoFilenameExists()
33
- {
34
- $p = new PostFile('foo', 'bar');
35
- $this->assertEquals('foo', $p->getFilename());
36
- }
37
-
38
- public function testCreatesFromMultipartFormData()
39
- {
40
- $mp = new MultipartBody([], [], 'baz');
41
- $p = new PostFile('foo', $mp);
42
- $this->assertEquals(
43
- 'form-data; name="foo"',
44
- $p->getHeaders()['Content-Disposition']
45
- );
46
- $this->assertEquals(
47
- 'multipart/form-data; boundary=baz',
48
- $p->getHeaders()['Content-Type']
49
- );
50
- }
51
-
52
- public function testCanAddHeaders()
53
- {
54
- $p = new PostFile('foo', Stream::factory('hi'), 'test.php', [
55
- 'X-Foo' => '123',
56
- 'Content-Disposition' => 'bar'
57
- ]);
58
- $this->assertEquals('bar', $p->getHeaders()['Content-Disposition']);
59
- $this->assertEquals('123', $p->getHeaders()['X-Foo']);
60
- }
61
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/QueryParserTest.php DELETED
@@ -1,80 +0,0 @@
1
- <?php
2
-
3
- namespace GuzzleHttp\Tests;
4
-
5
- use GuzzleHttp\Query;
6
- use GuzzleHttp\QueryParser;
7
-
8
- class QueryParserTest extends \PHPUnit_Framework_TestCase
9
- {
10
- public function parseQueryProvider()
11
- {
12
- return [
13
- // Does not need to parse when the string is empty
14
- ['', []],
15
- // Can parse mult-values items
16
- ['q=a&q=b', ['q' => ['a', 'b']]],
17
- // Can parse multi-valued items that use numeric indices
18
- ['q[0]=a&q[1]=b', ['q' => ['a', 'b']]],
19
- // Can parse duplicates and does not include numeric indices
20
- ['q[]=a&q[]=b', ['q' => ['a', 'b']]],
21
- // Ensures that the value of "q" is an array even though one value
22
- ['q[]=a', ['q' => ['a']]],
23
- // Does not modify "." to "_" like PHP's parse_str()
24
- ['q.a=a&q.b=b', ['q.a' => 'a', 'q.b' => 'b']],
25
- // Can decode %20 to " "
26
- ['q%20a=a%20b', ['q a' => 'a b']],
27
- // Can parse funky strings with no values by assigning each to null
28
- ['q&a', ['q' => null, 'a' => null]],
29
- // Does not strip trailing equal signs
30
- ['data=abc=', ['data' => 'abc=']],
31
- // Can store duplicates without affecting other values
32
- ['foo=a&foo=b&?µ=c', ['foo' => ['a', 'b'], '?µ' => 'c']],
33
- // Sets value to null when no "=" is present
34
- ['foo', ['foo' => null]],
35
- // Preserves "0" keys.
36
- ['0', ['0' => null]],
37
- // Sets the value to an empty string when "=" is present
38
- ['0=', ['0' => '']],
39
- // Preserves falsey keys
40
- ['var=0', ['var' => '0']],
41
- // Can deeply nest and store duplicate PHP values
42
- ['a[b][c]=1&a[b][c]=2', [
43
- 'a' => ['b' => ['c' => ['1', '2']]]
44
- ]],
45
- // Can parse PHP style arrays
46
- ['a[b]=c&a[d]=e', ['a' => ['b' => 'c', 'd' => 'e']]],
47
- // Ensure it doesn't leave things behind with repeated values
48
- // Can parse mult-values items
49
- ['q=a&q=b&q=c', ['q' => ['a', 'b', 'c']]],
50
- ];
51
- }
52
-
53
- /**
54
- * @dataProvider parseQueryProvider
55
- */
56
- public function testParsesQueries($input, $output)
57
- {
58
- $query = Query::fromString($input);
59
- $this->assertEquals($output, $query->toArray());
60
- // Normalize the input and output
61
- $query->setEncodingType(false);
62
- $this->assertEquals(rawurldecode($input), (string) $query);
63
- }
64
-
65
- public function testConvertsPlusSymbolsToSpacesByDefault()
66
- {
67
- $query = Query::fromString('var=foo+bar', true);
68
- $this->assertEquals('foo bar', $query->get('var'));
69
- }
70
-
71
- public function testCanControlDecodingType()
72
- {
73
- $qp = new QueryParser();
74
- $q = new Query();
75
- $qp->parseInto($q, 'var=foo+bar', Query::RFC3986);
76
- $this->assertEquals('foo+bar', $q->get('var'));
77
- $qp->parseInto($q, 'var=foo+bar', Query::RFC1738);
78
- $this->assertEquals('foo bar', $q->get('var'));
79
- }
80
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/QueryTest.php DELETED
@@ -1,171 +0,0 @@
1
- <?php
2
-
3
- namespace GuzzleHttp\Tests;
4
-
5
- use GuzzleHttp\Query;
6
-
7
- class QueryTest extends \PHPUnit_Framework_TestCase
8
- {
9
- public function testCanCastToString()
10
- {
11
- $q = new Query(['foo' => 'baz', 'bar' => 'bam boozle']);
12
- $this->assertEquals('foo=baz&bar=bam%20boozle', (string) $q);
13
- }
14
-
15
- public function testCanDisableUrlEncoding()
16
- {
17
- $q = new Query(['bar' => 'bam boozle']);
18
- $q->setEncodingType(false);
19
- $this->assertEquals('bar=bam boozle', (string) $q);
20
- }
21
-
22
- public function testCanSpecifyRfc1783UrlEncodingType()
23
- {
24
- $q = new Query(['bar abc' => 'bam boozle']);
25
- $q->setEncodingType(Query::RFC1738);
26
- $this->assertEquals('bar+abc=bam+boozle', (string) $q);
27
- }
28
-
29
- public function testCanSpecifyRfc3986UrlEncodingType()
30
- {
31
- $q = new Query(['bar abc' => 'bam boozle', 'ሴ' => 'hi']);
32
- $q->setEncodingType(Query::RFC3986);
33
- $this->assertEquals('bar%20abc=bam%20boozle&%E1%88%B4=hi', (string) $q);
34
- }
35
-
36
- /**
37
- * @expectedException \InvalidArgumentException
38
- */
39
- public function testValidatesEncodingType()
40
- {
41
- (new Query(['bar' => 'bam boozle']))->setEncodingType('foo');
42
- }
43
-
44
- public function testAggregatesMultipleValues()
45
- {
46
- $q = new Query(['foo' => ['bar', 'baz']]);
47
- $this->assertEquals('foo%5B0%5D=bar&foo%5B1%5D=baz', (string) $q);
48
- }
49
-
50
- public function testCanSetAggregator()
51
- {
52
- $q = new Query(['foo' => ['bar', 'baz']]);
53
- $q->setAggregator(function (array $data) {
54
- return ['foo' => ['barANDbaz']];
55
- });
56
- $this->assertEquals('foo=barANDbaz', (string) $q);
57
- }
58
-
59
- public function testAllowsMultipleValuesPerKey()
60
- {
61
- $q = new Query();
62
- $q->add('facet', 'size');
63
- $q->add('facet', 'width');
64
- $q->add('facet.field', 'foo');
65
- // Use the duplicate aggregator
66
- $q->setAggregator($q::duplicateAggregator());
67
- $this->assertEquals('facet=size&facet=width&facet.field=foo', (string) $q);
68
- }
69
-
70
- public function testAllowsZeroValues()
71
- {
72
- $query = new Query(array(
73
- 'foo' => 0,
74
- 'baz' => '0',
75
- 'bar' => null,
76
- 'boo' => false
77
- ));
78
- $this->assertEquals('foo=0&baz=0&bar&boo=', (string) $query);
79
- }
80
-
81
- private $encodeData = [
82
- 't' => [
83
- 'v1' => ['a', '1'],
84
- 'v2' => 'b',
85
- 'v3' => ['v4' => 'c', 'v5' => 'd']
86
- ]
87
- ];
88
-
89
- public function testEncodesDuplicateAggregator()
90
- {
91
- $agg = Query::duplicateAggregator();
92
- $result = $agg($this->encodeData);
93
- $this->assertEquals(array(
94
- 't[v1]' => ['a', '1'],
95
- 't[v2]' => ['b'],
96
- 't[v3][v4]' => ['c'],
97
- 't[v3][v5]' => ['d'],
98
- ), $result);
99
- }
100
-
101
- public function testDuplicateEncodesNoNumericIndices()
102
- {
103
- $agg = Query::duplicateAggregator();
104
- $result = $agg($this->encodeData);
105
- $this->assertEquals(array(
106
- 't[v1]' => ['a', '1'],
107
- 't[v2]' => ['b'],
108
- 't[v3][v4]' => ['c'],
109
- 't[v3][v5]' => ['d'],
110
- ), $result);
111
- }
112
-
113
- public function testEncodesPhpAggregator()
114
- {
115
- $agg = Query::phpAggregator();
116
- $result = $agg($this->encodeData);
117
- $this->assertEquals(array(
118
- 't[v1][0]' => ['a'],
119
- 't[v1][1]' => ['1'],
120
- 't[v2]' => ['b'],
121
- 't[v3][v4]' => ['c'],
122
- 't[v3][v5]' => ['d'],
123
- ), $result);
124
- }
125
-
126
- public function testPhpEncodesNoNumericIndices()
127
- {
128
- $agg = Query::phpAggregator(false);
129
- $result = $agg($this->encodeData);
130
- $this->assertEquals(array(
131
- 't[v1][]' => ['a', '1'],
132
- 't[v2]' => ['b'],
133
- 't[v3][v4]' => ['c'],
134
- 't[v3][v5]' => ['d'],
135
- ), $result);
136
- }
137
-
138
- public function testCanDisableUrlEncodingDecoding()
139
- {
140
- $q = Query::fromString('foo=bar+baz boo%20', false);
141
- $this->assertEquals('bar+baz boo%20', $q['foo']);
142
- $this->assertEquals('foo=bar+baz boo%20', (string) $q);
143
- }
144
-
145
- public function testCanChangeUrlEncodingDecodingToRfc1738()
146
- {
147
- $q = Query::fromString('foo=bar+baz', Query::RFC1738);
148
- $this->assertEquals('bar baz', $q['foo']);
149
- $this->assertEquals('foo=bar+baz', (string) $q);
150
- }
151
-
152
- public function testCanChangeUrlEncodingDecodingToRfc3986()
153
- {
154
- $q = Query::fromString('foo=bar%20baz', Query::RFC3986);
155
- $this->assertEquals('bar baz', $q['foo']);
156
- $this->assertEquals('foo=bar%20baz', (string) $q);
157
- }
158
-
159
- public function testQueryStringsAllowSlashButDoesNotDecodeWhenDisable()
160
- {
161
- $q = Query::fromString('foo=bar%2Fbaz&bam=boo%20boo', Query::RFC3986);
162
- $q->setEncodingType(false);
163
- $this->assertEquals('foo=bar/baz&bam=boo boo', (string) $q);
164
- }
165
-
166
- public function testQueryStringsAllowDecodingEncodingCompletelyDisabled()
167
- {
168
- $q = Query::fromString('foo=bar%2Fbaz&bam=boo boo!', false);
169
- $this->assertEquals('foo=bar%2Fbaz&bam=boo boo!', (string) $q);
170
- }
171
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/RequestFsmTest.php DELETED
@@ -1,187 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests;
3
-
4
- use GuzzleHttp\Exception\RequestException;
5
- use GuzzleHttp\Message\MessageFactory;
6
- use GuzzleHttp\Message\Response;
7
- use GuzzleHttp\RequestFsm;
8
- use GuzzleHttp\Ring\Future\CompletedFutureArray;
9
- use GuzzleHttp\Subscriber\Mock;
10
- use GuzzleHttp\Transaction;
11
- use GuzzleHttp\Client;
12
- use GuzzleHttp\Message\Request;
13
- use GuzzleHttp\Event\BeforeEvent;
14
- use GuzzleHttp\Event\CompleteEvent;
15
- use GuzzleHttp\Event\ErrorEvent;
16
- use GuzzleHttp\Event\EndEvent;
17
- use GuzzleHttp\Message\FutureResponse;
18
- use GuzzleHttp\Message\RequestInterface;
19
- use GuzzleHttp\Event\RequestEvents;
20
- use React\Promise\Deferred;
21
-
22
- class RequestFsmTest extends \PHPUnit_Framework_TestCase
23
- {
24
- private $mf;
25
-
26
- public function setup()
27
- {
28
- $this->mf = new MessageFactory();
29
- }
30
-
31
- public function testEmitsBeforeEventInTransition()
32
- {
33
- $fsm = new RequestFsm(function () {
34
- return new CompletedFutureArray(['status' => 200]);
35
- }, $this->mf);
36
- $t = new Transaction(new Client(), new Request('GET', 'http://foo.com'));
37
- $c = false;
38
- $t->request->getEmitter()->on('before', function (BeforeEvent $e) use (&$c) {
39
- $c = true;
40
- });
41
- $fsm($t);
42
- $this->assertTrue($c);
43
- }
44
-
45
- public function testEmitsCompleteEventInTransition()
46
- {
47
- $fsm = new RequestFsm(function () {
48
- return new CompletedFutureArray(['status' => 200]);
49
- }, $this->mf);
50
- $t = new Transaction(new Client(), new Request('GET', 'http://foo.com'));
51
- $t->response = new Response(200);
52
- $t->state = 'complete';
53
- $c = false;
54
- $t->request->getEmitter()->on('complete', function (CompleteEvent $e) use (&$c) {
55
- $c = true;
56
- });
57
- $fsm($t);
58
- $this->assertTrue($c);
59
- }
60
-
61
- public function testDoesNotEmitCompleteForFuture()
62
- {
63
- $fsm = new RequestFsm(function () {
64
- return new CompletedFutureArray(['status' => 200]);
65
- }, $this->mf);
66
- $t = new Transaction(new Client(), new Request('GET', 'http://foo.com'));
67
- $deferred = new Deferred();
68
- $t->response = new FutureResponse($deferred->promise());
69
- $t->state = 'complete';
70
- $c = false;
71
- $t->request->getEmitter()->on('complete', function (CompleteEvent $e) use (&$c) {
72
- $c = true;
73
- });
74
- $fsm($t);
75
- $this->assertFalse($c);
76
- }
77
-
78
- public function testTransitionsThroughSuccessfulTransfer()
79
- {
80
- $client = new Client();
81
- $client->getEmitter()->attach(new Mock([new Response(200)]));
82
- $request = $client->createRequest('GET', 'http://ewfewwef.com');
83
- $this->addListeners($request, $calls);
84
- $client->send($request);
85
- $this->assertEquals(['before', 'complete', 'end'], $calls);
86
- }
87
-
88
- public function testTransitionsThroughErrorsInBefore()
89
- {
90
- $fsm = new RequestFsm(function () {
91
- return new CompletedFutureArray(['status' => 200]);
92
- }, $this->mf);
93
- $client = new Client();
94
- $request = $client->createRequest('GET', 'http://ewfewwef.com');
95
- $t = new Transaction($client, $request);
96
- $calls = [];
97
- $this->addListeners($t->request, $calls);
98
- $t->request->getEmitter()->on('before', function (BeforeEvent $e) {
99
- throw new \Exception('foo');
100
- });
101
- try {
102
- $fsm($t);
103
- $this->fail('did not throw');
104
- } catch (RequestException $e) {
105
- $this->assertContains('foo', $t->exception->getMessage());
106
- $this->assertEquals(['before', 'error', 'end'], $calls);
107
- }
108
- }
109
-
110
- public function testTransitionsThroughErrorsInComplete()
111
- {
112
- $client = new Client();
113
- $client->getEmitter()->attach(new Mock([new Response(200)]));
114
- $request = $client->createRequest('GET', 'http://ewfewwef.com');
115
- $this->addListeners($request, $calls);
116
- $request->getEmitter()->once('complete', function (CompleteEvent $e) {
117
- throw new \Exception('foo');
118
- });
119
- try {
120
- $client->send($request);
121
- $this->fail('did not throw');
122
- } catch (RequestException $e) {
123
- $this->assertContains('foo', $e->getMessage());
124
- $this->assertEquals(['before', 'complete', 'error', 'end'], $calls);
125
- }
126
- }
127
-
128
- public function testTransitionsThroughErrorInterception()
129
- {
130
- $fsm = new RequestFsm(function () {
131
- return new CompletedFutureArray(['status' => 404]);
132
- }, $this->mf);
133
- $client = new Client();
134
- $request = $client->createRequest('GET', 'http://ewfewwef.com');
135
- $t = new Transaction($client, $request);
136
- $calls = [];
137
- $this->addListeners($t->request, $calls);
138
- $t->request->getEmitter()->on('error', function (ErrorEvent $e) {
139
- $e->intercept(new Response(200));
140
- });
141
- $fsm($t);
142
- $this->assertEquals(200, $t->response->getStatusCode());
143
- $this->assertNull($t->exception);
144
- $this->assertEquals(['before', 'complete', 'error', 'complete', 'end'], $calls);
145
- }
146
-
147
- private function addListeners(RequestInterface $request, &$calls)
148
- {
149
- $request->getEmitter()->on('before', function (BeforeEvent $e) use (&$calls) {
150
- $calls[] = 'before';
151
- }, RequestEvents::EARLY);
152
- $request->getEmitter()->on('complete', function (CompleteEvent $e) use (&$calls) {
153
- $calls[] = 'complete';
154
- }, RequestEvents::EARLY);
155
- $request->getEmitter()->on('error', function (ErrorEvent $e) use (&$calls) {
156
- $calls[] = 'error';
157
- }, RequestEvents::EARLY);
158
- $request->getEmitter()->on('end', function (EndEvent $e) use (&$calls) {
159
- $calls[] = 'end';
160
- }, RequestEvents::EARLY);
161
- }
162
-
163
- /**
164
- * @expectedException \GuzzleHttp\Exception\RequestException
165
- * @expectedExceptionMessage Too many state transitions
166
- */
167
- public function testDetectsInfiniteLoops()
168
- {
169
- $client = new Client([
170
- 'fsm' => $fsm = new RequestFsm(
171
- function () {
172
- return new CompletedFutureArray(['status' => 200]);
173
- },
174
- new MessageFactory(),
175
- 3
176
- )
177
- ]);
178
- $request = $client->createRequest('GET', 'http://foo.com:123');
179
- $request->getEmitter()->on('before', function () {
180
- throw new \Exception('foo');
181
- });
182
- $request->getEmitter()->on('error', function ($e) {
183
- $e->retry();
184
- });
185
- $client->send($request);
186
- }
187
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/RingBridgeTest.php DELETED
@@ -1,195 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Event\ProgressEvent;
6
- use GuzzleHttp\Message\MessageFactory;
7
- use GuzzleHttp\RingBridge;
8
- use GuzzleHttp\Stream\Stream;
9
- use GuzzleHttp\Transaction;
10
- use GuzzleHttp\Message\Request;
11
- use GuzzleHttp\Message\Response;
12
- use GuzzleHttp\Ring\Client\MockHandler;
13
- use GuzzleHttp\Exception\RequestException;
14
- use GuzzleHttp\Event\ErrorEvent;
15
- use GuzzleHttp\RequestFsm;
16
-
17
- class RingBridgeTest extends \PHPUnit_Framework_TestCase
18
- {
19
- public function testCreatesRingRequests()
20
- {
21
- $stream = Stream::factory('test');
22
- $request = new Request('GET', 'http://httpbin.org/get?a=b', [
23
- 'test' => 'hello'
24
- ], $stream);
25
- $request->getConfig()->set('foo', 'bar');
26
- $trans = new Transaction(new Client(), $request);
27
- $factory = new MessageFactory();
28
- $fsm = new RequestFsm(function () {}, new MessageFactory());
29
- $r = RingBridge::prepareRingRequest($trans, $factory, $fsm);
30
- $this->assertEquals('http', $r['scheme']);
31
- $this->assertEquals('1.1', $r['version']);
32
- $this->assertEquals('GET', $r['http_method']);
33
- $this->assertEquals('http://httpbin.org/get?a=b', $r['url']);
34
- $this->assertEquals('/get', $r['uri']);
35
- $this->assertEquals('a=b', $r['query_string']);
36
- $this->assertEquals([
37
- 'Host' => ['httpbin.org'],
38
- 'test' => ['hello']
39
- ], $r['headers']);
40
- $this->assertSame($stream, $r['body']);
41
- $this->assertEquals(['foo' => 'bar'], $r['client']);
42
- $this->assertFalse($r['future']);
43
- }
44
-
45
- public function testCreatesRingRequestsWithNullQueryString()
46
- {
47
- $request = new Request('GET', 'http://httpbin.org');
48
- $trans = new Transaction(new Client(), $request);
49
- $factory = new MessageFactory();
50
- $fsm = new RequestFsm(function () {}, new MessageFactory());
51
- $r = RingBridge::prepareRingRequest($trans, $factory, $fsm);
52
- $this->assertNull($r['query_string']);
53
- $this->assertEquals('/', $r['uri']);
54
- $this->assertEquals(['Host' => ['httpbin.org']], $r['headers']);
55
- $this->assertNull($r['body']);
56
- $this->assertEquals([], $r['client']);
57
- }
58
-
59
- public function testAddsProgress()
60
- {
61
- Server::enqueue([new Response(200)]);
62
- $client = new Client(['base_url' => Server::$url]);
63
- $request = $client->createRequest('GET');
64
- $called = false;
65
- $request->getEmitter()->on(
66
- 'progress',
67
- function (ProgressEvent $e) use (&$called) {
68
- $called = true;
69
- }
70
- );
71
- $this->assertEquals(200, $client->send($request)->getStatusCode());
72
- $this->assertTrue($called);
73
- }
74
-
75
- public function testGetsResponseProtocolVersionAndEffectiveUrlAndReason()
76
- {
77
- $client = new Client([
78
- 'handler' => new MockHandler([
79
- 'status' => 200,
80
- 'reason' => 'test',
81
- 'headers' => [],
82
- 'version' => '1.0',
83
- 'effective_url' => 'http://foo.com'
84
- ])
85
- ]);
86
- $request = $client->createRequest('GET', 'http://foo.com');
87
- $response = $client->send($request);
88
- $this->assertEquals('1.0', $response->getProtocolVersion());
89
- $this->assertEquals('http://foo.com', $response->getEffectiveUrl());
90
- $this->assertEquals('test', $response->getReasonPhrase());
91
- }
92
-
93
- public function testGetsStreamFromResponse()
94
- {
95
- $res = fopen('php://temp', 'r+');
96
- fwrite($res, 'foo');
97
- rewind($res);
98
- $client = new Client([
99
- 'handler' => new MockHandler([
100
- 'status' => 200,
101
- 'headers' => [],
102
- 'body' => $res
103
- ])
104
- ]);
105
- $request = $client->createRequest('GET', 'http://foo.com');
106
- $response = $client->send($request);
107
- $this->assertEquals('foo', (string) $response->getBody());
108
- }
109
-
110
- public function testEmitsErrorEventOnError()
111
- {
112
- $client = new Client(['base_url' => 'http://127.0.0.1:123']);
113
- $request = $client->createRequest('GET');
114
- $called = false;
115
- $request->getEmitter()->on('error', function () use (&$called) {
116
- $called = true;
117
- });
118
- $request->getConfig()['timeout'] = 0.001;
119
- $request->getConfig()['connect_timeout'] = 0.001;
120
- try {
121
- $client->send($request);
122
- $this->fail('did not throw');
123
- } catch (RequestException $e) {
124
- $this->assertSame($request, $e->getRequest());
125
- $this->assertContains('cURL error', $e->getMessage());
126
- $this->assertTrue($called);
127
- }
128
- }
129
-
130
- /**
131
- * @expectedException \InvalidArgumentException
132
- */
133
- public function testValidatesRingRequest()
134
- {
135
- RingBridge::fromRingRequest([]);
136
- }
137
-
138
- public function testCreatesRequestFromRing()
139
- {
140
- $request = RingBridge::fromRingRequest([
141
- 'http_method' => 'GET',
142
- 'uri' => '/',
143
- 'headers' => [
144
- 'foo' => ['bar'],
145
- 'host' => ['foo.com']
146
- ],
147
- 'body' => 'test',
148
- 'version' => '1.0'
149
- ]);
150
- $this->assertEquals('GET', $request->getMethod());
151
- $this->assertEquals('http://foo.com/', $request->getUrl());
152
- $this->assertEquals('1.0', $request->getProtocolVersion());
153
- $this->assertEquals('test', (string) $request->getBody());
154
- $this->assertEquals('bar', $request->getHeader('foo'));
155
- }
156
-
157
- public function testCanInterceptException()
158
- {
159
- $client = new Client(['base_url' => 'http://127.0.0.1:123']);
160
- $request = $client->createRequest('GET');
161
- $called = false;
162
- $request->getEmitter()->on(
163
- 'error',
164
- function (ErrorEvent $e) use (&$called) {
165
- $called = true;
166
- $e->intercept(new Response(200));
167
- }
168
- );
169
- $request->getConfig()['timeout'] = 0.001;
170
- $request->getConfig()['connect_timeout'] = 0.001;
171
- $this->assertEquals(200, $client->send($request)->getStatusCode());
172
- $this->assertTrue($called);
173
- }
174
-
175
- public function testCreatesLongException()
176
- {
177
- $r = new Request('GET', 'http://www.google.com');
178
- $e = RingBridge::getNoRingResponseException($r);
179
- $this->assertInstanceOf('GuzzleHttp\Exception\RequestException', $e);
180
- $this->assertSame($r, $e->getRequest());
181
- }
182
-
183
- public function testEnsuresResponseOrExceptionWhenCompletingResponse()
184
- {
185
- $trans = new Transaction(new Client(), new Request('GET', 'http://f.co'));
186
- $f = new MessageFactory();
187
- $fsm = new RequestFsm(function () {}, new MessageFactory());
188
- try {
189
- RingBridge::completeRingResponse($trans, [], $f, $fsm);
190
- } catch (RequestException $e) {
191
- $this->assertSame($trans->request, $e->getRequest());
192
- $this->assertContains('RingPHP', $e->getMessage());
193
- }
194
- }
195
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Server.php DELETED
@@ -1,107 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Message\MessageFactory;
6
- use GuzzleHttp\Message\Response;
7
- use GuzzleHttp\Message\ResponseInterface;
8
- use GuzzleHttp\RingBridge;
9
- use GuzzleHttp\Tests\Ring\Client\Server as TestServer;
10
-
11
- /**
12
- * Placeholder for the RingPHP-Client server that makes it easier to use.
13
- */
14
- class Server
15
- {
16
- public static $url = 'http://127.0.0.1:8125/';
17
- public static $port = 8125;
18
-
19
- /**
20
- * Queue an array of responses or a single response on the server.
21
- *
22
- * Any currently queued responses will be overwritten. Subsequent requests
23
- * on the server will return queued responses in FIFO order.
24
- *
25
- * @param array $responses Responses to queue.
26
- * @throws \Exception
27
- */
28
- public static function enqueue(array $responses)
29
- {
30
- static $factory;
31
- if (!$factory) {
32
- $factory = new MessageFactory();
33
- }
34
-
35
- $data = [];
36
- foreach ($responses as $response) {
37
- // Create the response object from a string
38
- if (is_string($response)) {
39
- $response = $factory->fromMessage($response);
40
- } elseif (!($response instanceof ResponseInterface)) {
41
- throw new \Exception('Responses must be strings or Responses');
42
- }
43
- $data[] = self::convertResponse($response);
44
- }
45
-
46
- TestServer::enqueue($data);
47
- }
48
-
49
- /**
50
- * Get all of the received requests
51
- *
52
- * @param bool $hydrate Set to TRUE to turn the messages into
53
- * actual {@see RequestInterface} objects. If $hydrate is FALSE,
54
- * requests will be returned as strings.
55
- *
56
- * @return array
57
- * @throws \RuntimeException
58
- */
59
- public static function received($hydrate = false)
60
- {
61
- $response = TestServer::received();
62
-
63
- if ($hydrate) {
64
- $c = new Client();
65
- $factory = new MessageFactory();
66
- $response = array_map(function($message) use ($factory, $c) {
67
- return RingBridge::fromRingRequest($message);
68
- }, $response);
69
- }
70
-
71
- return $response;
72
- }
73
-
74
- public static function flush()
75
- {
76
- TestServer::flush();
77
- }
78
-
79
- public static function stop()
80
- {
81
- TestServer::stop();
82
- }
83
-
84
- public static function wait($maxTries = 5)
85
- {
86
- TestServer::wait($maxTries);
87
- }
88
-
89
- public static function start()
90
- {
91
- TestServer::start();
92
- }
93
-
94
- private static function convertResponse(Response $response)
95
- {
96
- $headers = array_map(function ($h) {
97
- return implode(', ', $h);
98
- }, $response->getHeaders());
99
-
100
- return [
101
- 'status' => $response->getStatusCode(),
102
- 'reason' => $response->getReasonPhrase(),
103
- 'headers' => $headers,
104
- 'body' => base64_encode((string) $response->getBody())
105
- ];
106
- }
107
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Subscriber/CookieTest.php DELETED
@@ -1,74 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Subscriber;
3
-
4
- use GuzzleHttp\Transaction;
5
- use GuzzleHttp\Client;
6
- use GuzzleHttp\Cookie\CookieJar;
7
- use GuzzleHttp\Event\CompleteEvent;
8
- use GuzzleHttp\Message\Request;
9
- use GuzzleHttp\Message\Response;
10
- use GuzzleHttp\Subscriber\Cookie;
11
- use GuzzleHttp\Subscriber\History;
12
- use GuzzleHttp\Subscriber\Mock;
13
-
14
- /**
15
- * @covers GuzzleHttp\Subscriber\Cookie
16
- */
17
- class CookieTest extends \PHPUnit_Framework_TestCase
18
- {
19
- public function testExtractsAndStoresCookies()
20
- {
21
- $request = new Request('GET', '/');
22
- $response = new Response(200);
23
- $mock = $this->getMockBuilder('GuzzleHttp\Cookie\CookieJar')
24
- ->setMethods(array('extractCookies'))
25
- ->getMock();
26
-
27
- $mock->expects($this->exactly(1))
28
- ->method('extractCookies')
29
- ->with($request, $response);
30
-
31
- $plugin = new Cookie($mock);
32
- $t = new Transaction(new Client(), $request);
33
- $t->response = $response;
34
- $plugin->onComplete(new CompleteEvent($t));
35
- }
36
-
37
- public function testProvidesCookieJar()
38
- {
39
- $jar = new CookieJar();
40
- $plugin = new Cookie($jar);
41
- $this->assertSame($jar, $plugin->getCookieJar());
42
- }
43
-
44
- public function testCookiesAreExtractedFromRedirectResponses()
45
- {
46
- $jar = new CookieJar();
47
- $cookie = new Cookie($jar);
48
- $history = new History();
49
- $mock = new Mock([
50
- "HTTP/1.1 302 Moved Temporarily\r\n" .
51
- "Set-Cookie: test=583551; Domain=www.foo.com; Expires=Wednesday, 23-Mar-2050 19:49:45 GMT; Path=/\r\n" .
52
- "Location: /redirect\r\n\r\n",
53
- "HTTP/1.1 200 OK\r\n" .
54
- "Content-Length: 0\r\n\r\n",
55
- "HTTP/1.1 200 OK\r\n" .
56
- "Content-Length: 0\r\n\r\n"
57
- ]);
58
- $client = new Client(['base_url' => 'http://www.foo.com']);
59
- $client->getEmitter()->attach($cookie);
60
- $client->getEmitter()->attach($mock);
61
- $client->getEmitter()->attach($history);
62
-
63
- $client->get();
64
- $request = $client->createRequest('GET', '/');
65
- $client->send($request);
66
-
67
- $this->assertEquals('test=583551', $request->getHeader('Cookie'));
68
- $requests = $history->getRequests();
69
- // Confirm subsequent requests have the cookie.
70
- $this->assertEquals('test=583551', $requests[2]->getHeader('Cookie'));
71
- // Confirm the redirected request has the cookie.
72
- $this->assertEquals('test=583551', $requests[1]->getHeader('Cookie'));
73
- }
74
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Subscriber/HistoryTest.php DELETED
@@ -1,140 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Subscriber;
3
-
4
- use GuzzleHttp\Transaction;
5
- use GuzzleHttp\Client;
6
- use GuzzleHttp\Event\CompleteEvent;
7
- use GuzzleHttp\Event\ErrorEvent;
8
- use GuzzleHttp\Exception\RequestException;
9
- use GuzzleHttp\Message\Request;
10
- use GuzzleHttp\Message\Response;
11
- use GuzzleHttp\Stream\Stream;
12
- use GuzzleHttp\Subscriber\History;
13
- use GuzzleHttp\Subscriber\Mock;
14
-
15
- /**
16
- * @covers GuzzleHttp\Subscriber\History
17
- */
18
- class HistoryTest extends \PHPUnit_Framework_TestCase
19
- {
20
- public function testAddsForErrorEvent()
21
- {
22
- $request = new Request('GET', '/');
23
- $response = new Response(400);
24
- $t = new Transaction(new Client(), $request);
25
- $t->response = $response;
26
- $e = new RequestException('foo', $request, $response);
27
- $ev = new ErrorEvent($t, $e);
28
- $h = new History(2);
29
- $h->onError($ev);
30
- // Only tracks when no response is present
31
- $this->assertEquals([], $h->getRequests());
32
- }
33
-
34
- public function testLogsConnectionErrors()
35
- {
36
- $request = new Request('GET', '/');
37
- $t = new Transaction(new Client(), $request);
38
- $e = new RequestException('foo', $request);
39
- $ev = new ErrorEvent($t, $e);
40
- $h = new History();
41
- $h->onError($ev);
42
- $this->assertEquals([$request], $h->getRequests());
43
- }
44
-
45
- public function testMaintainsLimitValue()
46
- {
47
- $request = new Request('GET', '/');
48
- $response = new Response(200);
49
- $t = new Transaction(new Client(), $request);
50
- $t->response = $response;
51
- $ev = new CompleteEvent($t);
52
- $h = new History(2);
53
- $h->onComplete($ev);
54
- $h->onComplete($ev);
55
- $h->onComplete($ev);
56
- $this->assertEquals(2, count($h));
57
- $this->assertSame($request, $h->getLastRequest());
58
- $this->assertSame($response, $h->getLastResponse());
59
- foreach ($h as $trans) {
60
- $this->assertInstanceOf('GuzzleHttp\Message\RequestInterface', $trans['request']);
61
- $this->assertInstanceOf('GuzzleHttp\Message\ResponseInterface', $trans['response']);
62
- }
63
- return $h;
64
- }
65
-
66
- /**
67
- * @depends testMaintainsLimitValue
68
- */
69
- public function testClearsHistory($h)
70
- {
71
- $this->assertEquals(2, count($h));
72
- $h->clear();
73
- $this->assertEquals(0, count($h));
74
- }
75
-
76
- public function testWorksWithMock()
77
- {
78
- $client = new Client(['base_url' => 'http://localhost/']);
79
- $h = new History();
80
- $client->getEmitter()->attach($h);
81
- $mock = new Mock([new Response(200), new Response(201), new Response(202)]);
82
- $client->getEmitter()->attach($mock);
83
- $request = $client->createRequest('GET', '/');
84
- $client->send($request);
85
- $request->setMethod('PUT');
86
- $client->send($request);
87
- $request->setMethod('POST');
88
- $client->send($request);
89
- $this->assertEquals(3, count($h));
90
-
91
- $result = implode("\n", array_map(function ($line) {
92
- return strpos($line, 'User-Agent') === 0
93
- ? 'User-Agent:'
94
- : trim($line);
95
- }, explode("\n", $h)));
96
-
97
- $this->assertEquals("> GET / HTTP/1.1
98
- Host: localhost
99
- User-Agent:
100
-
101
- < HTTP/1.1 200 OK
102
-
103
- > PUT / HTTP/1.1
104
- Host: localhost
105
- User-Agent:
106
-
107
- < HTTP/1.1 201 Created
108
-
109
- > POST / HTTP/1.1
110
- Host: localhost
111
- User-Agent:
112
-
113
- < HTTP/1.1 202 Accepted
114
- ", $result);
115
- }
116
-
117
- public function testCanCastToString()
118
- {
119
- $client = new Client(['base_url' => 'http://localhost/']);
120
- $h = new History();
121
- $client->getEmitter()->attach($h);
122
-
123
- $mock = new Mock(array(
124
- new Response(301, array('Location' => '/redirect1', 'Content-Length' => 0)),
125
- new Response(307, array('Location' => '/redirect2', 'Content-Length' => 0)),
126
- new Response(200, array('Content-Length' => '2'), Stream::factory('HI'))
127
- ));
128
-
129
- $client->getEmitter()->attach($mock);
130
- $request = $client->createRequest('GET', '/');
131
- $client->send($request);
132
- $this->assertEquals(3, count($h));
133
-
134
- $h = str_replace("\r", '', $h);
135
- $this->assertContains("> GET / HTTP/1.1\nHost: localhost\nUser-Agent:", $h);
136
- $this->assertContains("< HTTP/1.1 301 Moved Permanently\nLocation: /redirect1", $h);
137
- $this->assertContains("< HTTP/1.1 307 Temporary Redirect\nLocation: /redirect2", $h);
138
- $this->assertContains("< HTTP/1.1 200 OK\nContent-Length: 2\n\nHI", $h);
139
- }
140
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Subscriber/HttpErrorTest.php DELETED
@@ -1,60 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Message;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Event\CompleteEvent;
6
- use GuzzleHttp\Message\Request;
7
- use GuzzleHttp\Message\Response;
8
- use GuzzleHttp\Subscriber\HttpError;
9
- use GuzzleHttp\Transaction;
10
- use GuzzleHttp\Subscriber\Mock;
11
-
12
- /**
13
- * @covers GuzzleHttp\Subscriber\HttpError
14
- */
15
- class HttpErrorTest extends \PHPUnit_Framework_TestCase
16
- {
17
- public function testIgnoreSuccessfulRequests()
18
- {
19
- $event = $this->getEvent();
20
- $event->intercept(new Response(200));
21
- (new HttpError())->onComplete($event);
22
- }
23
-
24
- /**
25
- * @expectedException \GuzzleHttp\Exception\ClientException
26
- */
27
- public function testThrowsClientExceptionOnFailure()
28
- {
29
- $event = $this->getEvent();
30
- $event->intercept(new Response(403));
31
- (new HttpError())->onComplete($event);
32
- }
33
-
34
- /**
35
- * @expectedException \GuzzleHttp\Exception\ServerException
36
- */
37
- public function testThrowsServerExceptionOnFailure()
38
- {
39
- $event = $this->getEvent();
40
- $event->intercept(new Response(500));
41
- (new HttpError())->onComplete($event);
42
- }
43
-
44
- private function getEvent()
45
- {
46
- return new CompleteEvent(new Transaction(new Client(), new Request('PUT', '/')));
47
- }
48
-
49
- /**
50
- * @expectedException \GuzzleHttp\Exception\ClientException
51
- */
52
- public function testFullTransaction()
53
- {
54
- $client = new Client();
55
- $client->getEmitter()->attach(new Mock([
56
- new Response(403)
57
- ]));
58
- $client->get('http://httpbin.org');
59
- }
60
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Subscriber/MockTest.php DELETED
@@ -1,225 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Subscriber;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Subscriber\Mock;
6
- use GuzzleHttp\Message\FutureResponse;
7
- use GuzzleHttp\Transaction;
8
- use GuzzleHttp\Event\BeforeEvent;
9
- use GuzzleHttp\Exception\RequestException;
10
- use GuzzleHttp\Message\MessageFactory;
11
- use GuzzleHttp\Message\Request;
12
- use GuzzleHttp\Message\Response;
13
- use GuzzleHttp\Stream\Stream;
14
- use React\Promise\Deferred;
15
-
16
- /**
17
- * @covers GuzzleHttp\Subscriber\Mock
18
- */
19
- class MockTest extends \PHPUnit_Framework_TestCase
20
- {
21
- public static function createFuture(
22
- callable $wait,
23
- callable $cancel = null
24
- ) {
25
- $deferred = new Deferred();
26
- return new FutureResponse(
27
- $deferred->promise(),
28
- function () use ($deferred, $wait) {
29
- $deferred->resolve($wait());
30
- },
31
- $cancel
32
- );
33
- }
34
-
35
- public function testDescribesSubscribedEvents()
36
- {
37
- $mock = new Mock();
38
- $this->assertInternalType('array', $mock->getEvents());
39
- }
40
-
41
- public function testIsCountable()
42
- {
43
- $plugin = new Mock();
44
- $plugin->addResponse((new MessageFactory())->fromMessage("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"));
45
- $this->assertEquals(1, count($plugin));
46
- }
47
-
48
- public function testCanClearQueue()
49
- {
50
- $plugin = new Mock();
51
- $plugin->addResponse((new MessageFactory())->fromMessage("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"));
52
- $plugin->clearQueue();
53
- $this->assertEquals(0, count($plugin));
54
- }
55
-
56
- public function testRetrievesResponsesFromFiles()
57
- {
58
- $tmp = tempnam('/tmp', 'tfile');
59
- file_put_contents($tmp, "HTTP/1.1 201 OK\r\nContent-Length: 0\r\n\r\n");
60
- $plugin = new Mock();
61
- $plugin->addResponse($tmp);
62
- unlink($tmp);
63
- $this->assertEquals(1, count($plugin));
64
- $q = $this->readAttribute($plugin, 'queue');
65
- $this->assertEquals(201, $q[0]->getStatusCode());
66
- }
67
-
68
- /**
69
- * @expectedException \InvalidArgumentException
70
- */
71
- public function testThrowsExceptionWhenInvalidResponse()
72
- {
73
- (new Mock())->addResponse(false);
74
- }
75
-
76
- public function testAddsMockResponseToRequestFromClient()
77
- {
78
- $response = new Response(200);
79
- $t = new Transaction(new Client(), new Request('GET', '/'));
80
- $m = new Mock([$response]);
81
- $ev = new BeforeEvent($t);
82
- $m->onBefore($ev);
83
- $this->assertSame($response, $t->response);
84
- }
85
-
86
- /**
87
- * @expectedException \OutOfBoundsException
88
- */
89
- public function testUpdateThrowsExceptionWhenEmpty()
90
- {
91
- $p = new Mock();
92
- $ev = new BeforeEvent(new Transaction(new Client(), new Request('GET', '/')));
93
- $p->onBefore($ev);
94
- }
95
-
96
- public function testReadsBodiesFromMockedRequests()
97
- {
98
- $m = new Mock([new Response(200)]);
99
- $client = new Client(['base_url' => 'http://test.com']);
100
- $client->getEmitter()->attach($m);
101
- $body = Stream::factory('foo');
102
- $client->put('/', ['body' => $body]);
103
- $this->assertEquals(3, $body->tell());
104
- }
105
-
106
- public function testCanMockBadRequestExceptions()
107
- {
108
- $client = new Client(['base_url' => 'http://test.com']);
109
- $request = $client->createRequest('GET', '/');
110
- $ex = new RequestException('foo', $request);
111
- $mock = new Mock([$ex]);
112
- $this->assertCount(1, $mock);
113
- $request->getEmitter()->attach($mock);
114
-
115
- try {
116
- $client->send($request);
117
- $this->fail('Did not dequeue an exception');
118
- } catch (RequestException $e) {
119
- $this->assertSame($e, $ex);
120
- $this->assertSame($request, $ex->getRequest());
121
- }
122
- }
123
-
124
- public function testCanMockFutureResponses()
125
- {
126
- $client = new Client(['base_url' => 'http://test.com']);
127
- $request = $client->createRequest('GET', '/', ['future' => true]);
128
- $response = new Response(200);
129
- $future = self::createFuture(function () use ($response) {
130
- return $response;
131
- });
132
- $mock = new Mock([$future]);
133
- $this->assertCount(1, $mock);
134
- $request->getEmitter()->attach($mock);
135
- $res = $client->send($request);
136
- $this->assertSame($future, $res);
137
- $this->assertFalse($this->readAttribute($res, 'isRealized'));
138
- $this->assertSame($response, $res->wait());
139
- }
140
-
141
- public function testCanMockExceptionFutureResponses()
142
- {
143
- $client = new Client(['base_url' => 'http://test.com']);
144
- $request = $client->createRequest('GET', '/', ['future' => true]);
145
- $future = self::createFuture(function () use ($request) {
146
- throw new RequestException('foo', $request);
147
- });
148
-
149
- $mock = new Mock([$future]);
150
- $request->getEmitter()->attach($mock);
151
- $response = $client->send($request);
152
- $this->assertSame($future, $response);
153
- $this->assertFalse($this->readAttribute($response, 'isRealized'));
154
-
155
- try {
156
- $response->wait();
157
- $this->fail('Did not throw');
158
- } catch (RequestException $e) {
159
- $this->assertContains('foo', $e->getMessage());
160
- }
161
- }
162
-
163
- public function testSaveToFile()
164
- {
165
- $filename = sys_get_temp_dir().'/mock_test_'.uniqid();
166
- $file = tmpfile();
167
- $stream = new Stream(tmpfile());
168
-
169
- $m = new Mock([
170
- new Response(200, [], Stream::factory('TEST FILENAME')),
171
- new Response(200, [], Stream::factory('TEST FILE')),
172
- new Response(200, [], Stream::factory('TEST STREAM')),
173
- ]);
174
-
175
- $client = new Client();
176
- $client->getEmitter()->attach($m);
177
-
178
- $client->get('/', ['save_to' => $filename]);
179
- $client->get('/', ['save_to' => $file]);
180
- $client->get('/', ['save_to' => $stream]);
181
-
182
- $this->assertFileExists($filename);
183
- $this->assertEquals('TEST FILENAME', file_get_contents($filename));
184
-
185
- $meta = stream_get_meta_data($file);
186
-
187
- $this->assertFileExists($meta['uri']);
188
- $this->assertEquals('TEST FILE', file_get_contents($meta['uri']));
189
-
190
- $this->assertFileExists($stream->getMetadata('uri'));
191
- $this->assertEquals('TEST STREAM', file_get_contents($stream->getMetadata('uri')));
192
-
193
- unlink($filename);
194
- }
195
-
196
- public function testCanMockFailedFutureResponses()
197
- {
198
- $client = new Client(['base_url' => 'http://test.com']);
199
- $request = $client->createRequest('GET', '/', ['future' => true]);
200
-
201
- // The first mock will be a mocked future response.
202
- $future = self::createFuture(function () use ($client) {
203
- // When dereferenced, we will set a mocked response and send
204
- // another request.
205
- $client->get('http://httpbin.org', ['events' => [
206
- 'before' => function (BeforeEvent $e) {
207
- $e->intercept(new Response(404));
208
- }
209
- ]]);
210
- });
211
-
212
- $mock = new Mock([$future]);
213
- $request->getEmitter()->attach($mock);
214
- $response = $client->send($request);
215
- $this->assertSame($future, $response);
216
- $this->assertFalse($this->readAttribute($response, 'isRealized'));
217
-
218
- try {
219
- $response->wait();
220
- $this->fail('Did not throw');
221
- } catch (RequestException $e) {
222
- $this->assertEquals(404, $e->getResponse()->getStatusCode());
223
- }
224
- }
225
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Subscriber/PrepareTest.php DELETED
@@ -1,213 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Message;
3
-
4
- use GuzzleHttp\Message\Response;
5
- use GuzzleHttp\Tests\Server;
6
- use GuzzleHttp\Transaction;
7
- use GuzzleHttp\Client;
8
- use GuzzleHttp\Event\BeforeEvent;
9
- use GuzzleHttp\Message\Request;
10
- use GuzzleHttp\Stream\NoSeekStream;
11
- use GuzzleHttp\Stream\Stream;
12
- use GuzzleHttp\Subscriber\Prepare;
13
-
14
- /**
15
- * @covers GuzzleHttp\Subscriber\Prepare
16
- */
17
- class PrepareTest extends \PHPUnit_Framework_TestCase
18
- {
19
- public function testIgnoresRequestsWithNoBody()
20
- {
21
- $s = new Prepare();
22
- $t = $this->getTrans();
23
- $s->onBefore(new BeforeEvent($t));
24
- $this->assertFalse($t->request->hasHeader('Expect'));
25
- }
26
-
27
- public function testAppliesPostBody()
28
- {
29
- $s = new Prepare();
30
- $t = $this->getTrans();
31
- $p = $this->getMockBuilder('GuzzleHttp\Post\PostBody')
32
- ->setMethods(['applyRequestHeaders'])
33
- ->getMockForAbstractClass();
34
- $p->expects($this->once())
35
- ->method('applyRequestHeaders');
36
- $t->request->setBody($p);
37
- $s->onBefore(new BeforeEvent($t));
38
- }
39
-
40
- public function testAddsExpectHeaderWithTrue()
41
- {
42
- $s = new Prepare();
43
- $t = $this->getTrans();
44
- $t->request->getConfig()->set('expect', true);
45
- $t->request->setBody(Stream::factory('foo'));
46
- $s->onBefore(new BeforeEvent($t));
47
- $this->assertEquals('100-Continue', $t->request->getHeader('Expect'));
48
- }
49
-
50
- public function testAddsExpectHeaderBySize()
51
- {
52
- $s = new Prepare();
53
- $t = $this->getTrans();
54
- $t->request->getConfig()->set('expect', 2);
55
- $t->request->setBody(Stream::factory('foo'));
56
- $s->onBefore(new BeforeEvent($t));
57
- $this->assertTrue($t->request->hasHeader('Expect'));
58
- }
59
-
60
- public function testDoesNotModifyExpectHeaderIfPresent()
61
- {
62
- $s = new Prepare();
63
- $t = $this->getTrans();
64
- $t->request->setHeader('Expect', 'foo');
65
- $t->request->setBody(Stream::factory('foo'));
66
- $s->onBefore(new BeforeEvent($t));
67
- $this->assertEquals('foo', $t->request->getHeader('Expect'));
68
- }
69
-
70
- public function testDoesAddExpectHeaderWhenSetToFalse()
71
- {
72
- $s = new Prepare();
73
- $t = $this->getTrans();
74
- $t->request->getConfig()->set('expect', false);
75
- $t->request->setBody(Stream::factory('foo'));
76
- $s->onBefore(new BeforeEvent($t));
77
- $this->assertFalse($t->request->hasHeader('Expect'));
78
- }
79
-
80
- public function testDoesNotAddExpectHeaderBySize()
81
- {
82
- $s = new Prepare();
83
- $t = $this->getTrans();
84
- $t->request->getConfig()->set('expect', 10);
85
- $t->request->setBody(Stream::factory('foo'));
86
- $s->onBefore(new BeforeEvent($t));
87
- $this->assertFalse($t->request->hasHeader('Expect'));
88
- }
89
-
90
- public function testAddsExpectHeaderForNonSeekable()
91
- {
92
- $s = new Prepare();
93
- $t = $this->getTrans();
94
- $t->request->setBody(new NoSeekStream(Stream::factory('foo')));
95
- $s->onBefore(new BeforeEvent($t));
96
- $this->assertTrue($t->request->hasHeader('Expect'));
97
- }
98
-
99
- public function testRemovesContentLengthWhenSendingWithChunked()
100
- {
101
- $s = new Prepare();
102
- $t = $this->getTrans();
103
- $t->request->setBody(Stream::factory('foo'));
104
- $t->request->setHeader('Transfer-Encoding', 'chunked');
105
- $s->onBefore(new BeforeEvent($t));
106
- $this->assertFalse($t->request->hasHeader('Content-Length'));
107
- }
108
-
109
- public function testUsesProvidedContentLengthAndRemovesXferEncoding()
110
- {
111
- $s = new Prepare();
112
- $t = $this->getTrans();
113
- $t->request->setBody(Stream::factory('foo'));
114
- $t->request->setHeader('Content-Length', '3');
115
- $t->request->setHeader('Transfer-Encoding', 'chunked');
116
- $s->onBefore(new BeforeEvent($t));
117
- $this->assertEquals(3, $t->request->getHeader('Content-Length'));
118
- $this->assertFalse($t->request->hasHeader('Transfer-Encoding'));
119
- }
120
-
121
- public function testSetsContentTypeIfPossibleFromStream()
122
- {
123
- $body = $this->getMockBody();
124
- $sub = new Prepare();
125
- $t = $this->getTrans();
126
- $t->request->setBody($body);
127
- $sub->onBefore(new BeforeEvent($t));
128
- $this->assertEquals(
129
- 'image/jpeg',
130
- $t->request->getHeader('Content-Type')
131
- );
132
- $this->assertEquals(4, $t->request->getHeader('Content-Length'));
133
- }
134
-
135
- public function testDoesNotOverwriteExistingContentType()
136
- {
137
- $s = new Prepare();
138
- $t = $this->getTrans();
139
- $t->request->setBody($this->getMockBody());
140
- $t->request->setHeader('Content-Type', 'foo/baz');
141
- $s->onBefore(new BeforeEvent($t));
142
- $this->assertEquals(
143
- 'foo/baz',
144
- $t->request->getHeader('Content-Type')
145
- );
146
- }
147
-
148
- public function testSetsContentLengthIfPossible()
149
- {
150
- $s = new Prepare();
151
- $t = $this->getTrans();
152
- $t->request->setBody($this->getMockBody());
153
- $s->onBefore(new BeforeEvent($t));
154
- $this->assertEquals(4, $t->request->getHeader('Content-Length'));
155
- }
156
-
157
- public function testSetsTransferEncodingChunkedIfNeeded()
158
- {
159
- $r = new Request('PUT', '/');
160
- $s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
161
- ->setMethods(['getSize'])
162
- ->getMockForAbstractClass();
163
- $s->expects($this->exactly(2))
164
- ->method('getSize')
165
- ->will($this->returnValue(null));
166
- $r->setBody($s);
167
- $t = $this->getTrans($r);
168
- $s = new Prepare();
169
- $s->onBefore(new BeforeEvent($t));
170
- $this->assertEquals('chunked', $r->getHeader('Transfer-Encoding'));
171
- }
172
-
173
- public function testContentLengthIntegrationTest()
174
- {
175
- Server::flush();
176
- Server::enqueue([new Response(200)]);
177
- $client = new Client(['base_url' => Server::$url]);
178
- $this->assertEquals(200, $client->put('/', [
179
- 'body' => 'test'
180
- ])->getStatusCode());
181
- $request = Server::received(true)[0];
182
- $this->assertEquals('PUT', $request->getMethod());
183
- $this->assertEquals('4', $request->getHeader('Content-Length'));
184
- $this->assertEquals('test', (string) $request->getBody());
185
- }
186
-
187
- private function getTrans($request = null)
188
- {
189
- return new Transaction(
190
- new Client(),
191
- $request ?: new Request('PUT', '/')
192
- );
193
- }
194
-
195
- /**
196
- * @return \GuzzleHttp\Stream\StreamInterface
197
- */
198
- private function getMockBody()
199
- {
200
- $s = $this->getMockBuilder('GuzzleHttp\Stream\MetadataStreamInterface')
201
- ->setMethods(['getMetadata', 'getSize'])
202
- ->getMockForAbstractClass();
203
- $s->expects($this->any())
204
- ->method('getMetadata')
205
- ->with('uri')
206
- ->will($this->returnValue('/foo/baz/bar.jpg'));
207
- $s->expects($this->exactly(2))
208
- ->method('getSize')
209
- ->will($this->returnValue(4));
210
-
211
- return $s;
212
- }
213
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/Subscriber/RedirectTest.php DELETED
@@ -1,302 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests\Plugin\Redirect;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Subscriber\History;
6
- use GuzzleHttp\Subscriber\Mock;
7
-
8
- /**
9
- * @covers GuzzleHttp\Subscriber\Redirect
10
- */
11
- class RedirectTest extends \PHPUnit_Framework_TestCase
12
- {
13
- public function testRedirectsRequests()
14
- {
15
- $mock = new Mock();
16
- $history = new History();
17
- $mock->addMultiple([
18
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect1\r\nContent-Length: 0\r\n\r\n",
19
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect2\r\nContent-Length: 0\r\n\r\n",
20
- "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
21
- ]);
22
-
23
- $client = new Client(['base_url' => 'http://test.com']);
24
- $client->getEmitter()->attach($history);
25
- $client->getEmitter()->attach($mock);
26
-
27
- $request = $client->createRequest('GET', '/foo');
28
- // Ensure "end" is called only once
29
- $called = 0;
30
- $request->getEmitter()->on('end', function () use (&$called) {
31
- $called++;
32
- });
33
- $response = $client->send($request);
34
-
35
- $this->assertEquals(200, $response->getStatusCode());
36
- $this->assertContains('/redirect2', $response->getEffectiveUrl());
37
-
38
- // Ensure that two requests were sent
39
- $requests = $history->getRequests(true);
40
-
41
- $this->assertEquals('/foo', $requests[0]->getPath());
42
- $this->assertEquals('GET', $requests[0]->getMethod());
43
- $this->assertEquals('/redirect1', $requests[1]->getPath());
44
- $this->assertEquals('GET', $requests[1]->getMethod());
45
- $this->assertEquals('/redirect2', $requests[2]->getPath());
46
- $this->assertEquals('GET', $requests[2]->getMethod());
47
-
48
- $this->assertEquals(1, $called);
49
- }
50
-
51
- /**
52
- * @expectedException \GuzzleHttp\Exception\TooManyRedirectsException
53
- * @expectedExceptionMessage Will not follow more than
54
- */
55
- public function testCanLimitNumberOfRedirects()
56
- {
57
- $mock = new Mock([
58
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect1\r\nContent-Length: 0\r\n\r\n",
59
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect2\r\nContent-Length: 0\r\n\r\n",
60
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect3\r\nContent-Length: 0\r\n\r\n",
61
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect4\r\nContent-Length: 0\r\n\r\n",
62
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect5\r\nContent-Length: 0\r\n\r\n",
63
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect6\r\nContent-Length: 0\r\n\r\n"
64
- ]);
65
- $client = new Client();
66
- $client->getEmitter()->attach($mock);
67
- $client->get('http://www.example.com/foo');
68
- }
69
-
70
- public function testDefaultBehaviorIsToRedirectWithGetForEntityEnclosingRequests()
71
- {
72
- $h = new History();
73
- $mock = new Mock([
74
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
75
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
76
- "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
77
- ]);
78
- $client = new Client();
79
- $client->getEmitter()->attach($mock);
80
- $client->getEmitter()->attach($h);
81
- $client->post('http://test.com/foo', [
82
- 'headers' => ['X-Baz' => 'bar'],
83
- 'body' => 'testing'
84
- ]);
85
-
86
- $requests = $h->getRequests(true);
87
- $this->assertEquals('POST', $requests[0]->getMethod());
88
- $this->assertEquals('GET', $requests[1]->getMethod());
89
- $this->assertEquals('bar', (string) $requests[1]->getHeader('X-Baz'));
90
- $this->assertEquals('GET', $requests[2]->getMethod());
91
- }
92
-
93
- public function testCanRedirectWithStrictRfcCompliance()
94
- {
95
- $h = new History();
96
- $mock = new Mock([
97
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
98
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
99
- "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
100
- ]);
101
- $client = new Client(['base_url' => 'http://test.com']);
102
- $client->getEmitter()->attach($mock);
103
- $client->getEmitter()->attach($h);
104
- $client->post('/foo', [
105
- 'headers' => ['X-Baz' => 'bar'],
106
- 'body' => 'testing',
107
- 'allow_redirects' => ['max' => 10, 'strict' => true]
108
- ]);
109
-
110
- $requests = $h->getRequests(true);
111
- $this->assertEquals('POST', $requests[0]->getMethod());
112
- $this->assertEquals('POST', $requests[1]->getMethod());
113
- $this->assertEquals('bar', (string) $requests[1]->getHeader('X-Baz'));
114
- $this->assertEquals('POST', $requests[2]->getMethod());
115
- }
116
-
117
- public function testRewindsStreamWhenRedirectingIfNeeded()
118
- {
119
- $h = new History();
120
- $mock = new Mock([
121
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
122
- "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
123
- ]);
124
- $client = new Client(['base_url' => 'http://test.com']);
125
- $client->getEmitter()->attach($mock);
126
- $client->getEmitter()->attach($h);
127
-
128
- $body = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
129
- ->setMethods(['seek', 'read', 'eof', 'tell'])
130
- ->getMockForAbstractClass();
131
- $body->expects($this->once())->method('tell')->will($this->returnValue(1));
132
- $body->expects($this->once())->method('seek')->will($this->returnValue(true));
133
- $body->expects($this->any())->method('eof')->will($this->returnValue(true));
134
- $body->expects($this->any())->method('read')->will($this->returnValue('foo'));
135
- $client->post('/foo', [
136
- 'body' => $body,
137
- 'allow_redirects' => ['max' => 5, 'strict' => true]
138
- ]);
139
- }
140
-
141
- /**
142
- * @expectedException \GuzzleHttp\Exception\CouldNotRewindStreamException
143
- * @expectedExceptionMessage Unable to rewind the non-seekable request body after redirecting
144
- */
145
- public function testThrowsExceptionWhenStreamCannotBeRewound()
146
- {
147
- $h = new History();
148
- $mock = new Mock([
149
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
150
- "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
151
- ]);
152
- $client = new Client();
153
- $client->getEmitter()->attach($mock);
154
- $client->getEmitter()->attach($h);
155
-
156
- $body = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
157
- ->setMethods(['seek', 'read', 'eof', 'tell'])
158
- ->getMockForAbstractClass();
159
- $body->expects($this->once())->method('tell')->will($this->returnValue(1));
160
- $body->expects($this->once())->method('seek')->will($this->returnValue(false));
161
- $body->expects($this->any())->method('eof')->will($this->returnValue(true));
162
- $body->expects($this->any())->method('read')->will($this->returnValue('foo'));
163
- $client->post('http://example.com/foo', [
164
- 'body' => $body,
165
- 'allow_redirects' => ['max' => 10, 'strict' => true]
166
- ]);
167
- }
168
-
169
- public function testRedirectsCanBeDisabledPerRequest()
170
- {
171
- $client = new Client(['base_url' => 'http://test.com']);
172
- $client->getEmitter()->attach(new Mock([
173
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
174
- "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
175
- ]));
176
- $response = $client->put('/', ['body' => 'test', 'allow_redirects' => false]);
177
- $this->assertEquals(301, $response->getStatusCode());
178
- }
179
-
180
- public function testCanRedirectWithNoLeadingSlashAndQuery()
181
- {
182
- $h = new History();
183
- $client = new Client(['base_url' => 'http://www.foo.com']);
184
- $client->getEmitter()->attach(new Mock([
185
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect?foo=bar\r\nContent-Length: 0\r\n\r\n",
186
- "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
187
- ]));
188
- $client->getEmitter()->attach($h);
189
- $client->get('?foo=bar');
190
- $requests = $h->getRequests(true);
191
- $this->assertEquals('http://www.foo.com?foo=bar', $requests[0]->getUrl());
192
- $this->assertEquals('http://www.foo.com/redirect?foo=bar', $requests[1]->getUrl());
193
- }
194
-
195
- public function testHandlesRedirectsWithSpacesProperly()
196
- {
197
- $client = new Client(['base_url' => 'http://www.foo.com']);
198
- $client->getEmitter()->attach(new Mock([
199
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect 1\r\nContent-Length: 0\r\n\r\n",
200
- "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
201
- ]));
202
- $h = new History();
203
- $client->getEmitter()->attach($h);
204
- $client->get('/foo');
205
- $reqs = $h->getRequests(true);
206
- $this->assertEquals('/redirect%201', $reqs[1]->getResource());
207
- }
208
-
209
- public function testAddsRefererWhenPossible()
210
- {
211
- $client = new Client(['base_url' => 'http://www.foo.com']);
212
- $client->getEmitter()->attach(new Mock([
213
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /bar\r\nContent-Length: 0\r\n\r\n",
214
- "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
215
- ]));
216
- $h = new History();
217
- $client->getEmitter()->attach($h);
218
- $client->get('/foo', ['allow_redirects' => ['max' => 5, 'referer' => true]]);
219
- $reqs = $h->getRequests(true);
220
- $this->assertEquals('http://www.foo.com/foo', $reqs[1]->getHeader('Referer'));
221
- }
222
-
223
- public function testDoesNotAddRefererWhenChangingProtocols()
224
- {
225
- $client = new Client(['base_url' => 'https://www.foo.com']);
226
- $client->getEmitter()->attach(new Mock([
227
- "HTTP/1.1 301 Moved Permanently\r\n"
228
- . "Location: http://www.foo.com/foo\r\n"
229
- . "Content-Length: 0\r\n\r\n",
230
- "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
231
- ]));
232
- $h = new History();
233
- $client->getEmitter()->attach($h);
234
- $client->get('/foo', ['allow_redirects' => ['max' => 5, 'referer' => true]]);
235
- $reqs = $h->getRequests(true);
236
- $this->assertFalse($reqs[1]->hasHeader('Referer'));
237
- }
238
-
239
- public function testRedirectsWithGetOn303()
240
- {
241
- $h = new History();
242
- $mock = new Mock([
243
- "HTTP/1.1 303 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
244
- "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
245
- ]);
246
- $client = new Client();
247
- $client->getEmitter()->attach($mock);
248
- $client->getEmitter()->attach($h);
249
- $client->post('http://test.com/foo', ['body' => 'testing']);
250
- $requests = $h->getRequests(true);
251
- $this->assertEquals('POST', $requests[0]->getMethod());
252
- $this->assertEquals('GET', $requests[1]->getMethod());
253
- }
254
-
255
- public function testRelativeLinkBasedLatestRequest()
256
- {
257
- $client = new Client(['base_url' => 'http://www.foo.com']);
258
- $client->getEmitter()->attach(new Mock([
259
- "HTTP/1.1 301 Moved Permanently\r\nLocation: http://www.bar.com\r\nContent-Length: 0\r\n\r\n",
260
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
261
- "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
262
- ]));
263
- $response = $client->get('/');
264
- $this->assertEquals(
265
- 'http://www.bar.com/redirect',
266
- $response->getEffectiveUrl()
267
- );
268
- }
269
-
270
- public function testUpperCaseScheme()
271
- {
272
- $client = new Client(['base_url' => 'http://www.foo.com']);
273
- $client->getEmitter()->attach(new Mock([
274
- "HTTP/1.1 301 Moved Permanently\r\nLocation: HTTP://www.bar.com\r\nContent-Length: 0\r\n\r\n",
275
- "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
276
- ]));
277
- $response = $client->get('/');
278
- $this->assertEquals(
279
- 'http://www.bar.com',
280
- $response->getEffectiveUrl()
281
- );
282
- }
283
-
284
- /**
285
- * @expectedException \GuzzleHttp\Exception\BadResponseException
286
- * @expectedExceptionMessage Redirect URL, https://foo.com/redirect2, does not use one of the allowed redirect protocols: http
287
- */
288
- public function testThrowsWhenRedirectingToInvalidUrlProtocol()
289
- {
290
- $mock = new Mock([
291
- "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect1\r\nContent-Length: 0\r\n\r\n",
292
- "HTTP/1.1 301 Moved Permanently\r\nLocation: https://foo.com/redirect2\r\nContent-Length: 0\r\n\r\n"
293
- ]);
294
- $client = new Client();
295
- $client->getEmitter()->attach($mock);
296
- $client->get('http://www.example.com/foo', [
297
- 'allow_redirects' => [
298
- 'protocols' => ['http']
299
- ]
300
- ]);
301
- }
302
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/TransactionTest.php DELETED
@@ -1,22 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests;
3
-
4
- use GuzzleHttp\Client;
5
- use GuzzleHttp\Message\Request;
6
- use GuzzleHttp\Message\Response;
7
- use GuzzleHttp\Transaction;
8
-
9
- class TransactionTest extends \PHPUnit_Framework_TestCase
10
- {
11
- public function testHoldsData()
12
- {
13
- $client = new Client();
14
- $request = new Request('GET', 'http://www.foo.com');
15
- $t = new Transaction($client, $request);
16
- $this->assertSame($client, $t->client);
17
- $this->assertSame($request, $t->request);
18
- $response = new Response(200);
19
- $t->response = $response;
20
- $this->assertSame($response, $t->response);
21
- }
22
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/UriTemplateTest.php DELETED
@@ -1,202 +0,0 @@
1
- <?php
2
-
3
- namespace GuzzleHttp\Tests;
4
-
5
- use GuzzleHttp\UriTemplate;
6
-
7
- /**
8
- * @covers GuzzleHttp\UriTemplate
9
- */
10
- class UriTemplateTest extends \PHPUnit_Framework_TestCase
11
- {
12
- /**
13
- * @return array
14
- */
15
- public function templateProvider()
16
- {
17
- $params = array(
18
- 'var' => 'value',
19
- 'hello' => 'Hello World!',
20
- 'empty' => '',
21
- 'path' => '/foo/bar',
22
- 'x' => '1024',
23
- 'y' => '768',
24
- 'null' => null,
25
- 'list' => array('red', 'green', 'blue'),
26
- 'keys' => array(
27
- "semi" => ';',
28
- "dot" => '.',
29
- "comma" => ','
30
- ),
31
- 'empty_keys' => array(),
32
- );
33
-
34
- return array_map(function ($t) use ($params) {
35
- $t[] = $params;
36
- return $t;
37
- }, array(
38
- array('foo', 'foo'),
39
- array('{var}', 'value'),
40
- array('{hello}', 'Hello%20World%21'),
41
- array('{+var}', 'value'),
42
- array('{+hello}', 'Hello%20World!'),
43
- array('{+path}/here', '/foo/bar/here'),
44
- array('here?ref={+path}', 'here?ref=/foo/bar'),
45
- array('X{#var}', 'X#value'),
46
- array('X{#hello}', 'X#Hello%20World!'),
47
- array('map?{x,y}', 'map?1024,768'),
48
- array('{x,hello,y}', '1024,Hello%20World%21,768'),
49
- array('{+x,hello,y}', '1024,Hello%20World!,768'),
50
- array('{+path,x}/here', '/foo/bar,1024/here'),
51
- array('{#x,hello,y}', '#1024,Hello%20World!,768'),
52
- array('{#path,x}/here', '#/foo/bar,1024/here'),
53
- array('X{.var}', 'X.value'),
54
- array('X{.x,y}', 'X.1024.768'),
55
- array('{/var}', '/value'),
56
- array('{/var,x}/here', '/value/1024/here'),
57
- array('{;x,y}', ';x=1024;y=768'),
58
- array('{;x,y,empty}', ';x=1024;y=768;empty'),
59
- array('{?x,y}', '?x=1024&y=768'),
60
- array('{?x,y,empty}', '?x=1024&y=768&empty='),
61
- array('?fixed=yes{&x}', '?fixed=yes&x=1024'),
62
- array('{&x,y,empty}', '&x=1024&y=768&empty='),
63
- array('{var:3}', 'val'),
64
- array('{var:30}', 'value'),
65
- array('{list}', 'red,green,blue'),
66
- array('{list*}', 'red,green,blue'),
67
- array('{keys}', 'semi,%3B,dot,.,comma,%2C'),
68
- array('{keys*}', 'semi=%3B,dot=.,comma=%2C'),
69
- array('{+path:6}/here', '/foo/b/here'),
70
- array('{+list}', 'red,green,blue'),
71
- array('{+list*}', 'red,green,blue'),
72
- array('{+keys}', 'semi,;,dot,.,comma,,'),
73
- array('{+keys*}', 'semi=;,dot=.,comma=,'),
74
- array('{#path:6}/here', '#/foo/b/here'),
75
- array('{#list}', '#red,green,blue'),
76
- array('{#list*}', '#red,green,blue'),
77
- array('{#keys}', '#semi,;,dot,.,comma,,'),
78
- array('{#keys*}', '#semi=;,dot=.,comma=,'),
79
- array('X{.var:3}', 'X.val'),
80
- array('X{.list}', 'X.red,green,blue'),
81
- array('X{.list*}', 'X.red.green.blue'),
82
- array('X{.keys}', 'X.semi,%3B,dot,.,comma,%2C'),
83
- array('X{.keys*}', 'X.semi=%3B.dot=..comma=%2C'),
84
- array('{/var:1,var}', '/v/value'),
85
- array('{/list}', '/red,green,blue'),
86
- array('{/list*}', '/red/green/blue'),
87
- array('{/list*,path:4}', '/red/green/blue/%2Ffoo'),
88
- array('{/keys}', '/semi,%3B,dot,.,comma,%2C'),
89
- array('{/keys*}', '/semi=%3B/dot=./comma=%2C'),
90
- array('{;hello:5}', ';hello=Hello'),
91
- array('{;list}', ';list=red,green,blue'),
92
- array('{;list*}', ';list=red;list=green;list=blue'),
93
- array('{;keys}', ';keys=semi,%3B,dot,.,comma,%2C'),
94
- array('{;keys*}', ';semi=%3B;dot=.;comma=%2C'),
95
- array('{?var:3}', '?var=val'),
96
- array('{?list}', '?list=red,green,blue'),
97
- array('{?list*}', '?list=red&list=green&list=blue'),
98
- array('{?keys}', '?keys=semi,%3B,dot,.,comma,%2C'),
99
- array('{?keys*}', '?semi=%3B&dot=.&comma=%2C'),
100
- array('{&var:3}', '&var=val'),
101
- array('{&list}', '&list=red,green,blue'),
102
- array('{&list*}', '&list=red&list=green&list=blue'),
103
- array('{&keys}', '&keys=semi,%3B,dot,.,comma,%2C'),
104
- array('{&keys*}', '&semi=%3B&dot=.&comma=%2C'),
105
- array('{.null}', ''),
106
- array('{.null,var}', '.value'),
107
- array('X{.empty_keys*}', 'X'),
108
- array('X{.empty_keys}', 'X'),
109
- // Test that missing expansions are skipped
110
- array('test{&missing*}', 'test'),
111
- // Test that multiple expansions can be set
112
- array('http://{var}/{var:2}{?keys*}', 'http://value/va?semi=%3B&dot=.&comma=%2C'),
113
- // Test more complex query string stuff
114
- array('http://www.test.com{+path}{?var,keys*}', 'http://www.test.com/foo/bar?var=value&semi=%3B&dot=.&comma=%2C')
115
- ));
116
- }
117
-
118
- /**
119
- * @dataProvider templateProvider
120
- */
121
- public function testExpandsUriTemplates($template, $expansion, $params)
122
- {
123
- $uri = new UriTemplate($template);
124
- $this->assertEquals($expansion, $uri->expand($template, $params));
125
- }
126
-
127
- public function expressionProvider()
128
- {
129
- return array(
130
- array(
131
- '{+var*}', array(
132
- 'operator' => '+',
133
- 'values' => array(
134
- array('value' => 'var', 'modifier' => '*')
135
- )
136
- ),
137
- ),
138
- array(
139
- '{?keys,var,val}', array(
140
- 'operator' => '?',
141
- 'values' => array(
142
- array('value' => 'keys', 'modifier' => ''),
143
- array('value' => 'var', 'modifier' => ''),
144
- array('value' => 'val', 'modifier' => '')
145
- )
146
- ),
147
- ),
148
- array(
149
- '{+x,hello,y}', array(
150
- 'operator' => '+',
151
- 'values' => array(
152
- array('value' => 'x', 'modifier' => ''),
153
- array('value' => 'hello', 'modifier' => ''),
154
- array('value' => 'y', 'modifier' => '')
155
- )
156
- )
157
- )
158
- );
159
- }
160
-
161
- /**
162
- * @dataProvider expressionProvider
163
- */
164
- public function testParsesExpressions($exp, $data)
165
- {
166
- $template = new UriTemplate($exp);
167
-
168
- // Access the config object
169
- $class = new \ReflectionClass($template);
170
- $method = $class->getMethod('parseExpression');
171
- $method->setAccessible(true);
172
-
173
- $exp = substr($exp, 1, -1);
174
- $this->assertEquals($data, $method->invokeArgs($template, array($exp)));
175
- }
176
-
177
- /**
178
- * @ticket https://github.com/guzzle/guzzle/issues/90
179
- */
180
- public function testAllowsNestedArrayExpansion()
181
- {
182
- $template = new UriTemplate();
183
-
184
- $result = $template->expand('http://example.com{+path}{/segments}{?query,data*,foo*}', array(
185
- 'path' => '/foo/bar',
186
- 'segments' => array('one', 'two'),
187
- 'query' => 'test',
188
- 'data' => array(
189
- 'more' => array('fun', 'ice cream')
190
- ),
191
- 'foo' => array(
192
- 'baz' => array(
193
- 'bar' => 'fizz',
194
- 'test' => 'buzz'
195
- ),
196
- 'bam' => 'boo'
197
- )
198
- ));
199
-
200
- $this->assertEquals('http://example.com/foo/bar/one,two?query=test&more%5B0%5D=fun&more%5B1%5D=ice%20cream&baz%5Bbar%5D=fizz&baz%5Btest%5D=buzz&bam=boo', $result);
201
- }
202
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/UrlTest.php DELETED
@@ -1,364 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests;
3
-
4
- use GuzzleHttp\Query;
5
- use GuzzleHttp\Url;
6
-
7
- /**
8
- * @covers GuzzleHttp\Url
9
- */
10
- class UrlTest extends \PHPUnit_Framework_TestCase
11
- {
12
- const RFC3986_BASE = "http://a/b/c/d;p?q";
13
-
14
- public function testEmptyUrl()
15
- {
16
- $url = Url::fromString('');
17
- $this->assertEquals('', (string) $url);
18
- }
19
-
20
- public function testPortIsDeterminedFromScheme()
21
- {
22
- $this->assertEquals(80, Url::fromString('http://www.test.com/')->getPort());
23
- $this->assertEquals(443, Url::fromString('https://www.test.com/')->getPort());
24
- $this->assertEquals(21, Url::fromString('ftp://www.test.com/')->getPort());
25
- $this->assertEquals(8192, Url::fromString('http://www.test.com:8192/')->getPort());
26
- $this->assertEquals(null, Url::fromString('foo://www.test.com/')->getPort());
27
- }
28
-
29
- public function testRemovesDefaultPortWhenSettingScheme()
30
- {
31
- $url = Url::fromString('http://www.test.com/');
32
- $url->setPort(80);
33
- $url->setScheme('https');
34
- $this->assertEquals(443, $url->getPort());
35
- }
36
-
37
- public function testCloneCreatesNewInternalObjects()
38
- {
39
- $u1 = Url::fromString('http://www.test.com/');
40
- $u2 = clone $u1;
41
- $this->assertNotSame($u1->getQuery(), $u2->getQuery());
42
- }
43
-
44
- public function testValidatesUrlPartsInFactory()
45
- {
46
- $url = Url::fromString('/index.php');
47
- $this->assertEquals('/index.php', (string) $url);
48
- $this->assertFalse($url->isAbsolute());
49
-
50
- $url = 'http://michael:test@test.com:80/path/123?q=abc#test';
51
- $u = Url::fromString($url);
52
- $this->assertEquals('http://michael:test@test.com/path/123?q=abc#test', (string) $u);
53
- $this->assertTrue($u->isAbsolute());
54
- }
55
-
56
- public function testAllowsFalsyUrlParts()
57
- {
58
- $url = Url::fromString('http://a:50/0?0#0');
59
- $this->assertSame('a', $url->getHost());
60
- $this->assertEquals(50, $url->getPort());
61
- $this->assertSame('/0', $url->getPath());
62
- $this->assertEquals('0', (string) $url->getQuery());
63
- $this->assertSame('0', $url->getFragment());
64
- $this->assertEquals('http://a:50/0?0#0', (string) $url);
65
-
66
- $url = Url::fromString('');
67
- $this->assertSame('', (string) $url);
68
-
69
- $url = Url::fromString('0');
70
- $this->assertSame('0', (string) $url);
71
- }
72
-
73
- public function testBuildsRelativeUrlsWithFalsyParts()
74
- {
75
- $url = Url::buildUrl(['path' => '/0']);
76
- $this->assertSame('/0', $url);
77
-
78
- $url = Url::buildUrl(['path' => '0']);
79
- $this->assertSame('0', $url);
80
-
81
- $url = Url::buildUrl(['host' => '', 'path' => '0']);
82
- $this->assertSame('0', $url);
83
- }
84
-
85
- public function testUrlStoresParts()
86
- {
87
- $url = Url::fromString('http://test:pass@www.test.com:8081/path/path2/?a=1&b=2#fragment');
88
- $this->assertEquals('http', $url->getScheme());
89
- $this->assertEquals('test', $url->getUsername());
90
- $this->assertEquals('pass', $url->getPassword());
91
- $this->assertEquals('www.test.com', $url->getHost());
92
- $this->assertEquals(8081, $url->getPort());
93
- $this->assertEquals('/path/path2/', $url->getPath());
94
- $this->assertEquals('fragment', $url->getFragment());
95
- $this->assertEquals('a=1&b=2', (string) $url->getQuery());
96
-
97
- $this->assertEquals(array(
98
- 'fragment' => 'fragment',
99
- 'host' => 'www.test.com',
100
- 'pass' => 'pass',
101
- 'path' => '/path/path2/',
102
- 'port' => 8081,
103
- 'query' => 'a=1&b=2',
104
- 'scheme' => 'http',
105
- 'user' => 'test'
106
- ), $url->getParts());
107
- }
108
-
109
- public function testHandlesPathsCorrectly()
110
- {
111
- $url = Url::fromString('http://www.test.com');
112
- $this->assertEquals('', $url->getPath());
113
- $url->setPath('test');
114
- $this->assertEquals('test', $url->getPath());
115
-
116
- $url->setPath('/test/123/abc');
117
- $this->assertEquals(array('', 'test', '123', 'abc'), $url->getPathSegments());
118
-
119
- $parts = parse_url('http://www.test.com/test');
120
- $parts['path'] = '';
121
- $this->assertEquals('http://www.test.com', Url::buildUrl($parts));
122
- $parts['path'] = 'test';
123
- $this->assertEquals('http://www.test.com/test', Url::buildUrl($parts));
124
- }
125
-
126
- public function testAddsQueryIfPresent()
127
- {
128
- $this->assertEquals('?foo=bar', Url::buildUrl(array(
129
- 'query' => 'foo=bar'
130
- )));
131
- }
132
-
133
- public function testAddsToPath()
134
- {
135
- // Does nothing here
136
- $url = Url::fromString('http://e.com/base?a=1');
137
- $url->addPath(false);
138
- $this->assertEquals('http://e.com/base?a=1', $url);
139
- $url = Url::fromString('http://e.com/base?a=1');
140
- $url->addPath('');
141
- $this->assertEquals('http://e.com/base?a=1', $url);
142
- $url = Url::fromString('http://e.com/base?a=1');
143
- $url->addPath('/');
144
- $this->assertEquals('http://e.com/base?a=1', $url);
145
- $url = Url::fromString('http://e.com/base');
146
- $url->addPath('0');
147
- $this->assertEquals('http://e.com/base/0', $url);
148
-
149
- $url = Url::fromString('http://e.com/base?a=1');
150
- $url->addPath('relative');
151
- $this->assertEquals('http://e.com/base/relative?a=1', $url);
152
- $url = Url::fromString('http://e.com/base?a=1');
153
- $url->addPath('/relative');
154
- $this->assertEquals('http://e.com/base/relative?a=1', $url);
155
- }
156
-
157
- /**
158
- * URL combination data provider
159
- *
160
- * @return array
161
- */
162
- public function urlCombineDataProvider()
163
- {
164
- return [
165
- // Specific test cases
166
- ['http://www.example.com/', 'http://www.example.com/', 'http://www.example.com/'],
167
- ['http://www.example.com/path', '/absolute', 'http://www.example.com/absolute'],
168
- ['http://www.example.com/path', '/absolute?q=2', 'http://www.example.com/absolute?q=2'],
169
- ['http://www.example.com/', '?q=1', 'http://www.example.com/?q=1'],
170
- ['http://www.example.com/path', 'http://test.com', 'http://test.com'],
171
- ['http://www.example.com:8080/path', 'http://test.com', 'http://test.com'],
172
- ['http://www.example.com:8080/path', '?q=2#abc', 'http://www.example.com:8080/path?q=2#abc'],
173
- ['http://www.example.com/path', 'http://u:a@www.example.com/', 'http://u:a@www.example.com/'],
174
- ['/path?q=2', 'http://www.test.com/', 'http://www.test.com/path?q=2'],
175
- ['http://api.flickr.com/services/', 'http://www.flickr.com/services/oauth/access_token', 'http://www.flickr.com/services/oauth/access_token'],
176
- ['https://www.example.com/path', '//foo.com/abc', 'https://foo.com/abc'],
177
- ['https://www.example.com/0/', 'relative/foo', 'https://www.example.com/0/relative/foo'],
178
- ['', '0', '0'],
179
- // RFC 3986 test cases
180
- [self::RFC3986_BASE, 'g:h', 'g:h'],
181
- [self::RFC3986_BASE, 'g', 'http://a/b/c/g'],
182
- [self::RFC3986_BASE, './g', 'http://a/b/c/g'],
183
- [self::RFC3986_BASE, 'g/', 'http://a/b/c/g/'],
184
- [self::RFC3986_BASE, '/g', 'http://a/g'],
185
- [self::RFC3986_BASE, '//g', 'http://g'],
186
- [self::RFC3986_BASE, '?y', 'http://a/b/c/d;p?y'],
187
- [self::RFC3986_BASE, 'g?y', 'http://a/b/c/g?y'],
188
- [self::RFC3986_BASE, '#s', 'http://a/b/c/d;p?q#s'],
189
- [self::RFC3986_BASE, 'g#s', 'http://a/b/c/g#s'],
190
- [self::RFC3986_BASE, 'g?y#s', 'http://a/b/c/g?y#s'],
191
- [self::RFC3986_BASE, ';x', 'http://a/b/c/;x'],
192
- [self::RFC3986_BASE, 'g;x', 'http://a/b/c/g;x'],
193
- [self::RFC3986_BASE, 'g;x?y#s', 'http://a/b/c/g;x?y#s'],
194
- [self::RFC3986_BASE, '', self::RFC3986_BASE],
195
- [self::RFC3986_BASE, '.', 'http://a/b/c/'],
196
- [self::RFC3986_BASE, './', 'http://a/b/c/'],
197
- [self::RFC3986_BASE, '..', 'http://a/b/'],
198
- [self::RFC3986_BASE, '../', 'http://a/b/'],
199
- [self::RFC3986_BASE, '../g', 'http://a/b/g'],
200
- [self::RFC3986_BASE, '../..', 'http://a/'],
201
- [self::RFC3986_BASE, '../../', 'http://a/'],
202
- [self::RFC3986_BASE, '../../g', 'http://a/g'],
203
- [self::RFC3986_BASE, '../../../g', 'http://a/g'],
204
- [self::RFC3986_BASE, '../../../../g', 'http://a/g'],
205
- [self::RFC3986_BASE, '/./g', 'http://a/g'],
206
- [self::RFC3986_BASE, '/../g', 'http://a/g'],
207
- [self::RFC3986_BASE, 'g.', 'http://a/b/c/g.'],
208
- [self::RFC3986_BASE, '.g', 'http://a/b/c/.g'],
209
- [self::RFC3986_BASE, 'g..', 'http://a/b/c/g..'],
210
- [self::RFC3986_BASE, '..g', 'http://a/b/c/..g'],
211
- [self::RFC3986_BASE, './../g', 'http://a/b/g'],
212
- [self::RFC3986_BASE, 'foo////g', 'http://a/b/c/foo////g'],
213
- [self::RFC3986_BASE, './g/.', 'http://a/b/c/g/'],
214
- [self::RFC3986_BASE, 'g/./h', 'http://a/b/c/g/h'],
215
- [self::RFC3986_BASE, 'g/../h', 'http://a/b/c/h'],
216
- [self::RFC3986_BASE, 'g;x=1/./y', 'http://a/b/c/g;x=1/y'],
217
- [self::RFC3986_BASE, 'g;x=1/../y', 'http://a/b/c/y'],
218
- [self::RFC3986_BASE, 'http:g', 'http:g'],
219
- ];
220
- }
221
-
222
- /**
223
- * @dataProvider urlCombineDataProvider
224
- */
225
- public function testCombinesUrls($a, $b, $c)
226
- {
227
- $this->assertEquals($c, (string) Url::fromString($a)->combine($b));
228
- }
229
-
230
- public function testHasGettersAndSetters()
231
- {
232
- $url = Url::fromString('http://www.test.com/');
233
- $url->setHost('example.com');
234
- $this->assertEquals('example.com', $url->getHost());
235
- $url->setPort(8080);
236
- $this->assertEquals('8080', $url->getPort());
237
- $url->setPath('/foo/bar');
238
- $this->assertEquals('/foo/bar', $url->getPath());
239
- $url->setPassword('a');
240
- $this->assertEquals('a', $url->getPassword());
241
- $url->setUsername('b');
242
- $this->assertEquals('b', $url->getUsername());
243
- $url->setFragment('abc');
244
- $this->assertEquals('abc', $url->getFragment());
245
- $url->setScheme('https');
246
- $this->assertEquals('https', $url->getScheme());
247
- $url->setQuery('a=123');
248
- $this->assertEquals('a=123', (string) $url->getQuery());
249
- $this->assertEquals(
250
- 'https://b:a@example.com:8080/foo/bar?a=123#abc',
251
- (string) $url
252
- );
253
- $url->setQuery(new Query(['b' => 'boo']));
254
- $this->assertEquals('b=boo', $url->getQuery());
255
- $this->assertEquals(
256
- 'https://b:a@example.com:8080/foo/bar?b=boo#abc',
257
- (string) $url
258
- );
259
-
260
- $url->setQuery('a%20=bar!', true);
261
- $this->assertEquals(
262
- 'https://b:a@example.com:8080/foo/bar?a%20=bar!#abc',
263
- (string) $url
264
- );
265
- }
266
-
267
- public function testSetQueryAcceptsArray()
268
- {
269
- $url = Url::fromString('http://www.test.com');
270
- $url->setQuery(array('a' => 'b'));
271
- $this->assertEquals('http://www.test.com?a=b', (string) $url);
272
- }
273
-
274
- /**
275
- * @expectedException \InvalidArgumentException
276
- */
277
- public function testQueryMustBeValid()
278
- {
279
- $url = Url::fromString('http://www.test.com');
280
- $url->setQuery(false);
281
- }
282
-
283
- public function testDefersParsingAndEncodingQueryUntilNecessary()
284
- {
285
- $url = Url::fromString('http://www.test.com');
286
- // Note that invalid characters are encoded.
287
- $url->setQuery('foo#bar/', true);
288
- $this->assertEquals('http://www.test.com?foo%23bar/', (string) $url);
289
- $this->assertInternalType('string', $this->readAttribute($url, 'query'));
290
- $this->assertEquals('foo%23bar%2F', (string) $url->getQuery());
291
- $this->assertInstanceOf('GuzzleHttp\Query', $this->readAttribute($url, 'query'));
292
- }
293
-
294
- public function urlProvider()
295
- {
296
- return array(
297
- array('/foo/..', '/'),
298
- array('//foo//..', '//foo/'),
299
- array('/foo//', '/foo//'),
300
- array('/foo/../..', '/'),
301
- array('/foo/../.', '/'),
302
- array('/./foo/..', '/'),
303
- array('/./foo', '/foo'),
304
- array('/./foo/', '/foo/'),
305
- array('*', '*'),
306
- array('/foo', '/foo'),
307
- array('/abc/123/../foo/', '/abc/foo/'),
308
- array('/a/b/c/./../../g', '/a/g'),
309
- array('/b/c/./../../g', '/g'),
310
- array('/b/c/./../../g', '/g'),
311
- array('/c/./../../g', '/g'),
312
- array('/./../../g', '/g'),
313
- array('foo', 'foo'),
314
- );
315
- }
316
-
317
- /**
318
- * @dataProvider urlProvider
319
- */
320
- public function testRemoveDotSegments($path, $result)
321
- {
322
- $url = Url::fromString('http://www.example.com');
323
- $url->setPath($path);
324
- $url->removeDotSegments();
325
- $this->assertEquals($result, $url->getPath());
326
- }
327
-
328
- public function testSettingHostWithPortModifiesPort()
329
- {
330
- $url = Url::fromString('http://www.example.com');
331
- $url->setHost('foo:8983');
332
- $this->assertEquals('foo', $url->getHost());
333
- $this->assertEquals(8983, $url->getPort());
334
- }
335
-
336
- /**
337
- * @expectedException \InvalidArgumentException
338
- */
339
- public function testValidatesUrlCanBeParsed()
340
- {
341
- Url::fromString('foo:////');
342
- }
343
-
344
- public function testConvertsSpecialCharsInPathWhenCastingToString()
345
- {
346
- $url = Url::fromString('http://foo.com/baz bar?a=b');
347
- $url->addPath('?');
348
- $this->assertEquals('http://foo.com/baz%20bar/%3F?a=b', (string) $url);
349
- }
350
-
351
- public function testCorrectlyEncodesPathWithoutDoubleEncoding()
352
- {
353
- $url = Url::fromString('http://foo.com/baz%20 bar:boo/baz!');
354
- $this->assertEquals('/baz%20%20bar:boo/baz!', $url->getPath());
355
- }
356
-
357
- public function testLowercaseScheme()
358
- {
359
- $url = Url::fromString('HTTP://foo.com/');
360
- $this->assertEquals('http', $url->getScheme());
361
- $url->setScheme('HTTPS');
362
- $this->assertEquals('https', $url->getScheme());
363
- }
364
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/UtilsTest.php DELETED
@@ -1,40 +0,0 @@
1
- <?php
2
- namespace GuzzleHttp\Tests;
3
-
4
- use GuzzleHttp\Utils;
5
-
6
- class UtilsTest extends \PHPUnit_Framework_TestCase
7
- {
8
- public function testExpandsTemplate()
9
- {
10
- $this->assertEquals(
11
- 'foo/123',
12
- Utils::uriTemplate('foo/{bar}', ['bar' => '123'])
13
- );
14
- }
15
-
16
- public function noBodyProvider()
17
- {
18
- return [['get'], ['head'], ['delete']];
19
- }
20
-
21
- public function testJsonDecodes()
22
- {
23
- $this->assertTrue(Utils::jsonDecode('true'));
24
- }
25
-
26
- /**
27
- * @expectedException \InvalidArgumentException
28
- * @expectedExceptionMessage Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, malformed JSON
29
- */
30
- public function testJsonDecodesWithErrorMessages()
31
- {
32
- Utils::jsonDecode('!narf!');
33
- }
34
-
35
- public function testProvidesDefaultUserAgent()
36
- {
37
- $ua = Utils::getDefaultUserAgent();
38
- $this->assertEquals(1, preg_match('#^Guzzle/.+ curl/.+ PHP/.+$#', $ua));
39
- }
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/bootstrap.php DELETED
@@ -1,11 +0,0 @@
1
- <?php
2
- require __DIR__ . '/../vendor/autoload.php';
3
- require __DIR__ . '/../vendor/guzzlehttp/ringphp/tests/Client/Server.php';
4
-
5
- use GuzzleHttp\Tests\Server;
6
-
7
- Server::start();
8
-
9
- register_shutdown_function(function () {
10
- Server::stop();
11
- });
 
 
 
 
 
 
 
 
 
 
 
vendor/constantcontact/guzzlehttp/guzzle/tests/perf.php DELETED
@@ -1,61 +0,0 @@
1
- <?php
2
- /*
3
- * Runs a performance test against the node.js server for both serial and
4
- * parallel requests. Requires PHP 5.5 or greater.
5
- *
6
- * # Basic usage
7
- * make perf
8
- * # With custom options
9
- * REQUESTS=100 PARALLEL=5000 make perf
10
- */
11
-
12
- require __DIR__ . '/bootstrap.php';
13
-
14
- use GuzzleHttp\Client;
15
- use GuzzleHttp\Tests\Server;
16
- use GuzzleHttp\Ring\Client\CurlMultiHandler;
17
- use GuzzleHttp\Pool;
18
-
19
- // Wait until the server is responding
20
- Server::wait();
21
-
22
- // Get custom make variables
23
- $total = isset($_SERVER['REQUESTS']) ? $_SERVER['REQUESTS'] : 1000;
24
- $parallel = isset($_SERVER['PARALLEL']) ? $_SERVER['PARALLEL'] : 100;
25
-
26
- $client = new Client(['base_url' => Server::$url]);
27
-
28
- $t = microtime(true);
29
- for ($i = 0; $i < $total; $i++) {
30
- $client->get('/guzzle-server/perf');
31
- }
32
- $totalTime = microtime(true) - $t;
33
- $perRequest = ($totalTime / $total) * 1000;
34
- printf("Serial: %f (%f ms / request) %d total\n",
35
- $totalTime, $perRequest, $total);
36
-
37
- // Create a generator used to yield batches of requests
38
- $reqs = function () use ($client, $total) {
39
- for ($i = 0; $i < $total; $i++) {
40
- yield $client->createRequest('GET', '/guzzle-server/perf');
41
- }
42
- };
43
-
44
- $t = microtime(true);
45
- Pool::send($client, $reqs(), ['parallel' => $parallel]);
46
- $totalTime = microtime(true) - $t;
47
- $perRequest = ($totalTime / $total) * 1000;
48
- printf("Batch: %f (%f ms / request) %d total with %d in parallel\n",
49
- $totalTime, $perRequest, $total, $parallel);
50
-
51
- $handler = new CurlMultiHandler(['max_handles' => $parallel]);
52
- $client = new Client(['handler' => $handler, 'base_url' => Server::$url]);
53
- $t = microtime(true);
54
- for ($i = 0; $i < $total; $i++) {
55
- $client->get('/guzzle-server/perf');
56
- }
57
- unset($client);
58
- $totalTime = microtime(true) - $t;
59
- $perRequest = ($totalTime / $total) * 1000;
60
- printf("Future: %f (%f ms / request) %d total\n",
61
- $totalTime, $perRequest, $total);