11
11
use Http \HttplugBundle \Collector \Formatter ;
12
12
use Http \HttplugBundle \Collector \StackPlugin ;
13
13
use Http \Message \Formatter as MessageFormatter ;
14
+ use Http \Message \Formatter \SimpleFormatter ;
14
15
use Http \Promise \FulfilledPromise ;
15
16
use Http \Promise \RejectedPromise ;
16
17
use PHPUnit \Framework \Error \Warning ;
@@ -48,8 +49,8 @@ class StackPluginTest extends TestCase
48
49
public function setUp (): void
49
50
{
50
51
$ 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));
53
54
$ this ->request = new Request ('GET ' , '/ ' );
54
55
$ this ->response = new Response ();
55
56
$ this ->exception = new HttpException ('' , $ this ->request , $ this ->response );
@@ -66,7 +67,7 @@ public function setUp(): void
66
67
->willReturn ('FormattedResponse ' )
67
68
;
68
69
69
- $ this ->subject = new StackPlugin ($ this ->collector , $ this -> formatter , 'default ' );
70
+ $ this ->subject = new StackPlugin ($ this ->collector , $ formatter , 'default ' );
70
71
}
71
72
72
73
public function testStackIsInitialized (): void
@@ -76,9 +77,11 @@ public function testStackIsInitialized(): void
76
77
$ this ->subject ->handleRequest ($ this ->request , $ next , function (): void {
77
78
});
78
79
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 ());
82
85
}
83
86
84
87
public function testOnFulfilled (): void
@@ -89,8 +92,10 @@ public function testOnFulfilled(): void
89
92
});
90
93
91
94
$ 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 ());
94
99
}
95
100
96
101
public function testOnRejected (): void
@@ -100,10 +105,14 @@ public function testOnRejected(): void
100
105
$ promise = $ this ->subject ->handleRequest ($ this ->request , $ next , function (): void {
101
106
});
102
107
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 ();
107
116
}
108
117
109
118
public function testOnException (): void
0 commit comments