SocketTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\tests\integration\net;
  9. use lithium\net\socket\Curl;
  10. use lithium\net\http\Response;
  11. use lithium\net\socket\Stream;
  12. use lithium\net\socket\Context;
  13. class SocketTest extends \lithium\test\Integration {
  14. protected $_testConfig = array(
  15. 'persistent' => false,
  16. 'scheme' => 'http',
  17. 'host' => 'google.com',
  18. 'port' => 80,
  19. 'timeout' => 1,
  20. 'classes' => array(
  21. 'request' => 'lithium\net\http\Request',
  22. 'response' => 'lithium\net\http\Response'
  23. )
  24. );
  25. public function skip() {
  26. $message = "No internet connection established.";
  27. $this->skipIf(!$this->_hasNetwork($this->_testConfig), $message);
  28. }
  29. public function testContextAdapter() {
  30. $socket = new Context($this->_testConfig);
  31. $this->assertTrue($socket->open());
  32. $response = $socket->send();
  33. $this->assertTrue($response instanceof Response);
  34. $expected = 'google.com';
  35. $result = $response->host;
  36. $this->assertEqual($expected, $result);
  37. $result = $response->body();
  38. $this->assertPattern("/<title[^>]*>.*Google.*<\/title>/im", (string) $result);
  39. }
  40. public function testCurlAdapter() {
  41. $message = 'Your PHP installation was not compiled with curl support.';
  42. $this->skipIf(!function_exists('curl_init'), $message);
  43. $socket = new Curl($this->_testConfig);
  44. $this->assertTrue($socket->open());
  45. $response = $socket->send();
  46. $this->assertTrue($response instanceof Response);
  47. $expected = 'google.com';
  48. $result = $response->host;
  49. $this->assertEqual($expected, $result);
  50. $result = $response->body();
  51. $this->assertPattern("/<title[^>]*>.*<\/title>/im", (string) $result);
  52. }
  53. public function testStreamAdapter() {
  54. $socket = new Stream($this->_testConfig);
  55. $this->assertTrue($socket->open());
  56. $response = $socket->send();
  57. $this->assertTrue($response instanceof Response);
  58. $expected = 'google.com';
  59. $result = $response->host;
  60. $this->assertEqual($expected, $result);
  61. $result = $response->body();
  62. $this->assertPattern("/<title[^>]*>.*<\/title>/im", (string) $result);
  63. }
  64. }
  65. ?>