66use Http \Client \Exception \TransferException ;
77use Http \HttplugBundle \Collector \Formatter ;
88use Http \Message \Formatter as MessageFormatter ;
9+ use Http \Message \Formatter \CurlCommandFormatter ;
910use Psr \Http \Message \RequestInterface ;
1011use Psr \Http \Message \ResponseInterface ;
1112
@@ -16,6 +17,11 @@ class FormatterTest extends \PHPUnit_Framework_TestCase
1617 */
1718 private $ formatter ;
1819
20+ /**
21+ * @var MessageFormatter
22+ */
23+ private $ curlFormatter ;
24+
1925 /**
2026 * @var Formatter
2127 */
@@ -24,8 +30,9 @@ class FormatterTest extends \PHPUnit_Framework_TestCase
2430 public function setUp ()
2531 {
2632 $ this ->formatter = $ this ->getMockBuilder (MessageFormatter::class)->getMock ();
33+ $ this ->curlFormatter = $ this ->getMockBuilder (CurlCommandFormatter::class)->getMock ();
2734
28- $ this ->subject = new Formatter ($ this ->formatter );
35+ $ this ->subject = new Formatter ($ this ->formatter , $ this -> curlFormatter );
2936 }
3037
3138 public function testFormatRequest ()
@@ -88,4 +95,18 @@ public function testFormatException()
8895 $ exception = new \RuntimeException ('Unexpected error ' );
8996 $ this ->assertEquals ('Unexpected exception of type "RuntimeException": Unexpected error ' , $ this ->subject ->formatException ($ exception ));
9097 }
98+
99+ public function testFormatAsCurlCommand ()
100+ {
101+ $ request = $ this ->getMockBuilder (RequestInterface::class)->getMock ();
102+
103+ $ this ->curlFormatter
104+ ->expects ($ this ->once ())
105+ ->method ('formatRequest ' )
106+ ->with ($ this ->identicalTo ($ request ))
107+ ->willReturn ('curl -L http://example.com ' )
108+ ;
109+
110+ $ this ->assertEquals ('curl -L http://example.com ' , $ this ->subject ->formatAsCurlCommand ($ request ));
111+ }
91112}
0 commit comments