@@ -13,4 +13,51 @@ public function testReject()
1313
1414 $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableOnce ());
1515 }
16+
17+ public function testRejectWithCustomMessage ()
18+ {
19+ $ cm = new ConnectionManagerReject ('Blocked ' );
20+ $ promise = $ cm ->connect ('www.google.com:80 ' );
21+
22+ $ text = null ;
23+ $ promise ->then ($ this ->expectCallableNever (), function (Exception $ e ) use (&$ text ) {
24+ $ text = $ e ->getMessage ();
25+ });
26+
27+ $ this ->assertEquals ('Blocked ' , $ text );
28+ }
29+
30+ public function testRejectThrowsCustomException ()
31+ {
32+ $ cm = new ConnectionManagerReject (function ($ uri ) {
33+ throw new RuntimeException ('Blocked ' . $ uri );
34+ });
35+
36+ $ promise = $ cm ->connect ('www.google.com:80 ' );
37+
38+ $ exception = null ;
39+ $ promise ->then ($ this ->expectCallableNever (), function ($ e ) use (&$ exception ) {
40+ $ exception = $ e ;
41+ });
42+
43+ $ this ->assertInstanceOf ('RuntimeException ' , $ exception );
44+ $ this ->assertEquals ('Blocked www.google.com:80 ' , $ exception ->getMessage ());
45+ }
46+
47+ public function testRejectReturnsCustomException ()
48+ {
49+ $ cm = new ConnectionManagerReject (function ($ uri ) {
50+ return new RuntimeException ('Blocked ' . $ uri );
51+ });
52+
53+ $ promise = $ cm ->connect ('www.google.com:80 ' );
54+
55+ $ exception = null ;
56+ $ promise ->then ($ this ->expectCallableNever (), function ($ e ) use (&$ exception ) {
57+ $ exception = $ e ;
58+ });
59+
60+ $ this ->assertInstanceOf ('RuntimeException ' , $ exception );
61+ $ this ->assertEquals ('Blocked www.google.com:80 ' , $ exception ->getMessage ());
62+ }
1663}
0 commit comments