55use Github \Api ;
66use Github \Client ;
77use Github \Exception \BadMethodCallException ;
8+ use Github \HttpClient \Builder ;
89use Github \HttpClient \Plugin \Authentication ;
910use Http \Client \Common \Plugin ;
1011
@@ -23,11 +24,12 @@ public function shouldNotHaveToPassHttpClientToConstructor()
2324 /**
2425 * @test
2526 */
26- public function shouldPassHttpClientInterfaceToConstructor ()
27+ public function shouldPassHttpClientBulderInterfaceToConstructor ()
2728 {
2829 $ httpClientMock = $ this ->getMockBuilder (\Http \Client \HttpClient::class)
2930 ->getMock ();
30- $ client = new Client ($ httpClientMock );
31+
32+ $ client = new Client (new Builder ($ httpClientMock ));
3133
3234 $ this ->assertInstanceOf (\Http \Client \HttpClient::class, $ client ->getHttpClient ());
3335 }
@@ -38,17 +40,25 @@ public function shouldPassHttpClientInterfaceToConstructor()
3840 */
3941 public function shouldAuthenticateUsingAllGivenParameters ($ login , $ password , $ method )
4042 {
41- $ client = $ this ->getMockBuilder (\Github \Client ::class)
43+ $ builder = $ this ->getMockBuilder (\Github \HttpClient \Builder ::class)
4244 ->setMethods (array ('addPlugin ' , 'removePlugin ' ))
45+ ->disableOriginalConstructor ()
4346 ->getMock ();
44- $ client ->expects ($ this ->once ())
47+ $ builder ->expects ($ this ->once ())
4548 ->method ('addPlugin ' )
4649 ->with ($ this ->equalTo (new Authentication ($ login , $ password , $ method )));
47-
48- $ client ->expects ($ this ->once ())
50+ $ builder ->expects ($ this ->once ())
4951 ->method ('removePlugin ' )
5052 ->with (Authentication::class);
5153
54+ $ client = $ this ->getMockBuilder (\Github \Client::class)
55+ ->disableOriginalConstructor ()
56+ ->setMethods (['getHttpClientBuilder ' ])
57+ ->getMock ();
58+ $ client ->expects ($ this ->any ())
59+ ->method ('getHttpClientBuilder ' )
60+ ->willReturn ($ builder );
61+
5262 $ client ->authenticate ($ login , $ password , $ method );
5363 }
5464
@@ -68,17 +78,25 @@ public function getAuthenticationFullData()
6878 */
6979 public function shouldAuthenticateUsingGivenParameters ($ token , $ method )
7080 {
71- $ client = $ this ->getMockBuilder (\Github \Client ::class)
81+ $ builder = $ this ->getMockBuilder (\Github \HttpClient \Builder ::class)
7282 ->setMethods (array ('addPlugin ' , 'removePlugin ' ))
7383 ->getMock ();
74- $ client ->expects ($ this ->once ())
84+ $ builder ->expects ($ this ->once ())
7585 ->method ('addPlugin ' )
7686 ->with ($ this ->equalTo (new Authentication ($ token , null , $ method )));
7787
78- $ client ->expects ($ this ->once ())
88+ $ builder ->expects ($ this ->once ())
7989 ->method ('removePlugin ' )
8090 ->with (Authentication::class);
8191
92+ $ client = $ this ->getMockBuilder (\Github \Client::class)
93+ ->disableOriginalConstructor ()
94+ ->setMethods (['getHttpClientBuilder ' ])
95+ ->getMock ();
96+ $ client ->expects ($ this ->any ())
97+ ->method ('getHttpClientBuilder ' )
98+ ->willReturn ($ builder );
99+
82100 $ client ->authenticate ($ token , $ method );
83101 }
84102
@@ -101,47 +119,6 @@ public function shouldThrowExceptionWhenAuthenticatingWithoutMethodSet()
101119 $ client ->authenticate ('login ' , null , null );
102120 }
103121
104- /**
105- * @test
106- */
107- public function shouldClearHeaders ()
108- {
109- $ client = $ this ->getMockBuilder (\Github \Client::class)
110- ->setMethods (array ('addPlugin ' , 'removePlugin ' ))
111- ->getMock ();
112- $ client ->expects ($ this ->once ())
113- ->method ('addPlugin ' )
114- ->with ($ this ->isInstanceOf (Plugin \HeaderAppendPlugin::class));
115-
116- $ client ->expects ($ this ->once ())
117- ->method ('removePlugin ' )
118- ->with (Plugin \HeaderAppendPlugin::class);
119-
120- $ client ->clearHeaders ();
121- }
122-
123- /**
124- * @test
125- */
126- public function shouldAddHeaders ()
127- {
128- $ headers = array ('header1 ' , 'header2 ' );
129-
130- $ client = $ this ->getMockBuilder (\Github \Client::class)
131- ->setMethods (array ('addPlugin ' , 'removePlugin ' ))
132- ->getMock ();
133- $ client ->expects ($ this ->once ())
134- ->method ('addPlugin ' )
135- // TODO verify that headers exists
136- ->with ($ this ->isInstanceOf (Plugin \HeaderAppendPlugin::class));
137-
138- $ client ->expects ($ this ->once ())
139- ->method ('removePlugin ' )
140- ->with (Plugin \HeaderAppendPlugin::class);
141-
142- $ client ->addHeaders ($ headers );
143- }
144-
145122 /**
146123 * @test
147124 * @dataProvider getApiClassesProvider
0 commit comments