File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111class Factory
1212{
1313 private $ loop ;
14+ private $ browser ;
1415
15- public function __construct (LoopInterface $ loop )
16+ public function __construct (LoopInterface $ loop, Browser $ browser = null )
1617 {
18+ if ($ browser === null ) {
19+ $ browser = new Browser ($ loop );
20+ }
21+
1722 $ this ->loop = $ loop ;
23+ $ this ->browser = $ browser ;
1824 }
1925
2026 public function createClient ($ url = null )
@@ -23,18 +29,17 @@ public function createClient($url = null)
2329 $ url = 'unix:///var/run/docker.sock ' ;
2430 }
2531
26- $ sender = null ;
32+ $ browser = $ this -> browser ;
2733
2834 if (substr ($ url , 0 , 7 ) === 'unix:// ' ) {
2935 // send everything through a local unix domain socket
3036 $ sender = Sender::createFromLoopUnix ($ this ->loop , $ url );
37+ $ browser = $ browser ->withSender ($ sender );
3138
3239 // pretend all HTTP URLs to be on localhost
3340 $ url = 'http://localhost ' ;
3441 }
3542
36- $ browser = new Browser ($ this ->loop , $ sender );
37-
3843 return new Client ($ browser , $ url );
3944 }
4045}
Original file line number Diff line number Diff line change 66class FactoryTest extends TestCase
77{
88 private $ loop ;
9+ private $ browser ;
910 private $ factory ;
1011
1112 public function setUp ()
1213 {
1314 $ this ->loop = LoopFactory::create ();
14- $ this ->factory = new Factory ($ this ->loop );
15+ $ this ->browser = $ this ->getMockBuilder ('Clue\React\Buzz\Browser ' )->disableOriginalConstructor ()->getMock ();
16+ $ this ->factory = new Factory ($ this ->loop , $ this ->browser );
1517 }
1618
17- public function testCreateClientDefault ()
19+ public function testCtorDefaultBrowser ()
1820 {
21+ $ factory = new Factory ($ this ->loop );
22+ }
23+
24+ public function testCreateClientUsesCustomUnixSender ()
25+ {
26+ $ this ->browser ->expects ($ this ->once ())->method ('withSender ' )->will ($ this ->returnValue ($ this ->browser ));
27+
1928 $ client = $ this ->factory ->createClient ();
2029
2130 $ this ->assertInstanceOf ('Clue\React\Docker\Client ' , $ client );
2231 }
32+
33+ public function testCreateClientWithHttp ()
34+ {
35+ $ this ->browser ->expects ($ this ->never ())->method ('withSender ' );
36+
37+ $ this ->factory ->createClient ('http://localhost:1234/ ' );
38+ }
2339}
You can’t perform that action at this time.
0 commit comments