Skip to content

Commit 281602f

Browse files
committed
Merge pull request #407 from whatthejeff/phpunit-simplify
Simplify PHPUnit setup.
2 parents ade1652 + 648ebcd commit 281602f

31 files changed

Lines changed: 83 additions & 331 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
phpunit.xml

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ php:
1414
- 5.5
1515
- 5.6
1616
- hhvm
17-
17+
1818
before_script:
1919
- composer install
2020
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "extension=memcache.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
@@ -23,4 +23,4 @@ before_script:
2323
- phpenv version-name | grep ^5.[34] && echo "apc.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true
2424

2525
script:
26-
- cd tests ; phpunit .
26+
- vendor/bin/phpunit

phpunit.xml.dist

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xsd"
4+
colors="true"
5+
bootstrap="tests/bootstrap.php">
6+
<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>
27+
</testsuite>
28+
</testsuites>
29+
<filter>
30+
<blacklist>
31+
<directory suffix=".php">tests</directory>
32+
</blacklist>
33+
</filter>
34+
</phpunit>

tests/AllTests.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

tests/BaseTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
require_once 'bootstrap.php';
18-
require_once 'Google/Client.php';
1917

2018
class BaseTest extends PHPUnit_Framework_TestCase
2119
{
2220
const KEY = "";
2321
private $token;
2422
private $memcacheHost;
2523
private $memcachePort;
26-
24+
2725
public function __construct()
2826
{
2927
parent::__construct();
@@ -34,7 +32,7 @@ public function __construct()
3432
$this->memcacheHost = getenv('MEMCACHE_HOST') ? getenv('MEMCACHE_HOST') : null;
3533
$this->memcachePort = getenv('MEMCACHE_PORT') ? getenv('MEMCACHE_PORT') : null;
3634
}
37-
35+
3836
public function getClient()
3937
{
4038
$client = new Google_Client();
@@ -48,22 +46,20 @@ public function getClient()
4846
}
4947
return $client;
5048
}
51-
49+
5250
public function testClientConstructor()
5351
{
5452
$this->assertInstanceOf('Google_Client', $this->getClient());
5553
}
56-
54+
5755
public function testIncludes()
5856
{
59-
$prefix = dirname(dirname(__FILE__)) . '/src/';
6057
$path = dirname(dirname(__FILE__)) . '/src/Google/Service';
6158
foreach (glob($path . "/*.php") as $file) {
62-
// Munge prefix so we don't double require.
63-
$this->assertEquals(1, require_once(str_replace($prefix, '', $file)));
59+
$this->assertEquals(1, require_once($file));
6460
}
6561
}
66-
62+
6763
public function checkToken()
6864
{
6965
if (!strlen($this->token)) {

tests/OAuthHelper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
include_once 'bootstrap.php';
18-
require_once 'Google/Client.php';
17+
require_once dirname(__FILE__) . '/../autoload.php';
1918

2019
$client = new Google_Client();
2120
$client->setScopes(

tests/adsense/AdSenseTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
require_once realpath(dirname(__FILE__) . '/../../autoload.php');
19-
20-
class AdsenseTests extends PHPUnit_Framework_TestSuite
21-
{
22-
public static function suite()
23-
{
24-
$suite = new PHPUnit_Framework_TestSuite();
25-
$suite->setName('AdSense Management API tests');
26-
$suite->addTestSuite('AdSenseManagementTest');
27-
return $suite;
28-
}
29-
}
30-
3118
class AdSenseManagementTest extends BaseTest
3219
{
3320
public $adsense;

tests/bootstrap.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
<?php
2-
set_include_path(
3-
dirname(__FILE__) . PATH_SEPARATOR .
4-
dirname(dirname(__FILE__)) . "/src". PATH_SEPARATOR .
5-
get_include_path()
6-
);
2+
/*
3+
* Copyright 2014 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
require_once dirname(__FILE__) . '/../autoload.php';
19+
require_once dirname(__FILE__) . '/BaseTest.php';
20+
721
date_default_timezone_set('UTC');

tests/general/ApiBatchRequestTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
* under the License.
1919
*/
2020

21-
require_once 'BaseTest.php';
22-
require_once realpath(dirname(__FILE__) . '/../../autoload.php');
23-
2421
class ApiBatchRequestTest extends BaseTest
2522
{
2623
public $plus;

tests/general/ApiCacheParserTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
* under the License.
1919
*/
2020

21-
require_once 'BaseTest.php';
22-
require_once realpath(dirname(__FILE__) . '/../../autoload.php');
23-
2421
class ApiCacheParserTest extends BaseTest
2522
{
2623
public function testIsResponseCacheable()

0 commit comments

Comments
 (0)