1111use Http \HttplugBundle \Collector \Formatter ;
1212use Http \HttplugBundle \Collector \StackPlugin ;
1313use Http \Message \Formatter as MessageFormatter ;
14+ use Http \Message \Formatter \SimpleFormatter ;
1415use Http \Promise \FulfilledPromise ;
1516use Http \Promise \RejectedPromise ;
1617use PHPUnit \Framework \Error \Warning ;
@@ -48,8 +49,8 @@ class StackPluginTest extends TestCase
4849 public function setUp (): void
4950 {
5051 $ this ->collector = new Collector ();
51- $ messageFormatter = $ this ->createMock (MessageFormatter ::class);
52- $ this -> formatter = new Formatter ($ messageFormatter , $ this ->createMock (MessageFormatter::class));
52+ $ messageFormatter = $ this ->createMock (SimpleFormatter ::class);
53+ $ formatter = new Formatter ($ messageFormatter , $ this ->createMock (MessageFormatter::class));
5354 $ this ->request = new Request ('GET ' , '/ ' );
5455 $ this ->response = new Response ();
5556 $ this ->exception = new HttpException ('' , $ this ->request , $ this ->response );
@@ -66,7 +67,7 @@ public function setUp(): void
6667 ->willReturn ('FormattedResponse ' )
6768 ;
6869
69- $ this ->subject = new StackPlugin ($ this ->collector , $ this -> formatter , 'default ' );
70+ $ this ->subject = new StackPlugin ($ this ->collector , $ formatter , 'default ' );
7071 }
7172
7273 public function testStackIsInitialized (): void
@@ -76,9 +77,11 @@ public function testStackIsInitialized(): void
7677 $ this ->subject ->handleRequest ($ this ->request , $ next , function (): void {
7778 });
7879
79- $ stack = $ this ->collector ->getActiveStack ();
80- $ this ->assertEquals ('default ' , $ stack ->getClient ());
81- $ this ->assertEquals ('FormattedRequest ' , $ stack ->getRequest ());
80+ $ this ->assertNull ($ this ->collector ->getActiveStack ());
81+ $ stacks = $ this ->collector ->getStacks ();
82+ $ this ->assertCount (1 , $ stacks );
83+ $ this ->assertEquals ('default ' , $ stacks [0 ]->getClient ());
84+ $ this ->assertEquals ('FormattedRequest ' , $ stacks [0 ]->getRequest ());
8285 }
8386
8487 public function testOnFulfilled (): void
@@ -89,8 +92,10 @@ public function testOnFulfilled(): void
8992 });
9093
9194 $ this ->assertEquals ($ this ->response , $ promise ->wait ());
92- $ currentStack = $ this ->collector ->getActiveStack ();
93- $ this ->assertEquals ('FormattedResponse ' , $ currentStack ->getResponse ());
95+ $ this ->assertNull ($ this ->collector ->getActiveStack ());
96+ $ stacks = $ this ->collector ->getStacks ();
97+ $ this ->assertCount (1 , $ stacks );
98+ $ this ->assertEquals ('FormattedResponse ' , $ stacks [0 ]->getResponse ());
9499 }
95100
96101 public function testOnRejected (): void
@@ -100,10 +105,14 @@ public function testOnRejected(): void
100105 $ promise = $ this ->subject ->handleRequest ($ this ->request , $ next , function (): void {
101106 });
102107
103- $ this ->assertEquals ($ this ->exception , $ promise ->wait ());
104- $ currentStack = $ this ->collector ->getActiveStack ();
105- $ this ->assertEquals ('FormattedResponse ' , $ currentStack ->getResponse ());
106- $ this ->assertTrue ($ currentStack ->isFailed ());
108+ $ this ->assertNull ($ this ->collector ->getActiveStack ());
109+ $ stacks = $ this ->collector ->getStacks ();
110+ $ this ->assertCount (1 , $ stacks );
111+ $ this ->assertEquals ('FormattedResponse ' , $ stacks [0 ]->getResponse ());
112+ $ this ->assertTrue ($ stacks [0 ]->isFailed ());
113+
114+ $ this ->expectException (\Exception::class);
115+ $ promise ->wait ();
107116 }
108117
109118 public function testOnException (): void
0 commit comments