@@ -20,106 +20,120 @@ public function setUp()
2020
2121 public function testPing ()
2222 {
23- $ this ->expectRequestFlow ('get ' , '/_ping ' , $ this ->createResponse ('OK ' ), 'expectPlain ' );
23+ $ body = 'OK ' ;
24+ $ this ->expectRequestFlow ('get ' , '/_ping ' , $ this ->createResponse ($ body ), 'expectPlain ' );
2425
25- $ this ->client ->ping ();
26+ $ this ->expectPromiseResolveWith ( $ body , $ this -> client ->ping () );
2627 }
2728
2829 public function testContainerInspect ()
2930 {
30- $ this ->expectRequestFlow ('get ' , '/containers/123/json ' , $ this ->createResponse ('{} ' ), 'expectJson ' );
31+ $ json = array ();
32+ $ this ->expectRequestFlow ('get ' , '/containers/123/json ' , $ this ->createResponseJson ($ json ), 'expectJson ' );
3133
32- $ this ->client ->containerInspect (123 );
34+ $ this ->expectPromiseResolveWith ( $ json , $ this -> client ->containerInspect (123 ) );
3335 }
3436
3537 public function testContainerTop ()
3638 {
37- $ this ->expectRequestFlow ('get ' , '/containers/123/top ' , $ this ->createResponse ('{} ' ), 'expectJson ' );
39+ $ json = array ();
40+ $ this ->expectRequestFlow ('get ' , '/containers/123/top ' , $ this ->createResponseJson ($ json ), 'expectJson ' );
3841
39- $ this ->client ->containerTop (123 );
42+ $ this ->expectPromiseResolveWith ( $ json , $ this -> client ->containerTop (123 ) );
4043 }
4144
4245 public function testContainerWait ()
4346 {
44- $ this ->expectRequestFlow ('post ' , '/containers/123/wait ' , $ this ->createResponse ('{} ' ), 'expectJson ' );
47+ $ json = array ();
48+ $ this ->expectRequestFlow ('post ' , '/containers/123/wait ' , $ this ->createResponseJson ($ json ), 'expectJson ' );
4549
46- $ this ->client ->containerWait (123 );
50+ $ this ->expectPromiseResolveWith ( $ json , $ this -> client ->containerWait (123 ) );
4751 }
4852
4953 public function testContainerKill ()
5054 {
5155 $ this ->expectRequestFlow ('post ' , '/containers/123/kill?signal= ' , $ this ->createResponse (), 'expectEmpty ' );
5256
53- $ this ->client ->containerKill (123 );
57+ $ this ->expectPromiseResolveWith ( '' , $ this -> client ->containerKill (123 ) );
5458 }
5559
5660 public function testContainerKillSignalName ()
5761 {
5862 $ this ->expectRequestFlow ('post ' , '/containers/123/kill?signal=SIGKILL ' , $ this ->createResponse (), 'expectEmpty ' );
5963
60- $ this ->client ->containerKill (123 , 'SIGKILL ' );
64+ $ this ->expectPromiseResolveWith ( '' , $ this -> client ->containerKill (123 , 'SIGKILL ' ) );
6165 }
6266
6367 public function testContainerKillSignalNumber ()
6468 {
6569 $ this ->expectRequestFlow ('post ' , '/containers/123/kill?signal=9 ' , $ this ->createResponse (), 'expectEmpty ' );
6670
67- $ this ->client ->containerKill (123 , 9 );
71+ $ this ->expectPromiseResolveWith ( '' , $ this -> client ->containerKill (123 , 9 ) );
6872 }
6973
7074 public function testContainerStop ()
7175 {
7276 $ this ->expectRequestFlow ('post ' , '/containers/123/stop?t=10 ' , $ this ->createResponse (), 'expectEmpty ' );
7377
74- $ this ->client ->containerStop (123 , 10 );
78+ $ this ->expectPromiseResolveWith ( '' , $ this -> client ->containerStop (123 , 10 ) );
7579 }
7680
7781 public function testContainerRestart ()
7882 {
7983 $ this ->expectRequestFlow ('post ' , '/containers/123/restart?t=10 ' , $ this ->createResponse (), 'expectEmpty ' );
8084
81- $ this ->client ->containerRestart (123 , 10 );
85+ $ this ->expectPromiseResolveWith ( '' , $ this -> client ->containerRestart (123 , 10 ) );
8286 }
8387
8488 public function testContainerPause ()
8589 {
8690 $ this ->expectRequestFlow ('post ' , '/containers/123/pause ' , $ this ->createResponse (), 'expectEmpty ' );
8791
88- $ this ->client ->containerPause (123 );
92+ $ this ->expectPromiseResolveWith ( '' , $ this -> client ->containerPause (123 ) );
8993 }
9094
9195 public function testContainerUnpause ()
9296 {
9397 $ this ->expectRequestFlow ('post ' , '/containers/123/unpause ' , $ this ->createResponse (), 'expectEmpty ' );
9498
95- $ this ->client ->containerUnpause (123 );
99+ $ this ->expectPromiseResolveWith ( '' , $ this -> client ->containerUnpause (123 ) );
96100 }
97101
98102 public function testContainerDelete ()
99103 {
100104 $ this ->expectRequestFlow ('delete ' , '/containers/123?v=0&force=0 ' , $ this ->createResponse (), 'expectEmpty ' );
101105
102- $ this ->client ->containerDelete (123 , false , false );
106+ $ this ->expectPromiseResolveWith ( '' , $ this -> client ->containerDelete (123 , false , false ) );
103107 }
104108
105109 public function testContainerResize ()
106110 {
107111 $ this ->expectRequestFlow ('get ' , '/containers/123/resize?w=800&h=600 ' , $ this ->createResponse (), 'expectEmpty ' );
108112
109- $ this ->client ->containerResize (123 , 800 , 600 );
113+ $ this ->expectPromiseResolveWith ( '' , $ this -> client ->containerResize (123 , 800 , 600 ) );
110114 }
111115
112116 private function expectRequestFlow ($ method , $ url , Response $ response , $ parser )
113117 {
118+ $ return = (string )$ response ->getBody ();
119+ if ($ parser === 'expectJson ' ) {
120+ $ return = json_decode ($ return , true );
121+ }
122+
114123 $ this ->browser ->expects ($ this ->once ())->method ($ method )->with ($ this ->equalTo ($ url ))->will ($ this ->returnPromise ($ response ));
115- $ this ->parser ->expects ($ this ->once ())->method ($ parser )->with ($ this ->equalTo ($ response ));
124+ $ this ->parser ->expects ($ this ->once ())->method ($ parser )->with ($ this ->equalTo ($ response ))-> will ( $ this -> returnValue ( $ return )) ;
116125 }
117126
118127 private function createResponse ($ body = '' )
119128 {
120129 return new Response ('HTTP/1.0 ' , 200 , 'OK ' , null , new Body ($ body ));
121130 }
122131
132+ private function createResponseJson ($ json )
133+ {
134+ return $ this ->createResponse (json_encode ($ json ));
135+ }
136+
123137 private function returnPromise ($ for )
124138 {
125139 $ deferred = new Deferred ();
0 commit comments