assertFalse(AppIdentityCredentials::onAppEngine()); } public function testIsTrueWhenServerSoftwareIsGoogleAppEngine() { $_SERVER['SERVER_SOFTWARE'] = 'Google App Engine'; $this->assertTrue(AppIdentityCredentials::onAppEngine()); } public function testIsTrueWhenAppEngineRuntimeIsPhp() { $_SERVER['APPENGINE_RUNTIME'] = 'php'; $this->assertTrue(AppIdentityCredentials::onAppEngine()); } } class AppIdentityCredentialsGetCacheKeyTest extends TestCase { public function testShouldBeEmpty() { $g = new AppIdentityCredentials(); $this->assertEmpty($g->getCacheKey()); } } class AppIdentityCredentialsFetchAuthTokenTest extends TestCase { public function testShouldBeEmptyIfNotOnAppEngine() { $g = new AppIdentityCredentials(); $this->assertEquals(array(), $g->fetchAuthToken()); } /* @expectedException */ public function testThrowsExceptionIfClassDoesntExist() { $_SERVER['SERVER_SOFTWARE'] = 'Google App Engine'; $g = new AppIdentityCredentials(); } public function testReturnsExpectedToken() { // include the mock AppIdentityService class require_once __DIR__ . '/../mocks/AppIdentityService.php'; $wantedToken = [ 'access_token' => '1/abdef1234567890', 'expires_in' => '57', 'token_type' => 'Bearer', ]; AppIdentityService::$accessToken = $wantedToken; $_SERVER['SERVER_SOFTWARE'] = 'Google App Engine'; $g = new AppIdentityCredentials(); $this->assertEquals($wantedToken, $g->fetchAuthToken()); } public function testScopeIsAlwaysArray() { // include the mock AppIdentityService class require_once __DIR__ . '/../mocks/AppIdentityService.php'; $scope1 = ['scopeA', 'scopeB']; $scope2 = 'scopeA scopeB'; $scope3 = 'scopeA'; $_SERVER['SERVER_SOFTWARE'] = 'Google App Engine'; $g = new AppIdentityCredentials($scope1); $g->fetchAuthToken(); $this->assertEquals($scope1, AppIdentityService::$scope); $g = new AppIdentityCredentials($scope2); $g->fetchAuthToken(); $this->assertEquals(explode(' ', $scope2), AppIdentityService::$scope); $g = new AppIdentityCredentials($scope3); $g->fetchAuthToken(); $this->assertEquals([$scope3], AppIdentityService::$scope); } }