Skip to content

Commit

Permalink
test refactoring
Browse files Browse the repository at this point in the history
 * 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.
  • Loading branch information
bshaffer committed Oct 19, 2015
1 parent 48dfd95 commit a1abf73
Show file tree
Hide file tree
Showing 31 changed files with 51 additions and 338 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ vendor
examples/testfile-small.txt
examples/testfile.txt
tests/.accessToken
tests/.apiKey
28 changes: 5 additions & 23 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,13 @@
colors="true"
bootstrap="tests/bootstrap.php">
<testsuites>
<testsuite name="Google YouTube API tests">
<directory>tests/youtube</directory>
</testsuite>
<testsuite name="Google Tasks API tests">
<directory>tests/tasks</directory>
</testsuite>
<testsuite name="Google PageSpeed API tests">
<directory>tests/pagespeed</directory>
</testsuite>
<testsuite name="Google UrlShortener API tests">
<directory>tests/urlshortener</directory>
</testsuite>
<testsuite name="Google Plus API tests">
<directory>tests/plus</directory>
</testsuite>
<testsuite name="AdSense Management API tests">
<directory>tests/adsense</directory>
</testsuite>
<testsuite name="Google API PHP Library core component tests">
<directory>tests/general</directory>
<testsuite name="Google PHP Client Test Suite">
<directory>tests/Google</directory>
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory suffix=".php">tests</directory>
</blacklist>
<whitelist>
<directory suffix=".php">./src/Google</directory>
</whitelist>
</filter>
</phpunit>
5 changes: 3 additions & 2 deletions tests/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class BaseTest extends PHPUnit_Framework_TestCase
private $token;
private $memcacheHost;
private $memcachePort;
protected $testDir = __DIR__;

public function __construct()
{
Expand Down Expand Up @@ -79,12 +80,12 @@ public function loadToken()

public function checkKey()
{
$this->key = $this->loadKey();

if (!strlen($this->key)) {
$this->markTestSkipped("Test requires api key\nYou can create one in your developer console");
return false;
}

$this->key = $this->loadKey();
}

public function loadKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use GuzzleHttp\Message\Request;

class ComputeEngineAuthTest extends BaseTest
class Google_Auth_ComputeEngineTest extends BaseTest
{
public function testTokenAcquisition()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* under the License.
*/

class ApiOAuth2Test extends BaseTest
class Google_Auth_OAuth2Test extends BaseTest
{

public function testSign()
Expand Down
2 changes: 1 addition & 1 deletion tests/general/CacheTest.php → tests/Google/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* under the License.
*/

class CacheTest extends BaseTest
class Google_CacheTest extends BaseTest
{
public function testFile()
{
Expand Down
17 changes: 15 additions & 2 deletions tests/general/ApiClientTest.php → tests/Google/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use GuzzleHttp\Message\Request;

class ApiClientTest extends BaseTest
class Google_ClientTest extends BaseTest
{
public function testClient()
{
Expand Down Expand Up @@ -195,7 +195,7 @@ public function testJsonConfig()

public function testIniConfig()
{
$config = new Google_Config(__DIR__ . "/testdata/test.ini");
$config = new Google_Config($this->testDir . "/config/test.ini");
$this->assertEquals('My Test application', $config->getApplicationName());
$this->assertEquals(
'gjfiwnGinpena3',
Expand All @@ -210,4 +210,17 @@ public function testIniConfig()
$config->getClassConfig('Google_IO_Abstract', 'request_timeout_seconds')
);
}

public function testNoAuth()
{
/** @var $noAuth Google_Auth_Simple */
$noAuth = new Google_Auth_Simple($this->getClient());
$client = new Google_Client();
$client->setAuth($noAuth);
$client->setDeveloperKey(null);
$req = new Request('GET', 'http://example.com');

$resp = $noAuth->sign($req);
$this->assertEquals('http://example.com', $resp->getUrl());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* under the License.
*/

class ApiBatchRequestTest extends BaseTest
class Google_Http_BatchTest extends BaseTest
{
public $plus;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* under the License.
*/

class ApiMediaFileUploadTest extends BaseTest
class Google_Http_MediaFileUploadTest extends BaseTest
{
public function testMediaFile()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use GuzzleHttp\Message\Response;
use GuzzleHttp\Stream\Stream;

class RestTest extends BaseTest
class Google_HTTP_RESTTest extends BaseTest
{
/**
* @var Google_Http_REST $rest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* under the License.
*/

class LoggerTest extends PHPUnit_Framework_TestCase
class Google_LoggerTest extends PHPUnit_Framework_TestCase
{
private $client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* under the License.
*/

class ApiModelTest extends BaseTest
class Google_ModelTest extends BaseTest
{
private $calendarData = '{
"kind": "calendar#event",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

class AdSenseManagementTest extends BaseTest
class Google_Service_AdSenseTest extends BaseTest
{
public $adsense;
public function __construct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

class PageSpeedTest extends BaseTest
class Google_Service_PagespeedonlineTest extends BaseTest
{
public $service;
public function __construct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

class PlusTest extends BaseTest
class Google_Service_PlusTest extends BaseTest
{
/** @var Google_PlusService */
public $plus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(Google_Client $client)
}
}

class ResourceTest extends PHPUnit_Framework_TestCase
class Google_Service_ResourceTest extends PHPUnit_Framework_TestCase
{
private $client;
private $service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

class TasksTest extends BaseTest
class Google_Service_TasksTest extends BaseTest
{
/** @var Google_TasksService */
public $taskService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,29 @@
* limitations under the License.
*/

class UrlShortenerTests extends BaseTest
class Google_Service_UrlshortenerTest extends BaseTest
{
/** @var Google_UrlshortenerService */
public $service;

public function __construct()
{
parent::__construct();
$this->service = new Google_Service_Urlshortener($this->getClient());
}

public function testUrlShort()
{
$this->checkKey();

$service = new Google_Service_Urlshortener($this->getClient());
$url = new Google_Service_Urlshortener_Url();
$url->longUrl = "http://google.com";

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

public function testEmptyJsonResponse()
{
$this->checkKey();

$service = new Google_Service_Urlshortener($this->getClient());

$optParams = array('fields' => '');
$resp = $this->service->url->get('http://goo.gl/KkHq8', $optParams);
$resp = $service->url->get('http://goo.gl/KkHq8', $optParams);

$this->assertEquals("", $resp->longUrl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

class YouTubeTest extends BaseTest
class Google_Service_YouTubeTest extends BaseTest
{
/** @var Google_PlusService */
public $plus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function isAssociativeArray($array)
}
}

class ServiceTest extends PHPUnit_Framework_TestCase
class Google_ServiceTest extends PHPUnit_Framework_TestCase
{

public function testModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use GuzzleHttp\Message\Response;
use GuzzleHttp\Stream\Stream;

class TaskTest extends PHPUnit_Framework_TestCase
class Google_Task_RunnerTest extends PHPUnit_Framework_TestCase
{
private $client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* under the License.
*/

class URITemplateTest extends BaseTest
class Google_Utils_URITemplateTest extends BaseTest
{
public function testLevelOne()
{
Expand Down
File renamed without changes.
Loading

0 comments on commit a1abf73

Please sign in to comment.