HttpTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Test\Unit;
  3. require_once dirname(__DIR__) . '/Setup.php';
  4. use Test\Setup;
  5. use Braintree;
  6. class HttpTest extends Setup
  7. {
  8. public function testMalformedNoSsl()
  9. {
  10. try {
  11. Braintree\Configuration::environment('development');
  12. $this->setExpectedException('Braintree\Exception\Connection', null, 3);
  13. $http = new Braintree\Http(Braintree\Configuration::$global);
  14. $http->_doUrlRequest('get', '/a_malformed_url');
  15. } catch (Braintree\Exception $e) {
  16. throw $e;
  17. }
  18. }
  19. public function testMalformedUrlUsingSsl()
  20. {
  21. try {
  22. Braintree\Configuration::environment('sandbox');
  23. $this->setExpectedException('Braintree\Exception\SSLCertificate', null, 3);
  24. $http = new Braintree\Http(Braintree\Configuration::$global);
  25. $http->_doUrlRequest('get', '/a_malformed_url_using_ssl');
  26. } catch (Braintree\Exception $e) {
  27. Braintree\Configuration::environment('development');
  28. throw $e;
  29. }
  30. Braintree\Configuration::environment('development');
  31. }
  32. public function testSSLVersionError()
  33. {
  34. try {
  35. Braintree\Configuration::environment('sandbox');
  36. Braintree\Configuration::sslVersion(3);
  37. $this->setExpectedException('Braintree\Exception\SSLCertificate', null, 35);
  38. $http = new Braintree\Http(Braintree\Configuration::$global);
  39. $http->get('/');
  40. } catch (Braintree\Exception $e) {
  41. Braintree\Configuration::environment('development');
  42. Braintree\Configuration::sslVersion(null);
  43. throw $e;
  44. }
  45. Braintree\Configuration::environment('development');
  46. Braintree\Configuration::sslVersion(null);
  47. }
  48. public function testGoodRequest()
  49. {
  50. Braintree\Configuration::environment('development');
  51. $http = new Braintree\Http(Braintree\Configuration::$global);
  52. $http->_doUrlRequest('get', 'http://example.com');
  53. }
  54. }