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