Skip to content

Commit a1abf73

Browse files
committed
test refactoring
* test files/classes match class names * removes tests/general/AuthTest.php because it tested firebase-jwt library, and not this library. * removes tests/testdata/*.pem, tests/testdata/*.p12, and tests/testdata/*.json as they are no longer used.
1 parent 48dfd95 commit a1abf73

31 files changed

+51
-338
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ vendor
55
examples/testfile-small.txt
66
examples/testfile.txt
77
tests/.accessToken
8+
tests/.apiKey

phpunit.xml.dist

+5-23
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,13 @@
44
colors="true"
55
bootstrap="tests/bootstrap.php">
66
<testsuites>
7-
<testsuite name="Google YouTube API tests">
8-
<directory>tests/youtube</directory>
9-
</testsuite>
10-
<testsuite name="Google Tasks API tests">
11-
<directory>tests/tasks</directory>
12-
</testsuite>
13-
<testsuite name="Google PageSpeed API tests">
14-
<directory>tests/pagespeed</directory>
15-
</testsuite>
16-
<testsuite name="Google UrlShortener API tests">
17-
<directory>tests/urlshortener</directory>
18-
</testsuite>
19-
<testsuite name="Google Plus API tests">
20-
<directory>tests/plus</directory>
21-
</testsuite>
22-
<testsuite name="AdSense Management API tests">
23-
<directory>tests/adsense</directory>
24-
</testsuite>
25-
<testsuite name="Google API PHP Library core component tests">
26-
<directory>tests/general</directory>
7+
<testsuite name="Google PHP Client Test Suite">
8+
<directory>tests/Google</directory>
279
</testsuite>
2810
</testsuites>
2911
<filter>
30-
<blacklist>
31-
<directory suffix=".php">tests</directory>
32-
</blacklist>
12+
<whitelist>
13+
<directory suffix=".php">./src/Google</directory>
14+
</whitelist>
3315
</filter>
3416
</phpunit>

tests/BaseTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class BaseTest extends PHPUnit_Framework_TestCase
2121
private $token;
2222
private $memcacheHost;
2323
private $memcachePort;
24+
protected $testDir = __DIR__;
2425

2526
public function __construct()
2627
{
@@ -79,12 +80,12 @@ public function loadToken()
7980

8081
public function checkKey()
8182
{
83+
$this->key = $this->loadKey();
84+
8285
if (!strlen($this->key)) {
8386
$this->markTestSkipped("Test requires api key\nYou can create one in your developer console");
8487
return false;
8588
}
86-
87-
$this->key = $this->loadKey();
8889
}
8990

9091
public function loadKey()

tests/general/ComputeEngineAuthTest.php renamed to tests/Google/Auth/ComputeEngineTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
use GuzzleHttp\Message\Request;
2222

23-
class ComputeEngineAuthTest extends BaseTest
23+
class Google_Auth_ComputeEngineTest extends BaseTest
2424
{
2525
public function testTokenAcquisition()
2626
{

tests/general/ApiOAuth2Test.php renamed to tests/Google/Auth/OAuth2Test.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* under the License.
2222
*/
2323

24-
class ApiOAuth2Test extends BaseTest
24+
class Google_Auth_OAuth2Test extends BaseTest
2525
{
2626

2727
public function testSign()

tests/general/CacheTest.php renamed to tests/Google/CacheTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* under the License.
1919
*/
2020

21-
class CacheTest extends BaseTest
21+
class Google_CacheTest extends BaseTest
2222
{
2323
public function testFile()
2424
{

tests/general/ApiClientTest.php renamed to tests/Google/ClientTest.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
use GuzzleHttp\Message\Request;
2222

23-
class ApiClientTest extends BaseTest
23+
class Google_ClientTest extends BaseTest
2424
{
2525
public function testClient()
2626
{
@@ -195,7 +195,7 @@ public function testJsonConfig()
195195

196196
public function testIniConfig()
197197
{
198-
$config = new Google_Config(__DIR__ . "/testdata/test.ini");
198+
$config = new Google_Config($this->testDir . "/config/test.ini");
199199
$this->assertEquals('My Test application', $config->getApplicationName());
200200
$this->assertEquals(
201201
'gjfiwnGinpena3',
@@ -210,4 +210,17 @@ public function testIniConfig()
210210
$config->getClassConfig('Google_IO_Abstract', 'request_timeout_seconds')
211211
);
212212
}
213+
214+
public function testNoAuth()
215+
{
216+
/** @var $noAuth Google_Auth_Simple */
217+
$noAuth = new Google_Auth_Simple($this->getClient());
218+
$client = new Google_Client();
219+
$client->setAuth($noAuth);
220+
$client->setDeveloperKey(null);
221+
$req = new Request('GET', 'http://example.com');
222+
223+
$resp = $noAuth->sign($req);
224+
$this->assertEquals('http://example.com', $resp->getUrl());
225+
}
213226
}

tests/general/ApiBatchRequestTest.php renamed to tests/Google/Http/BatchTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* under the License.
1919
*/
2020

21-
class ApiBatchRequestTest extends BaseTest
21+
class Google_Http_BatchTest extends BaseTest
2222
{
2323
public $plus;
2424

tests/general/ApiMediaFileUploadTest.php renamed to tests/Google/Http/MediaFuleUploadTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* under the License.
2323
*/
2424

25-
class ApiMediaFileUploadTest extends BaseTest
25+
class Google_Http_MediaFileUploadTest extends BaseTest
2626
{
2727
public function testMediaFile()
2828
{

tests/general/RestTest.php renamed to tests/Google/Http/RESTTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use GuzzleHttp\Message\Response;
1919
use GuzzleHttp\Stream\Stream;
2020

21-
class RestTest extends BaseTest
21+
class Google_HTTP_RESTTest extends BaseTest
2222
{
2323
/**
2424
* @var Google_Http_REST $rest

tests/general/LoggerTest.php renamed to tests/Google/LoggerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* under the License.
1919
*/
2020

21-
class LoggerTest extends PHPUnit_Framework_TestCase
21+
class Google_LoggerTest extends PHPUnit_Framework_TestCase
2222
{
2323
private $client;
2424

tests/general/ApiModelTest.php renamed to tests/Google/ModelTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* under the License.
1919
*/
2020

21-
class ApiModelTest extends BaseTest
21+
class Google_ModelTest extends BaseTest
2222
{
2323
private $calendarData = '{
2424
"kind": "calendar#event",

tests/adsense/AdSenseTest.php renamed to tests/Google/Service/AdSenseTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
class AdSenseManagementTest extends BaseTest
18+
class Google_Service_AdSenseTest extends BaseTest
1919
{
2020
public $adsense;
2121
public function __construct()

tests/pagespeed/PageSpeedTest.php renamed to tests/Google/Service/PagespeedonlineTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
class PageSpeedTest extends BaseTest
18+
class Google_Service_PagespeedonlineTest extends BaseTest
1919
{
2020
public $service;
2121
public function __construct()

tests/plus/PlusTest.php renamed to tests/Google/Service/PlusTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
class PlusTest extends BaseTest
18+
class Google_Service_PlusTest extends BaseTest
1919
{
2020
/** @var Google_PlusService */
2121
public $plus;

tests/general/ResourceTest.php renamed to tests/Google/Service/ResourceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(Google_Client $client)
3030
}
3131
}
3232

33-
class ResourceTest extends PHPUnit_Framework_TestCase
33+
class Google_Service_ResourceTest extends PHPUnit_Framework_TestCase
3434
{
3535
private $client;
3636
private $service;

tests/tasks/TasksTest.php renamed to tests/Google/Service/TasksTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
class TasksTest extends BaseTest
18+
class Google_Service_TasksTest extends BaseTest
1919
{
2020
/** @var Google_TasksService */
2121
public $taskService;

tests/urlshortener/UrlShortenerTests.php renamed to tests/Google/Service/UrlshortenerTest.php

+10-12
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,29 @@
1515
* limitations under the License.
1616
*/
1717

18-
class UrlShortenerTests extends BaseTest
18+
class Google_Service_UrlshortenerTest extends BaseTest
1919
{
20-
/** @var Google_UrlshortenerService */
21-
public $service;
22-
23-
public function __construct()
24-
{
25-
parent::__construct();
26-
$this->service = new Google_Service_Urlshortener($this->getClient());
27-
}
28-
2920
public function testUrlShort()
3021
{
22+
$this->checkKey();
23+
24+
$service = new Google_Service_Urlshortener($this->getClient());
3125
$url = new Google_Service_Urlshortener_Url();
3226
$url->longUrl = "http://google.com";
3327

34-
$shortUrl = $this->service->url->insert($url);
28+
$shortUrl = $service->url->insert($url);
3529
$this->assertEquals('urlshortener#url', $shortUrl['kind']);
3630
$this->assertEquals('http://google.com/', $shortUrl['longUrl']);
3731
}
3832

3933
public function testEmptyJsonResponse()
4034
{
35+
$this->checkKey();
36+
37+
$service = new Google_Service_Urlshortener($this->getClient());
38+
4139
$optParams = array('fields' => '');
42-
$resp = $this->service->url->get('http://goo.gl/KkHq8', $optParams);
40+
$resp = $service->url->get('http://goo.gl/KkHq8', $optParams);
4341

4442
$this->assertEquals("", $resp->longUrl);
4543
}

tests/youtube/YouTubeTest.php renamed to tests/Google/Service/YouTubeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
class YouTubeTest extends BaseTest
18+
class Google_Service_YouTubeTest extends BaseTest
1919
{
2020
/** @var Google_PlusService */
2121
public $plus;

tests/general/ServiceTest.php renamed to tests/Google/ServiceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function isAssociativeArray($array)
3131
}
3232
}
3333

34-
class ServiceTest extends PHPUnit_Framework_TestCase
34+
class Google_ServiceTest extends PHPUnit_Framework_TestCase
3535
{
3636

3737
public function testModel()

tests/general/TaskTest.php renamed to tests/Google/Task/RunnerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use GuzzleHttp\Message\Response;
2020
use GuzzleHttp\Stream\Stream;
2121

22-
class TaskTest extends PHPUnit_Framework_TestCase
22+
class Google_Task_RunnerTest extends PHPUnit_Framework_TestCase
2323
{
2424
private $client;
2525

tests/general/URITemplateTest.php renamed to tests/Google/Utils/URITemplateTest

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* under the License.
1919
*/
2020

21-
class URITemplateTest extends BaseTest
21+
class Google_Utils_URITemplateTest extends BaseTest
2222
{
2323
public function testLevelOne()
2424
{
File renamed without changes.

0 commit comments

Comments
 (0)