@@ -190,7 +190,7 @@ public function testContainerLogsRejectsWhenInspectingContainerRejects()
190190 $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableOnce ());
191191 }
192192
193- public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerResolvesWithTtyAndContainerLogsArePending ()
193+ public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerResolvesWithTtyAndContainerLogsRequestIsPending ()
194194 {
195195 $ this ->browser ->expects ($ this ->once ())->method ('withOptions ' )->willReturnSelf ();
196196 $ this ->browser ->expects ($ this ->exactly (2 ))->method ('get ' )->withConsecutive (
@@ -211,7 +211,7 @@ public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerRes
211211 $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableNever ());
212212 }
213213
214- public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerResolvesWithoutTtyAndContainerLogsArePending ()
214+ public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerResolvesWithoutTtyAndContainerLogsRequestIsPending ()
215215 {
216216 $ this ->browser ->expects ($ this ->once ())->method ('withOptions ' )->willReturnSelf ();
217217 $ this ->browser ->expects ($ this ->exactly (2 ))->method ('get ' )->withConsecutive (
@@ -232,7 +232,7 @@ public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerRes
232232 $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableNever ());
233233 }
234234
235- public function testContainerLogsResolvesWhenInspectingContainerResolvesWithTtyAndContainerLogsResolves ()
235+ public function testContainerLogsResolvesWhenInspectingContainerResolvesWithTtyAndContainerLogsRequestResolves ()
236236 {
237237 $ this ->browser ->expects ($ this ->once ())->method ('withOptions ' )->willReturnSelf ();
238238 $ this ->browser ->expects ($ this ->exactly (2 ))->method ('get ' )->withConsecutive (
@@ -253,7 +253,7 @@ public function testContainerLogsResolvesWhenInspectingContainerResolvesWithTtyA
253253 $ promise ->then ($ this ->expectCallableOnceWith ('output ' ), $ this ->expectCallableNever ());
254254 }
255255
256- public function testContainerLogsStreamReturnStreamWhenInspectingContainerResolvesWithTtyAndContainerLogsResolves ()
256+ public function testContainerLogsStreamReturnStreamWhenInspectingContainerResolvesWithTtyAndContainerLogsRequestResolves ()
257257 {
258258 $ this ->browser ->expects ($ this ->once ())->method ('withOptions ' )->willReturnSelf ();
259259 $ this ->browser ->expects ($ this ->exactly (2 ))->method ('get ' )->withConsecutive (
@@ -379,6 +379,93 @@ public function testContainerUnpause()
379379 $ this ->expectPromiseResolveWith ('' , $ this ->client ->containerUnpause (123 ));
380380 }
381381
382+ public function testContainerAttachReturnsPendingPromiseWhenInspectingContainerIsPending ()
383+ {
384+ $ this ->browser ->expects ($ this ->once ())->method ('get ' )->with ('/containers/123/json ' )->willReturn (new \React \Promise \Promise (function () { }));
385+
386+ $ this ->streamingParser ->expects ($ this ->once ())->method ('bufferedStream ' )->with ($ this ->isInstanceOf ('React\Stream\ReadableStreamInterface ' ))->willReturn (new \React \Promise \Promise (function () { }));
387+
388+ $ promise = $ this ->client ->containerAttach ('123 ' , true , false );
389+
390+ $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableNever ());
391+ }
392+
393+ public function testContainerAttachRejectsWhenInspectingContainerRejects ()
394+ {
395+ $ this ->browser ->expects ($ this ->once ())->method ('get ' )->with ('/containers/123/json ' )->willReturn (\React \Promise \reject (new \RuntimeException ()));
396+
397+ $ this ->streamingParser ->expects ($ this ->once ())->method ('bufferedStream ' )->with ($ this ->isInstanceOf ('React\Stream\ReadableStreamInterface ' ))->willReturn (\React \Promise \reject (new \RuntimeException ()));
398+
399+ $ promise = $ this ->client ->containerAttach ('123 ' , true , false );
400+
401+ $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableOnce ());
402+ }
403+
404+ public function testContainerAttachReturnsPendingPromiseWhenInspectingContainerResolvesWithTtyAndContainerAttachIsPending ()
405+ {
406+ $ this ->browser ->expects ($ this ->once ())->method ('withOptions ' )->willReturnSelf ();
407+ $ this ->browser ->expects ($ this ->once ())->method ('get ' )->with ('/containers/123/json ' )->willReturn (\React \Promise \resolve (new Response (200 , array (), '{"Config":{"Tty":true}} ' )));
408+ $ this ->browser ->expects ($ this ->once ())->method ('post ' )->with ('/containers/123/attach?logs=1&stdout=1&stderr=1 ' )->willReturn (new \React \Promise \Promise (function () { }));
409+
410+ $ this ->parser ->expects ($ this ->once ())->method ('expectJson ' )->willReturn (array ('Config ' => array ('Tty ' => true )));
411+ $ this ->streamingParser ->expects ($ this ->once ())->method ('bufferedStream ' )->with ($ this ->isInstanceOf ('React\Stream\ReadableStreamInterface ' ))->willReturn (new \React \Promise \Promise (function () { }));
412+ $ this ->streamingParser ->expects ($ this ->once ())->method ('parsePlainStream ' )->willReturn ($ this ->getMockBuilder ('React\Stream\ReadableStreamInterface ' )->getMock ());
413+ $ this ->streamingParser ->expects ($ this ->never ())->method ('demultiplexStream ' );
414+
415+ $ promise = $ this ->client ->containerAttach ('123 ' , true , false );
416+
417+ $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableNever ());
418+ }
419+
420+ public function testContainerAttachReturnsPendingPromiseWhenInspectingContainerResolvesWithoutTtyAndContainerAttachRequestIsPending ()
421+ {
422+ $ this ->browser ->expects ($ this ->once ())->method ('withOptions ' )->willReturnSelf ();
423+ $ this ->browser ->expects ($ this ->once ())->method ('get ' )->with ('/containers/123/json ' )->willReturn (\React \Promise \resolve (new Response (200 , array (), '{"Config":{"Tty":false}} ' )));
424+ $ this ->browser ->expects ($ this ->once ())->method ('post ' )->with ('/containers/123/attach?logs=1&stdout=1&stderr=1 ' )->willReturn (new \React \Promise \Promise (function () { }));
425+
426+ $ this ->parser ->expects ($ this ->once ())->method ('expectJson ' )->willReturn (array ('Config ' => array ('Tty ' => false )));
427+ $ this ->streamingParser ->expects ($ this ->once ())->method ('bufferedStream ' )->with ($ this ->isInstanceOf ('React\Stream\ReadableStreamInterface ' ))->willReturn (new \React \Promise \Promise (function () { }));
428+ $ this ->streamingParser ->expects ($ this ->once ())->method ('parsePlainStream ' )->willReturn ($ this ->getMockBuilder ('React\Stream\ReadableStreamInterface ' )->getMock ());
429+ $ this ->streamingParser ->expects ($ this ->once ())->method ('demultiplexStream ' )->willReturn ($ this ->getMockBuilder ('React\Stream\ReadableStreamInterface ' )->getMock ());
430+
431+ $ promise = $ this ->client ->containerAttach ('123 ' , true , false );
432+
433+ $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableNever ());
434+ }
435+
436+ public function testContainerAttachResolvesWhenInspectingContainerResolvesWithTtyAndContainerAttachResolvesAndContainerAttachRequestResolves ()
437+ {
438+ $ this ->browser ->expects ($ this ->once ())->method ('withOptions ' )->willReturnSelf ();
439+ $ this ->browser ->expects ($ this ->once ())->method ('get ' )->with ('/containers/123/json ' )->willReturn (\React \Promise \resolve (new Response (200 , array (), '{"Config":{"Tty":true}} ' )));
440+ $ this ->browser ->expects ($ this ->once ())->method ('post ' )->with ('/containers/123/attach?logs=1&stdout=1&stderr=1 ' )->willReturn (\React \Promise \resolve (new Response (200 , array (), '' )));
441+
442+ $ this ->parser ->expects ($ this ->once ())->method ('expectJson ' )->willReturn (array ('Config ' => array ('Tty ' => true )));
443+ $ this ->streamingParser ->expects ($ this ->once ())->method ('bufferedStream ' )->with ($ this ->isInstanceOf ('React\Stream\ReadableStreamInterface ' ))->willReturn (\React \Promise \resolve ('output ' ));
444+ $ this ->streamingParser ->expects ($ this ->once ())->method ('parsePlainStream ' )->willReturn ($ this ->getMockBuilder ('React\Stream\ReadableStreamInterface ' )->getMock ());
445+ $ this ->streamingParser ->expects ($ this ->never ())->method ('demultiplexStream ' );
446+
447+ $ promise = $ this ->client ->containerAttach ('123 ' , true , false );
448+
449+ $ promise ->then ($ this ->expectCallableOnceWith ('output ' ), $ this ->expectCallableNever ());
450+ }
451+
452+ public function testContainerAttachStreamReturnStreamWhenInspectingContainerResolvesWithTtyAndContainerAttachRequestResolves ()
453+ {
454+ $ this ->browser ->expects ($ this ->once ())->method ('withOptions ' )->willReturnSelf ();
455+ $ this ->browser ->expects ($ this ->once ())->method ('get ' )->with ('/containers/123/json ' )->willReturn (\React \Promise \resolve (new Response (200 , array (), '{"Config":{"Tty":true}} ' )));
456+ $ this ->browser ->expects ($ this ->once ())->method ('post ' )->with ('/containers/123/attach?logs=1&stream=1&stdout=1&stderr=1 ' )->willReturn (\React \Promise \resolve (new Response (200 , array (), '' )));
457+
458+ $ response = new ThroughStream ();
459+ $ this ->parser ->expects ($ this ->once ())->method ('expectJson ' )->willReturn (array ('Config ' => array ('Tty ' => true )));
460+ $ this ->streamingParser ->expects ($ this ->once ())->method ('parsePlainStream ' )->willReturn ($ response );
461+ $ this ->streamingParser ->expects ($ this ->never ())->method ('demultiplexStream ' );
462+
463+ $ stream = $ this ->client ->containerAttachStream ('123 ' , true , true );
464+
465+ $ stream ->on ('data ' , $ this ->expectCallableOnceWith ('output ' ));
466+ $ response ->write ('output ' );
467+ }
468+
382469 public function testContainerRemove ()
383470 {
384471 $ this ->expectRequestFlow ('delete ' , '/containers/123 ' , $ this ->createResponse (), 'expectEmpty ' );
0 commit comments