66
77namespace Joomla \Github \Tests ;
88
9+ use Joomla \Github \AbstractGithubObject ;
910use Joomla \Github \Tests \Stub \GitHubTestCase ;
1011use Joomla \Github \Tests \Stub \ObjectMock ;
12+ use Joomla \Http \Http ;
13+ use Joomla \Http \Transport \Curl ;
1114
1215/**
1316 * Test class for Joomla\Github\Object.
1720class GithubObjectTest extends GitHubTestCase
1821{
1922 /**
20- * @var ObjectMock Object under test.
23+ * @var AbstractGithubObject Object under test.
2124 * @since 1.0
2225 */
2326 protected $ object ;
2427
28+ /**
29+ * @var Http The HTTP client
30+ * @since __DEPLOY_VERSION__
31+ */
32+ protected $ client ;
33+
2534 /**
2635 * Sets up the fixture, for example, opens a network connection.
2736 * This method is called before a test is executed.
@@ -34,6 +43,8 @@ protected function setUp()
3443 {
3544 parent ::setUp ();
3645
46+ $ transport = new Curl (array ());
47+ $ this ->client = new Http (array (), $ transport );
3748 $ this ->object = new ObjectMock ($ this ->options , $ this ->client );
3849 }
3950
@@ -47,10 +58,34 @@ protected function setUp()
4758 public function fetchUrlData ()
4859 {
4960 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+ ),
5489 );
5590 }
5691
@@ -72,9 +107,10 @@ public function testFetchUrl($apiUrl, $path, $page, $limit, $expected)
72107 {
73108 $ this ->options ->set ('api.url ' , $ apiUrl );
74109
75- $ this ->assertThat (
110+ self ::assertEquals (
111+ $ expected ,
76112 $ this ->object ->fetchUrl ($ path , $ page , $ limit ),
77- $ this -> equalTo ( $ expected)
113+ ' URL is not as expected. '
78114 );
79115 }
80116
@@ -92,9 +128,10 @@ public function testFetchUrlBasicAuth()
92128 $ this ->options ->set ('api.username ' , 'MyTestUser ' );
93129 $ this ->options ->set ('api.password ' , 'MyTestPass ' );
94130
95- $ this ->assertThat (
131+ self ::assertEquals (
132+ 'https://MyTestUser:[email protected] /gists ' ,
96133 $ this ->object ->fetchUrl ('/gists ' , 0 , 0 ),
97- $ this -> equalTo ( ' https://MyTestUser:[email protected] /gists ' ) 134+ ' URL is not as expected. '
98135 );
99136 }
100137
@@ -109,9 +146,16 @@ public function testFetchUrlToken()
109146
110147 $ this ->options ->set ('gh.token ' , 'MyTestToken ' );
111148
112- $ this ->assertThat (
149+ self ::assertEquals (
150+ 'https://api.github.com/gists ' ,
113151 $ 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. '
115159 );
116160 }
117161}
0 commit comments