55use  Http \Client \HttpAsyncClient ;
66use  Http \Client \HttpClient ;
77use  Http \HttplugBundle \Discovery \ConfiguredClientsStrategy ;
8- use  Symfony \Component \DependencyInjection \ContainerInterface ;
9- use  Symfony \Component \DependencyInjection \ServiceLocator ;
108
119class  ConfiguredClientsStrategyTest extends  \PHPUnit_Framework_TestCase
1210{
1311    public  function  testGetCandidates ()
1412    {
1513        $ httpClient  = $ this  ->getMockBuilder (HttpClient::class)->getMock ();
1614        $ httpAsyncClient  = $ this  ->getMockBuilder (HttpAsyncClient::class)->getMock ();
17-         $ locator  = $ this  ->getLocatorMock ();
18-         $ locator
19-             ->expects ($ this  ->exactly (2 ))
20-             ->method ('has ' )
21-             ->willReturn (true )
22-         ;
23-         $ locator
24-             ->expects ($ this  ->exactly (2 ))
25-             ->method ('get ' )
26-             ->will ($ this  ->onConsecutiveCalls ($ httpClient , $ httpAsyncClient ))
27-         ;
28- 
29-         $ strategy  = new  ConfiguredClientsStrategy ($ locator , 'httplug.auto_discovery.auto_discovered_client ' , 'httplug.auto_discovery.auto_discovered_async ' );
15+         $ strategy  = new  ConfiguredClientsStrategy ($ httpClient , $ httpAsyncClient );
3016
3117        $ candidates  = $ strategy ::getCandidates (HttpClient::class);
3218        $ candidate  = array_shift ($ candidates );
@@ -39,18 +25,7 @@ public function testGetCandidates()
3925
4026    public  function  testGetCandidatesEmpty ()
4127    {
42-         $ locator  = $ this  ->getLocatorMock ();
43-         $ locator
44-             ->expects ($ this  ->exactly (2 ))
45-             ->method ('has ' )
46-             ->willReturn (false )
47-         ;
48-         $ locator
49-             ->expects ($ this  ->never ())
50-             ->method ('get ' )
51-         ;
52- 
53-         $ strategy  = new  ConfiguredClientsStrategy ($ locator , 'httplug.auto_discovery.auto_discovered_client ' , 'httplug.auto_discovery.auto_discovered_async ' );
28+         $ strategy  = new  ConfiguredClientsStrategy (null , null );
5429
5530        $ candidates  = $ strategy ::getCandidates (HttpClient::class);
5631        $ this  ->assertEquals ([], $ candidates );
@@ -62,23 +37,7 @@ public function testGetCandidatesEmpty()
6237    public  function  testGetCandidatesEmptyAsync ()
6338    {
6439        $ httpClient  = $ this  ->getMockBuilder (HttpClient::class)->getMock ();
65- 
66-         $ locator  = $ this  ->getLocatorMock ();
67-         $ locator
68-             ->expects ($ this  ->exactly (2 ))
69-             ->method ('has ' )
70-             ->willReturnMap ([
71-                 ['httplug.auto_discovery.auto_discovered_client ' , true ],
72-                 ['httplug.auto_discovery.auto_discovered_async ' , false ],
73-             ])
74-         ;
75-         $ locator
76-             ->expects ($ this  ->once ())
77-             ->method ('get ' )
78-             ->willReturn ($ httpClient )
79-         ;
80- 
81-         $ strategy  = new  ConfiguredClientsStrategy ($ locator , 'httplug.auto_discovery.auto_discovered_client ' , 'httplug.auto_discovery.auto_discovered_async ' );
40+         $ strategy  = new  ConfiguredClientsStrategy ($ httpClient , null );
8241
8342        $ candidates  = $ strategy ::getCandidates (HttpClient::class);
8443        $ candidate  = array_shift ($ candidates );
@@ -91,23 +50,7 @@ public function testGetCandidatesEmptyAsync()
9150    public  function  testGetCandidatesEmptySync ()
9251    {
9352        $ httpAsyncClient  = $ this  ->getMockBuilder (HttpAsyncClient::class)->getMock ();
94- 
95-         $ locator  = $ this  ->getLocatorMock ();
96-         $ locator
97-             ->expects ($ this  ->exactly (2 ))
98-             ->method ('has ' )
99-             ->willReturnMap ([
100-                 ['httplug.auto_discovery.auto_discovered_client ' , false ],
101-                 ['httplug.auto_discovery.auto_discovered_async ' , true ],
102-             ])
103-         ;
104-         $ locator
105-             ->expects ($ this  ->once ())
106-             ->method ('get ' )
107-             ->willReturn ($ httpAsyncClient )
108-         ;
109- 
110-         $ strategy  = new  ConfiguredClientsStrategy ($ locator , 'httplug.auto_discovery.auto_discovered_client ' , 'httplug.auto_discovery.auto_discovered_async ' );
53+         $ strategy  = new  ConfiguredClientsStrategy (null , $ httpAsyncClient );
11154
11255        $ candidates  = $ strategy ::getCandidates (HttpClient::class);
11356        $ this  ->assertEquals ([], $ candidates );
@@ -116,16 +59,4 @@ public function testGetCandidatesEmptySync()
11659        $ candidate  = array_shift ($ candidates );
11760        $ this  ->assertEquals ($ httpAsyncClient , $ candidate ['class ' ]());
11861    }
119- 
120-     /** 
121-      * @return ContainerInterface|ServiceLocator 
122-      */ 
123-     private  function  getLocatorMock ()
124-     {
125-         if  (class_exists (ServiceLocator::class)) {
126-             return  $ this  ->getMockBuilder (ServiceLocator::class)->disableOriginalConstructor ()->getMock ();
127-         }
128- 
129-         return  $ this  ->getMockBuilder (ContainerInterface::class)->getMock ();
130-     }
13162}
0 commit comments