Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ed002a9

Browse files
committedOct 13, 2017
Create connector test
1 parent 3654d5a commit ed002a9

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
 

‎test/ConnectorTest.php

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
3+
class ConnectorTest extends \PHPUnit\Framework\TestCase
4+
{
5+
public function testInstance()
6+
{
7+
$connector = new \SimpleSocket\Connector();
8+
$this->assertInstanceOf('\SimpleSocket\Connector', $connector);
9+
}
10+
11+
public function testConnectTcpWithUnknonHost()
12+
{
13+
try {
14+
$connector = new \SimpleSocket\Connector();
15+
$connector->connectTcp('0.0.0.0', 22, 100);
16+
$this->fail('Unable to occur error exception');
17+
} catch (\Exception $e) {
18+
$this->assertEquals(10, $e->getCode());
19+
}
20+
}
21+
22+
public function testAccessReadMethodWithoutConnection()
23+
{
24+
try {
25+
$connector = new \SimpleSocket\Connector();
26+
$connector->read();
27+
$this->fail('Unable to occur error exception');
28+
} catch (\Exception $e) {
29+
$this->assertEquals(20, $e->getCode());
30+
}
31+
}
32+
33+
public function testAccessWriteMethodWithoutConnection()
34+
{
35+
try {
36+
$connector = new \SimpleSocket\Connector();
37+
$connector->write('test');
38+
$this->fail('Unable to occur error exception');
39+
} catch (\Exception $e) {
40+
$this->assertEquals(20, $e->getCode());
41+
}
42+
}
43+
44+
public function testAccessCloseMethodWithoutConnection()
45+
{
46+
try {
47+
$connector = new \SimpleSocket\Connector();
48+
$connector->close();
49+
$this->fail('Unable to occur error exception');
50+
} catch (\Exception $e) {
51+
$this->assertEquals(20, $e->getCode());
52+
}
53+
}
54+
55+
public function testAccessThenMethodWithoutConnection()
56+
{
57+
try {
58+
$connector = new \SimpleSocket\Connector();
59+
$connector->then(function ($conn) {
60+
});
61+
$this->fail('Unable to occur error exception');
62+
} catch (\Exception $e) {
63+
$this->assertEquals(20, $e->getCode());
64+
}
65+
}
66+
67+
public function testAccessThenMethod()
68+
{
69+
try {
70+
$connector = new \SimpleSocket\Connector();
71+
$connector->connectTcp('google.com', 80, 100)->then(function ($conn) {
72+
$this->assertInstanceOf('\SimpleSocket\Connector', $conn);
73+
});
74+
} catch (\Exception $e) {
75+
$this->fail('Occur error exception');
76+
}
77+
}
78+
79+
public function testAccessWriteMethod()
80+
{
81+
try {
82+
$connector = new \SimpleSocket\Connector();
83+
$instance = $connector->connectTcp('google.com', 80, 100)->write("GET / HTTP/1.1\r\n\Host: google.com\r\n\r\n");
84+
$this->assertInstanceOf('\SimpleSocket\Connector', $instance);
85+
} catch (\Exception $e) {
86+
$this->fail('Occur error exception');
87+
}
88+
}
89+
90+
public function testAccessReadMethod()
91+
{
92+
try {
93+
$connector = new \SimpleSocket\Connector();
94+
$buf = $connector->connectTcp('google.com', 80, 100)->write("GET / HTTP/1.1\r\n\Host: google.com\r\n\r\n")->read(2048);
95+
$this->assertRegExp('/HTML/', (string) $buf);
96+
} catch (\Exception $e) {
97+
$this->fail('Occur error exception');
98+
}
99+
}
100+
101+
public function testAccessCloseMethod()
102+
{
103+
try {
104+
$connector = new \SimpleSocket\Connector();
105+
$instance = $connector->connectTcp('google.com', 80, 100)->close();
106+
$this->assertInstanceOf('\SimpleSocket\Connector', $instance);
107+
} catch (\Exception $e) {
108+
$this->fail('Occur error exception');
109+
}
110+
}
111+
}

0 commit comments

Comments
 (0)
Please sign in to comment.