14
14
use Http \Message \Formatter \CurlCommandFormatter ;
15
15
use Http \Message \Formatter \FullHttpMessageFormatter ;
16
16
use Http \Mock \Client ;
17
+ use Psr \Http \Message \RequestInterface ;
17
18
use Symfony \Component \Cache \Adapter \ArrayAdapter ;
18
19
use Symfony \Component \Stopwatch \Stopwatch ;
19
20
@@ -41,12 +42,10 @@ public function setUp()
41
42
$ this ->stopwatch = new Stopwatch ();
42
43
}
43
44
44
- public function testCachePluginProfiling ()
45
+ public function testProfilingWithCachePlugin ()
45
46
{
46
- $ pool = new ArrayAdapter ();
47
-
48
47
$ client = $ this ->createClient ([
49
- new Plugin \CachePlugin ($ pool , StreamFactoryDiscovery::find (), [
48
+ new Plugin \CachePlugin (new ArrayAdapter () , StreamFactoryDiscovery::find (), [
50
49
'respect_response_cache_directives ' => [],
51
50
'default_ttl ' => 86400 ,
52
51
]),
@@ -63,6 +62,26 @@ public function testCachePluginProfiling()
63
62
$ this ->assertEquals ('example.com ' , $ stack ->getRequestHost ());
64
63
}
65
64
65
+ public function testProfilingWhenPluginThrowException ()
66
+ {
67
+ $ client = $ this ->createClient ([
68
+ new ExceptionThrowerPlugin (),
69
+ ]);
70
+
71
+ $ this ->setExpectedException (\Exception::class);
72
+
73
+ try {
74
+ $ client ->sendRequest (new Request ('GET ' , 'https://example.com ' ));
75
+ } finally {
76
+ $ this ->assertCount (1 , $ this ->collector ->getStacks ());
77
+ $ stack = $ this ->collector ->getStacks ()[0 ];
78
+ $ this ->assertEquals ('GET ' , $ stack ->getRequestMethod ());
79
+ $ this ->assertEquals ('https ' , $ stack ->getRequestScheme ());
80
+ $ this ->assertEquals ('/ ' , $ stack ->getRequestTarget ());
81
+ $ this ->assertEquals ('example.com ' , $ stack ->getRequestHost ());
82
+ }
83
+ }
84
+
66
85
private function createClient (array $ plugins , $ clientName = 'Acme ' , array $ clientOptions = [])
67
86
{
68
87
$ plugins = array_map (function (Plugin $ plugin ) {
@@ -78,3 +97,14 @@ private function createClient(array $plugins, $clientName = 'Acme', array $clien
78
97
return $ client ;
79
98
}
80
99
}
100
+
101
+ class ExceptionThrowerPlugin implements Plugin
102
+ {
103
+ /**
104
+ * {@inheritdoc}
105
+ */
106
+ public function handleRequest (RequestInterface $ request , callable $ next , callable $ first )
107
+ {
108
+ throw new \Exception ();
109
+ }
110
+ }
0 commit comments