11
11
use Http \HttplugBundle \Collector \ProfilePlugin ;
12
12
use Http \HttplugBundle \Collector \Stack ;
13
13
use Http \Promise \FulfilledPromise ;
14
+ use Http \Promise \Promise ;
15
+ use Http \Promise \RejectedPromise ;
14
16
use Psr \Http \Message \RequestInterface ;
15
17
use Psr \Http \Message \ResponseInterface ;
16
18
@@ -36,6 +38,11 @@ class ProfilePluginTest extends \PHPUnit_Framework_TestCase
36
38
*/
37
39
private $ response ;
38
40
41
+ /**
42
+ * @var Promise
43
+ */
44
+ private $ fulfilledPromise ;
45
+
39
46
/**
40
47
* @var Stack
41
48
*/
@@ -46,6 +53,11 @@ class ProfilePluginTest extends \PHPUnit_Framework_TestCase
46
53
*/
47
54
private $ exception ;
48
55
56
+ /**
57
+ * @var Promise
58
+ */
59
+ private $ rejectedPromise ;
60
+
49
61
/**
50
62
* @var Formatter
51
63
*/
@@ -62,8 +74,10 @@ public function setUp()
62
74
$ this ->collector = $ this ->getMockBuilder (Collector::class)->disableOriginalConstructor ()->getMock ();
63
75
$ this ->request = new Request ('GET ' , '/ ' );
64
76
$ this ->response = new Response ();
77
+ $ this ->fulfilledPromise = new FulfilledPromise ($ this ->response );
65
78
$ this ->currentStack = new Stack ('default ' , 'FormattedRequest ' );
66
79
$ this ->exception = new TransferException ();
80
+ $ this ->rejectedPromise = new RejectedPromise ($ this ->exception );
67
81
$ this ->formatter = $ this ->getMockBuilder (Formatter::class)->disableOriginalConstructor ()->getMock ();
68
82
69
83
$ this ->collector
@@ -74,9 +88,7 @@ public function setUp()
74
88
$ this ->plugin
75
89
->method ('handleRequest ' )
76
90
->willReturnCallback (function ($ request , $ next , $ first ) {
77
- $ next ($ request );
78
-
79
- return new FulfilledPromise ($ this ->response );
91
+ return $ next ($ request );
80
92
})
81
93
;
82
94
@@ -115,13 +127,15 @@ public function testCallDecoratedPlugin()
115
127
;
116
128
117
129
$ this ->subject ->handleRequest ($ this ->request , function () {
130
+ return $ this ->fulfilledPromise ;
118
131
}, function () {
119
132
});
120
133
}
121
134
122
135
public function testProfileIsInitialized ()
123
136
{
124
137
$ this ->subject ->handleRequest ($ this ->request , function () {
138
+ return $ this ->fulfilledPromise ;
125
139
}, function () {
126
140
});
127
141
@@ -133,6 +147,7 @@ public function testProfileIsInitialized()
133
147
public function testCollectRequestInformations ()
134
148
{
135
149
$ this ->subject ->handleRequest ($ this ->request , function () {
150
+ return $ this ->fulfilledPromise ;
136
151
}, function () {
137
152
});
138
153
@@ -143,6 +158,7 @@ public function testCollectRequestInformations()
143
158
public function testOnFulfilled ()
144
159
{
145
160
$ promise = $ this ->subject ->handleRequest ($ this ->request , function () {
161
+ return $ this ->fulfilledPromise ;
146
162
}, function () {
147
163
});
148
164
@@ -156,7 +172,7 @@ public function testOnRejected()
156
172
$ this ->setExpectedException (TransferException::class);
157
173
158
174
$ promise = $ this ->subject ->handleRequest ($ this ->request , function () {
159
- throw new TransferException () ;
175
+ return $ this -> rejectedPromise ;
160
176
}, function () {
161
177
});
162
178
0 commit comments