6
6
7
7
namespace Joomla \Github \Tests ;
8
8
9
+ use Joomla \Github \AbstractGithubObject ;
9
10
use Joomla \Github \Tests \Stub \GitHubTestCase ;
10
11
use Joomla \Github \Tests \Stub \ObjectMock ;
12
+ use Joomla \Http \Http ;
13
+ use Joomla \Http \Transport \Curl ;
11
14
12
15
/**
13
16
* Test class for Joomla\Github\Object.
17
20
class GithubObjectTest extends GitHubTestCase
18
21
{
19
22
/**
20
- * @var ObjectMock Object under test.
23
+ * @var AbstractGithubObject Object under test.
21
24
* @since 1.0
22
25
*/
23
26
protected $ object ;
24
27
28
+ /**
29
+ * @var Http The HTTP client
30
+ * @since __DEPLOY_VERSION__
31
+ */
32
+ protected $ client ;
33
+
25
34
/**
26
35
* Sets up the fixture, for example, opens a network connection.
27
36
* This method is called before a test is executed.
@@ -34,6 +43,8 @@ protected function setUp()
34
43
{
35
44
parent ::setUp ();
36
45
46
+ $ transport = new Curl (array ());
47
+ $ this ->client = new Http (array (), $ transport );
37
48
$ this ->object = new ObjectMock ($ this ->options , $ this ->client );
38
49
}
39
50
@@ -47,10 +58,34 @@ protected function setUp()
47
58
public function fetchUrlData ()
48
59
{
49
60
return array (
50
- 'Standard github - no pagination data ' => array ('https://api.github.com ' , '/gists ' , 0 , 0 , 'https://api.github.com/gists ' ),
51
- 'Enterprise github - no pagination data ' => array ('https://mygithub.com ' , '/gists ' , 0 , 0 , 'https://mygithub.com/gists ' ),
52
- 'Standard github - page 3 ' => array ('https://api.github.com ' , '/gists ' , 3 , 0 , 'https://api.github.com/gists?page=3 ' ),
53
- 'Enterprise github - page 3, 50 per page ' => array ('https://mygithub.com ' , '/gists ' , 3 , 50 , 'https://mygithub.com/gists?page=3&per_page=50 ' ),
61
+ 'Standard github - no pagination data ' => array (
62
+ 'https://api.github.com ' ,
63
+ '/gists ' ,
64
+ 0 ,
65
+ 0 ,
66
+ 'https://api.github.com/gists '
67
+ ),
68
+ 'Enterprise github - no pagination data ' => array (
69
+ 'https://mygithub.com ' ,
70
+ '/gists ' ,
71
+ 0 ,
72
+ 0 ,
73
+ 'https://mygithub.com/gists '
74
+ ),
75
+ 'Standard github - page 3 ' => array (
76
+ 'https://api.github.com ' ,
77
+ '/gists ' ,
78
+ 3 ,
79
+ 0 ,
80
+ 'https://api.github.com/gists?page=3 '
81
+ ),
82
+ 'Enterprise github - page 3, 50 per page ' => array (
83
+ 'https://mygithub.com ' ,
84
+ '/gists ' ,
85
+ 3 ,
86
+ 50 ,
87
+ 'https://mygithub.com/gists?page=3&per_page=50 '
88
+ ),
54
89
);
55
90
}
56
91
@@ -72,9 +107,10 @@ public function testFetchUrl($apiUrl, $path, $page, $limit, $expected)
72
107
{
73
108
$ this ->options ->set ('api.url ' , $ apiUrl );
74
109
75
- $ this ->assertThat (
110
+ self ::assertEquals (
111
+ $ expected ,
76
112
$ this ->object ->fetchUrl ($ path , $ page , $ limit ),
77
- $ this -> equalTo ( $ expected)
113
+ ' URL is not as expected. '
78
114
);
79
115
}
80
116
@@ -92,9 +128,10 @@ public function testFetchUrlBasicAuth()
92
128
$ this ->options ->set ('api.username ' , 'MyTestUser ' );
93
129
$ this ->options ->set ('api.password ' , 'MyTestPass ' );
94
130
95
- $ this ->assertThat (
131
+ self ::assertEquals (
132
+ 'https://MyTestUser:MyTestPass@api.github.com/gists ' ,
96
133
$ this ->object ->fetchUrl ('/gists ' , 0 , 0 ),
97
- $ this -> equalTo ( ' https://MyTestUser:MyTestPass@api.github.com/gists ' )
134
+ ' URL is not as expected. '
98
135
);
99
136
}
100
137
@@ -109,9 +146,16 @@ public function testFetchUrlToken()
109
146
110
147
$ this ->options ->set ('gh.token ' , 'MyTestToken ' );
111
148
112
- $ this ->assertThat (
149
+ self ::assertEquals (
150
+ 'https://api.github.com/gists ' ,
113
151
$ this ->object ->fetchUrl ('/gists ' , 0 , 0 ),
114
- $ this ->equalTo ('https://api.github.com/gists?access_token=MyTestToken ' )
152
+ 'URL is not as expected. '
153
+ );
154
+
155
+ self ::assertEquals (
156
+ array ('Authorization ' => 'token MyTestToken ' ),
157
+ $ this ->client ->getOption ('headers ' ),
158
+ 'Token should be propagated as a header. '
115
159
);
116
160
}
117
161
}
0 commit comments