2
2
3
3
namespace Jaeger \Tests ;
4
4
5
+ use Jaeger \Tests \Logger \StackLogger ;
5
6
use Jaeger \ThriftUdpTransport ;
6
7
use PHPUnit \Framework \TestCase ;
7
8
use Thrift \Exception \TTransportException ;
@@ -13,43 +14,72 @@ class ThriftUdpTransportTest extends TestCase
13
14
*/
14
15
private $ transport ;
15
16
17
+ /**
18
+ * @var StackLogger
19
+ */
20
+ private $ logger ;
21
+
16
22
public function setUp (): void
17
23
{
18
- $ this ->transport = new ThriftUdpTransport ('127.0.0.1 ' , 12345 );
24
+ $ this ->logger = new StackLogger ();
25
+ $ this ->transport = new ThriftUdpTransport ('127.0.0.1 ' , 12345 , $ this ->logger );
19
26
}
20
27
21
28
public function testisOpenWhenOpen ()
22
29
{
30
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 0 );
23
31
$ this ->assertTrue ($ this ->transport ->isOpen ());
32
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 0 );
24
33
}
25
34
26
35
public function testisOpenWhenClosed ()
27
36
{
37
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 0 );
28
38
$ this ->transport ->close ();
29
39
$ this ->assertFalse ($ this ->transport ->isOpen ());
40
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 0 );
30
41
}
31
42
32
43
public function testClose ()
33
44
{
45
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 0 );
34
46
$ this ->transport ->close ();
35
47
36
- $ this ->expectException (TTransportException::class);
37
- $ this ->expectExceptionMessage ('transport is closed ' );
48
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 0 );
38
49
$ this ->transport ->write ('hello ' );
50
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 1 );
51
+ $ this ->assertEquals ($ this ->logger ->getLastMessage (), 'transport is closed ' );
52
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 0 );
53
+ }
54
+
55
+ public function testDoubleClose () {
56
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 0 );
57
+ $ this ->transport ->close ();
58
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 0 );
59
+ $ this ->transport ->close ();
60
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 1 );
61
+ $ this ->assertEquals (
62
+ $ this ->logger ->getLastMessage (),
63
+ "can't close empty socket "
64
+ );
39
65
}
40
66
41
67
public function testException () {
68
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 0 );
42
69
$ this ->transport ->open ();
70
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 0 );
43
71
44
- $ this ->expectException (TTransportException::class );
72
+ $ this ->transport -> write ( str_repeat ( " some string " , 10000 ) );
45
73
46
- $ msgRegEx = "/socket_write failed: \[code - \d+\] Message too long/ " ;
47
- if (method_exists ($ this , "expectExceptionMessageRegExp " )) {
48
- $ this ->expectExceptionMessageRegExp ($ msgRegEx );
74
+ $ this ->assertEquals ($ this ->logger ->getMessagesCount (), 1 );
75
+ $ msg = $ this ->logger ->getLastMessage ();
76
+ $ pattern = "/socket_write failed: \[code - \d+\] Message too long/ " ;
77
+
78
+ if (method_exists ($ this , "assertMatchesRegularExpression " )) {
79
+ $ this ->assertMatchesRegularExpression ($ pattern , $ msg );
49
80
} else {
50
- $ this ->expectExceptionMessageMatches ( $ msgRegEx );
81
+ $ this ->assertRegExp ( $ pattern , $ msg );
51
82
}
52
83
53
- $ this ->transport ->write (str_repeat ("some string " , 10000 ));
54
84
}
55
85
}
0 commit comments