5
5
use Http \Client \HttpAsyncClient ;
6
6
use Http \Client \HttpClient ;
7
7
use Http \HttplugBundle \Discovery \ConfiguredClientsStrategy ;
8
- use Symfony \Component \DependencyInjection \ContainerInterface ;
9
- use Symfony \Component \DependencyInjection \ServiceLocator ;
10
8
11
9
class ConfiguredClientsStrategyTest extends \PHPUnit_Framework_TestCase
12
10
{
13
11
public function testGetCandidates ()
14
12
{
15
13
$ httpClient = $ this ->getMockBuilder (HttpClient::class)->getMock ();
16
14
$ 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 );
30
16
31
17
$ candidates = $ strategy ::getCandidates (HttpClient::class);
32
18
$ candidate = array_shift ($ candidates );
@@ -39,18 +25,7 @@ public function testGetCandidates()
39
25
40
26
public function testGetCandidatesEmpty ()
41
27
{
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 );
54
29
55
30
$ candidates = $ strategy ::getCandidates (HttpClient::class);
56
31
$ this ->assertEquals ([], $ candidates );
@@ -62,23 +37,7 @@ public function testGetCandidatesEmpty()
62
37
public function testGetCandidatesEmptyAsync ()
63
38
{
64
39
$ 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 );
82
41
83
42
$ candidates = $ strategy ::getCandidates (HttpClient::class);
84
43
$ candidate = array_shift ($ candidates );
@@ -91,23 +50,7 @@ public function testGetCandidatesEmptyAsync()
91
50
public function testGetCandidatesEmptySync ()
92
51
{
93
52
$ 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 );
111
54
112
55
$ candidates = $ strategy ::getCandidates (HttpClient::class);
113
56
$ this ->assertEquals ([], $ candidates );
@@ -116,16 +59,4 @@ public function testGetCandidatesEmptySync()
116
59
$ candidate = array_shift ($ candidates );
117
60
$ this ->assertEquals ($ httpAsyncClient , $ candidate ['class ' ]());
118
61
}
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
- }
131
62
}
0 commit comments