88
99namespace LeanPHP \Behat \CodeCoverage \Driver ;
1010
11- use Guzzle \Http \Client ;
11+ use GuzzleHttp \Client ;
12+ use GuzzleHttp \Message \Response ;
1213use SebastianBergmann \CodeCoverage \Driver \Driver as DriverInterface ;
1314
1415/**
@@ -24,7 +25,7 @@ class RemoteXdebug implements DriverInterface
2425 private $ config ;
2526
2627 /**
27- * @var \Guzzle\Http \Client
28+ * @var GuzzleHttp \Client
2829 */
2930 private $ client ;
3031
@@ -52,7 +53,7 @@ class RemoteXdebug implements DriverInterface
5253 * ]
5354 *
5455 * @param array $config Configuration
55- * @param \Guzzle\Http \Client $client HTTP client
56+ * @param GuzzleHttp \Client $client HTTP client
5657 */
5758 public function __construct (array $ config , Client $ client )
5859 {
@@ -67,9 +68,7 @@ public function __construct(array $config, Client $client)
6768 */
6869 public function start ($ determineUnusedAndDead = true )
6970 {
70- $ request = $ this ->buildRequest ('create ' );
71-
72- $ response = $ request ->send ();
71+ $ response = $ this ->sendRequest ('create ' );
7372
7473 if ($ response ->getStatusCode () !== 200 ) {
7574 throw new \Exception ('remote driver start failed: ' . $ response ->getReasonPhrase ());
@@ -81,17 +80,13 @@ public function start($determineUnusedAndDead = true)
8180 */
8281 public function stop ()
8382 {
84- $ request = $ this ->buildRequest ('read ' );
85- $ request ->setHeader ('Accept ' , 'application/json ' );
86-
87- $ response = $ request ->send ();
83+ $ response = $ this ->sendRequest ('read ' , ['Accept ' => 'application/json ' ]);
8884
8985 if ($ response ->getStatusCode () !== 200 ) {
9086 throw new \Exception ('remote driver fetch failed: ' . $ response ->getReasonPhrase ());
9187 }
9288
93- $ request = $ this ->buildRequest ('delete ' );
94- $ request ->send ();
89+ $ response = $ this ->sendRequest ('delete ' );
9590
9691 return json_decode ($ response ->getBody (true ), true );
9792 }
@@ -100,23 +95,33 @@ public function stop()
10095 * Construct request
10196 *
10297 * @param string $endpoint
98+ * @param array $headers
10399 *
104- * @return \Guzzle\Http\ Message\Request
100+ * @return GuzzleHttp\ Message\Response
105101 */
106- private function buildRequest ($ endpoint )
102+ private function sendRequest ($ endpoint, $ headers = array () )
107103 {
108104 $ method = strtolower ($ this ->config [$ endpoint ]['method ' ]);
109105
110106 if (! in_array ($ method , array ('get ' , 'post ' , 'put ' , 'delete ' ))) {
111107 throw new \Exception ($ endpoint . ' method must be GET, POST, PUT, or DELETE ' );
112108 }
113109
114- $ request = $ this ->client ->$ method ($ this ->config [$ endpoint ]['path ' ]);
115-
116110 if (isset ($ this ->config ['auth ' ])) {
117- $ request ->setAuth ($ this ->config ['auth ' ]['user ' ], $ this ->config ['auth ' ]['password ' ]);
111+ $ response = $ this ->client ->$ method (
112+ $ this ->config [$ endpoint ]['path ' ], [
113+ 'auth ' => [$ this ->config ['auth ' ]['user ' ], $ this ->config ['auth ' ]['password ' ]],
114+ 'headers ' => $ headers ,
115+ ]
116+ );
117+ } else {
118+ $ response = $ this ->client ->$ method (
119+ $ this ->config [$ endpoint ]['path ' ], [
120+ 'headers ' => $ headers
121+ ]
122+ );
118123 }
119124
120- return $ request ;
125+ return $ response ;
121126 }
122127}
0 commit comments