@@ -419,4 +419,65 @@ public function testContainerList()
419419
420420 $ this ->loop ->run ();
421421 }
422+
423+ /**
424+ * @depends testImageInspectCheckIfBusyboxExists
425+ */
426+ public function testCreateConnectDisconnectAndRemoveNetwork ()
427+ {
428+ $ containerConfig = array (
429+ 'Image ' => 'busybox ' ,
430+ 'Cmd ' => array ('echo ' , 'test ' )
431+ );
432+ $ networkName = uniqid ('reactphp-docker ' );
433+
434+ $ promise = $ this ->client ->containerCreate ($ containerConfig );
435+ $ container = Block \await ($ promise , $ this ->loop );
436+
437+ $ promise = $ this ->client ->containerStart ($ container ['Id ' ]);
438+ $ ret = Block \await ($ promise , $ this ->loop );
439+
440+ $ start = microtime (true );
441+
442+ $ promise = $ this ->client ->networkCreate ($ networkName );
443+ $ network = Block \await ($ promise , $ this ->loop );
444+
445+ $ this ->assertNotNull ($ network ['Id ' ]);
446+ $ this ->assertEquals ('' , $ network ['Warning ' ]);
447+
448+ $ promise = $ this ->client ->networkConnect ($ network ['Id ' ], $ container ['Id ' ]);
449+ $ ret = Block \await ($ promise , $ this ->loop );
450+
451+ $ this ->assertEquals ('' , $ ret );
452+
453+ $ promise = $ this ->client ->networkDisconnect ($ network ['Id ' ], $ container ['Id ' ], false );
454+ $ ret = Block \await ($ promise , $ this ->loop );
455+
456+ $ this ->assertEquals ('' , $ ret );
457+
458+ $ promise = $ this ->client ->networkRemove ($ network ['Id ' ]);
459+ $ ret = Block \await ($ promise , $ this ->loop );
460+
461+ $ this ->assertEquals ('' , $ ret );
462+
463+ $ end = microtime (true );
464+
465+ $ promise = $ this ->client ->containerStop ($ container ['Id ' ]);
466+ $ ret = Block \await ($ promise , $ this ->loop );
467+
468+ $ promise = $ this ->client ->containerRemove ($ container ['Id ' ]);
469+ $ ret = Block \await ($ promise , $ this ->loop );
470+
471+ // get all events between starting and removing for this container
472+ $ promise = $ this ->client ->events ($ start , $ end , array ('network ' => array ($ network ['Id ' ])));
473+ $ ret = Block \await ($ promise , $ this ->loop );
474+
475+ // expects "create", "connect", "disconnect", "destroy" events
476+ //$this->assertEquals(4, count($ret));
477+ $ this ->assertEquals (3 , count ($ ret ));
478+ $ this ->assertEquals ('create ' , $ ret [0 ]['Action ' ]);
479+ //$this->assertEquals('connect', $ret[1]['Action']);
480+ $ this ->assertEquals ('disconnect ' , $ ret [1 ]['Action ' ]);
481+ $ this ->assertEquals ('destroy ' , $ ret [2 ]['Action ' ]);
482+ }
422483}
0 commit comments