1111use Http \HttplugBundle \Collector \ProfilePlugin ;
1212use Http \HttplugBundle \Collector \Stack ;
1313use Http \Promise \FulfilledPromise ;
14+ use Http \Promise \Promise ;
15+ use Http \Promise \RejectedPromise ;
1416use Psr \Http \Message \RequestInterface ;
1517use Psr \Http \Message \ResponseInterface ;
1618
@@ -36,6 +38,11 @@ class ProfilePluginTest extends \PHPUnit_Framework_TestCase
3638 */
3739 private $ response ;
3840
41+ /**
42+ * @var Promise
43+ */
44+ private $ fulfilledPromise ;
45+
3946 /**
4047 * @var Stack
4148 */
@@ -46,6 +53,11 @@ class ProfilePluginTest extends \PHPUnit_Framework_TestCase
4653 */
4754 private $ exception ;
4855
56+ /**
57+ * @var Promise
58+ */
59+ private $ rejectedPromise ;
60+
4961 /**
5062 * @var Formatter
5163 */
@@ -62,8 +74,10 @@ public function setUp()
6274 $ this ->collector = $ this ->getMockBuilder (Collector::class)->disableOriginalConstructor ()->getMock ();
6375 $ this ->request = new Request ('GET ' , '/ ' );
6476 $ this ->response = new Response ();
77+ $ this ->fulfilledPromise = new FulfilledPromise ($ this ->response );
6578 $ this ->currentStack = new Stack ('default ' , 'FormattedRequest ' );
6679 $ this ->exception = new TransferException ();
80+ $ this ->rejectedPromise = new RejectedPromise ($ this ->exception );
6781 $ this ->formatter = $ this ->getMockBuilder (Formatter::class)->disableOriginalConstructor ()->getMock ();
6882
6983 $ this ->collector
@@ -74,9 +88,7 @@ public function setUp()
7488 $ this ->plugin
7589 ->method ('handleRequest ' )
7690 ->willReturnCallback (function ($ request , $ next , $ first ) {
77- $ next ($ request );
78-
79- return new FulfilledPromise ($ this ->response );
91+ return $ next ($ request );
8092 })
8193 ;
8294
@@ -115,13 +127,15 @@ public function testCallDecoratedPlugin()
115127 ;
116128
117129 $ this ->subject ->handleRequest ($ this ->request , function () {
130+ return $ this ->fulfilledPromise ;
118131 }, function () {
119132 });
120133 }
121134
122135 public function testProfileIsInitialized ()
123136 {
124137 $ this ->subject ->handleRequest ($ this ->request , function () {
138+ return $ this ->fulfilledPromise ;
125139 }, function () {
126140 });
127141
@@ -133,6 +147,7 @@ public function testProfileIsInitialized()
133147 public function testCollectRequestInformations ()
134148 {
135149 $ this ->subject ->handleRequest ($ this ->request , function () {
150+ return $ this ->fulfilledPromise ;
136151 }, function () {
137152 });
138153
@@ -143,6 +158,7 @@ public function testCollectRequestInformations()
143158 public function testOnFulfilled ()
144159 {
145160 $ promise = $ this ->subject ->handleRequest ($ this ->request , function () {
161+ return $ this ->fulfilledPromise ;
146162 }, function () {
147163 });
148164
@@ -156,7 +172,7 @@ public function testOnRejected()
156172 $ this ->setExpectedException (TransferException::class);
157173
158174 $ promise = $ this ->subject ->handleRequest ($ this ->request , function () {
159- throw new TransferException () ;
175+ return $ this -> rejectedPromise ;
160176 }, function () {
161177 });
162178
0 commit comments