1111use Http \HttplugBundle \Collector \Formatter ;
1212use Http \HttplugBundle \Collector \StackPlugin ;
1313use Http \Message \Formatter as MessageFormatter ;
14- use Http \Message \Formatter \SimpleFormatter ;
1514use Http \Promise \FulfilledPromise ;
1615use Http \Promise \RejectedPromise ;
1716use PHPUnit \Framework \Error \Warning ;
@@ -49,8 +48,8 @@ class StackPluginTest extends TestCase
4948 public function setUp (): void
5049 {
5150 $ this ->collector = new Collector ();
52- $ messageFormatter = $ this ->createMock (SimpleFormatter ::class);
53- $ formatter = new Formatter ($ messageFormatter , $ this ->createMock (MessageFormatter::class));
51+ $ messageFormatter = $ this ->createMock (MessageFormatter ::class);
52+ $ this -> formatter = new Formatter ($ messageFormatter , $ this ->createMock (MessageFormatter::class));
5453 $ this ->request = new Request ('GET ' , '/ ' );
5554 $ this ->response = new Response ();
5655 $ this ->exception = new HttpException ('' , $ this ->request , $ this ->response );
@@ -67,7 +66,7 @@ public function setUp(): void
6766 ->willReturn ('FormattedResponse ' )
6867 ;
6968
70- $ this ->subject = new StackPlugin ($ this ->collector , $ formatter , 'default ' );
69+ $ this ->subject = new StackPlugin ($ this ->collector , $ this -> formatter , 'default ' );
7170 }
7271
7372 public function testStackIsInitialized (): void
@@ -77,11 +76,9 @@ public function testStackIsInitialized(): void
7776 $ this ->subject ->handleRequest ($ this ->request , $ next , function (): void {
7877 });
7978
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 ());
79+ $ stack = $ this ->collector ->getActiveStack ();
80+ $ this ->assertEquals ('default ' , $ stack ->getClient ());
81+ $ this ->assertEquals ('FormattedRequest ' , $ stack ->getRequest ());
8582 }
8683
8784 public function testOnFulfilled (): void
@@ -92,10 +89,8 @@ public function testOnFulfilled(): void
9289 });
9390
9491 $ this ->assertEquals ($ this ->response , $ promise ->wait ());
95- $ this ->assertNull ($ this ->collector ->getActiveStack ());
96- $ stacks = $ this ->collector ->getStacks ();
97- $ this ->assertCount (1 , $ stacks );
98- $ this ->assertEquals ('FormattedResponse ' , $ stacks [0 ]->getResponse ());
92+ $ currentStack = $ this ->collector ->getActiveStack ();
93+ $ this ->assertEquals ('FormattedResponse ' , $ currentStack ->getResponse ());
9994 }
10095
10196 public function testOnRejected (): void
@@ -105,14 +100,10 @@ public function testOnRejected(): void
105100 $ promise = $ this ->subject ->handleRequest ($ this ->request , $ next , function (): void {
106101 });
107102
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 ();
103+ $ this ->assertEquals ($ this ->exception , $ promise ->wait ());
104+ $ currentStack = $ this ->collector ->getActiveStack ();
105+ $ this ->assertEquals ('FormattedResponse ' , $ currentStack ->getResponse ());
106+ $ this ->assertTrue ($ currentStack ->isFailed ());
116107 }
117108
118109 public function testOnException (): void
0 commit comments