1414use Http \Message \Formatter \CurlCommandFormatter ;
1515use Http \Message \Formatter \FullHttpMessageFormatter ;
1616use Http \Mock \Client ;
17+ use Psr \Http \Message \RequestInterface ;
1718use Symfony \Component \Cache \Adapter \ArrayAdapter ;
1819use Symfony \Component \Stopwatch \Stopwatch ;
1920
@@ -41,12 +42,10 @@ public function setUp()
4142 $ this ->stopwatch = new Stopwatch ();
4243 }
4344
44- public function testCachePluginProfiling ()
45+ public function testProfilingWithCachePlugin ()
4546 {
46- $ pool = new ArrayAdapter ();
47-
4847 $ client = $ this ->createClient ([
49- new Plugin \CachePlugin ($ pool , StreamFactoryDiscovery::find (), [
48+ new Plugin \CachePlugin (new ArrayAdapter () , StreamFactoryDiscovery::find (), [
5049 'respect_response_cache_directives ' => [],
5150 'default_ttl ' => 86400 ,
5251 ]),
@@ -63,6 +62,26 @@ public function testCachePluginProfiling()
6362 $ this ->assertEquals ('example.com ' , $ stack ->getRequestHost ());
6463 }
6564
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+
6685 private function createClient (array $ plugins , $ clientName = 'Acme ' , array $ clientOptions = [])
6786 {
6887 $ plugins = array_map (function (Plugin $ plugin ) {
@@ -78,3 +97,14 @@ private function createClient(array $plugins, $clientName = 'Acme', array $clien
7897 return $ client ;
7998 }
8099}
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