Skip to content

Commit 29abd13

Browse files
authored
chore(tests): organize fixtures into a single test directory (#651)
1 parent c28fffc commit 29abd13

38 files changed

Lines changed: 87 additions & 86 deletions

tests/AccessTokenTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public function provideCertsFromUrl()
293293

294294
public function testRetrieveCertsFromLocationLocalFile()
295295
{
296-
$certsLocation = __DIR__ . '/fixtures/federated-certs.json';
296+
$certsLocation = __DIR__ . '/fixtures/fixtures1/federated-certs.json';
297297
$certsData = json_decode(file_get_contents($certsLocation), true);
298298

299299
$item = $this->prophesize('Psr\Cache\CacheItemInterface');
@@ -336,7 +336,7 @@ public function testRetrieveCertsFromLocationLocalFileInvalidFilePath()
336336
$this->expectException(InvalidArgumentException::class);
337337
$this->expectExceptionMessage('Failed to retrieve verification certificates from path');
338338

339-
$certsLocation = __DIR__ . '/fixtures/federated-certs-does-not-exist.json';
339+
$certsLocation = __DIR__ . '/fixtures/fixtures1/federated-certs-does-not-exist.json';
340340

341341
$item = $this->prophesize('Psr\Cache\CacheItemInterface');
342342
$item->get()
@@ -409,7 +409,7 @@ public function testRetrieveCertsFromLocationLocalFileInvalidFileData()
409409

410410
public function testRetrieveCertsFromLocationRespectsCacheControl()
411411
{
412-
$certsLocation = __DIR__ . '/fixtures/federated-certs.json';
412+
$certsLocation = __DIR__ . '/fixtures/fixtures1/federated-certs.json';
413413
$certsJson = file_get_contents($certsLocation);
414414
$certsData = json_decode($certsJson, true);
415415

@@ -454,7 +454,7 @@ public function testRetrieveCertsFromLocationRespectsCacheControl()
454454

455455
public function testRetrieveCertsFromLocationRemote()
456456
{
457-
$certsLocation = __DIR__ . '/fixtures/federated-certs.json';
457+
$certsLocation = __DIR__ . '/fixtures/fixtures1/federated-certs.json';
458458
$certsJson = file_get_contents($certsLocation);
459459
$certsData = json_decode($certsJson, true);
460460

tests/ApplicationDefaultCredentialsTest.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ public function testGetCredentialsFailsIfEnvSpecifiesNonExistentFile()
5454
{
5555
$this->expectException(DomainException::class);
5656

57-
$keyFile = __DIR__ . '/fixtures' . '/does-not-exist-private.json';
57+
$keyFile = __DIR__ . '/fixtures/fixtures1/does-not-exist-private.json';
5858
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
5959
ApplicationDefaultCredentials::getCredentials('a scope');
6060
}
6161

6262
public function testLoadsOKIfEnvSpecifiedIsValid()
6363
{
64-
$keyFile = __DIR__ . '/fixtures' . '/private.json';
64+
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
6565
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
6666
$this->assertNotNull(
6767
ApplicationDefaultCredentials::getCredentials('a scope')
@@ -70,7 +70,7 @@ public function testLoadsOKIfEnvSpecifiedIsValid()
7070

7171
public function testLoadsDefaultFileIfPresentAndEnvVarIsNotSet()
7272
{
73-
setHomeEnv(__DIR__ . '/fixtures');
73+
setHomeEnv(__DIR__ . '/fixtures/fixtures1');
7474
$this->assertNotNull(
7575
ApplicationDefaultCredentials::getCredentials('a scope')
7676
);
@@ -159,7 +159,7 @@ public function testGceCredentials()
159159

160160
public function testImpersonatedServiceAccountCredentials()
161161
{
162-
setHomeEnv(__DIR__ . '/fixtures5');
162+
setHomeEnv(__DIR__ . '/fixtures/fixtures5');
163163
$creds = ApplicationDefaultCredentials::getCredentials(
164164
null,
165165
null,
@@ -181,7 +181,7 @@ public function testImpersonatedServiceAccountCredentials()
181181

182182
public function testUserRefreshCredentials()
183183
{
184-
setHomeEnv(__DIR__ . '/fixtures2');
184+
setHomeEnv(__DIR__ . '/fixtures/fixtures2');
185185

186186
$creds = ApplicationDefaultCredentials::getCredentials(
187187
null, // $scope
@@ -216,7 +216,7 @@ public function testUserRefreshCredentials()
216216

217217
public function testServiceAccountCredentials()
218218
{
219-
setHomeEnv(__DIR__ . '/fixtures');
219+
setHomeEnv(__DIR__ . '/fixtures/fixtures1');
220220

221221
$creds = ApplicationDefaultCredentials::getCredentials(
222222
null, // $scope
@@ -251,7 +251,7 @@ public function testServiceAccountCredentials()
251251

252252
public function testDefaultScopeArray()
253253
{
254-
setHomeEnv(__DIR__ . '/fixtures2');
254+
setHomeEnv(__DIR__ . '/fixtures/fixtures2');
255255

256256
$creds = ApplicationDefaultCredentials::getCredentials(
257257
null, // $scope
@@ -273,21 +273,21 @@ public function testGetMiddlewareFailsIfEnvSpecifiesNonExistentFile()
273273
{
274274
$this->expectException(DomainException::class);
275275

276-
$keyFile = __DIR__ . '/fixtures' . '/does-not-exist-private.json';
276+
$keyFile = __DIR__ . '/fixtures/fixtures1/does-not-exist-private.json';
277277
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
278278
ApplicationDefaultCredentials::getMiddleware('a scope');
279279
}
280280

281281
public function testGetMiddlewareLoadsOKIfEnvSpecifiedIsValid()
282282
{
283-
$keyFile = __DIR__ . '/fixtures' . '/private.json';
283+
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
284284
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
285285
$this->assertNotNull(ApplicationDefaultCredentials::getMiddleware('a scope'));
286286
}
287287

288288
public function testLGetMiddlewareoadsDefaultFileIfPresentAndEnvVarIsNotSet()
289289
{
290-
setHomeEnv(__DIR__ . '/fixtures');
290+
setHomeEnv(__DIR__ . '/fixtures/fixtures1');
291291
$this->assertNotNull(ApplicationDefaultCredentials::getMiddleware('a scope'));
292292
}
293293

@@ -309,7 +309,7 @@ public function testGetMiddlewareFailsIfNotOnGceAndNoDefaultFileFound()
309309

310310
public function testGetMiddlewareWithCacheOptions()
311311
{
312-
$keyFile = __DIR__ . '/fixtures' . '/private.json';
312+
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
313313
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
314314

315315
$httpHandler = getHandler([
@@ -452,14 +452,14 @@ public function testGetIdTokenCredentialsFailsIfEnvSpecifiesNonExistentFile()
452452
{
453453
$this->expectException(DomainException::class);
454454

455-
$keyFile = __DIR__ . '/fixtures' . '/does-not-exist-private.json';
455+
$keyFile = __DIR__ . '/fixtures/fixtures1/does-not-exist-private.json';
456456
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
457457
ApplicationDefaultCredentials::getIdTokenCredentials($this->targetAudience);
458458
}
459459

460460
public function testGetIdTokenCredentialsLoadsOKIfEnvSpecifiedIsValid()
461461
{
462-
$keyFile = __DIR__ . '/fixtures' . '/private.json';
462+
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
463463
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
464464

465465
$creds = ApplicationDefaultCredentials::getIdTokenCredentials($this->targetAudience);
@@ -468,7 +468,7 @@ public function testGetIdTokenCredentialsLoadsOKIfEnvSpecifiedIsValid()
468468

469469
public function testGetIdTokenCredentialsLoadsDefaultFileIfPresentAndEnvVarIsNotSet()
470470
{
471-
setHomeEnv(__DIR__ . '/fixtures');
471+
setHomeEnv(__DIR__ . '/fixtures/fixtures1');
472472
$creds = ApplicationDefaultCredentials::getIdTokenCredentials($this->targetAudience);
473473
$this->assertInstanceOf(ServiceAccountCredentials::class, $creds);
474474
}
@@ -495,14 +495,14 @@ public function testGetIdTokenCredentialsFailsIfNotOnGceAndNoDefaultFileFound()
495495

496496
public function testGetIdTokenCredentialsWithImpersonatedServiceAccountCredentials()
497497
{
498-
setHomeEnv(__DIR__ . '/fixtures5');
498+
setHomeEnv(__DIR__ . '/fixtures/fixtures5');
499499
$creds = ApplicationDefaultCredentials::getIdTokenCredentials('123@456.com');
500500
$this->assertInstanceOf(ImpersonatedServiceAccountCredentials::class, $creds);
501501
}
502502

503503
public function testGetIdTokenCredentialsWithCacheOptions()
504504
{
505-
$keyFile = __DIR__ . '/fixtures' . '/private.json';
505+
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
506506
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
507507

508508
$httpHandler = getHandler([
@@ -548,7 +548,7 @@ public function testGetIdTokenCredentialsSuccedsIfNoDefaultFilesButIsOnGCE()
548548

549549
public function testGetIdTokenCredentialsWithUserRefreshCredentials()
550550
{
551-
setHomeEnv(__DIR__ . '/fixtures2');
551+
setHomeEnv(__DIR__ . '/fixtures/fixtures2');
552552

553553
$creds = ApplicationDefaultCredentials::getIdTokenCredentials(
554554
$this->targetAudience,
@@ -567,7 +567,7 @@ public function testGetIdTokenCredentialsWithUserRefreshCredentials()
567567

568568
public function testWithServiceAccountCredentialsAndExplicitQuotaProject()
569569
{
570-
$keyFile = __DIR__ . '/fixtures' . '/private.json';
570+
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
571571
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
572572

573573
$credentials = ApplicationDefaultCredentials::getCredentials(
@@ -588,7 +588,7 @@ public function testWithServiceAccountCredentialsAndExplicitQuotaProject()
588588

589589
public function testGetCredentialsUtilizesQuotaProjectInKeyFile()
590590
{
591-
$keyFile = __DIR__ . '/fixtures' . '/private.json';
591+
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
592592
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
593593

594594
$credentials = ApplicationDefaultCredentials::getCredentials();
@@ -604,7 +604,7 @@ public function testGetCredentialsUtilizesQuotaProjectEnvVar()
604604
{
605605
$quotaProject = 'quota-project-from-env-var';
606606
putenv(CredentialsLoader::QUOTA_PROJECT_ENV_VAR . '=' . $quotaProject);
607-
setHomeEnv(__DIR__ . '/fixtures');
607+
setHomeEnv(__DIR__ . '/fixtures/fixtures1');
608608

609609
$credentials = ApplicationDefaultCredentials::getCredentials();
610610

@@ -619,7 +619,7 @@ public function testGetCredentialsUtilizesQuotaProjectParameterOverEnvVar()
619619
{
620620
$quotaProject = 'quota-project-from-parameter';
621621
putenv(CredentialsLoader::QUOTA_PROJECT_ENV_VAR . '=quota-project-from-env-var');
622-
setHomeEnv(__DIR__ . '/fixtures');
622+
setHomeEnv(__DIR__ . '/fixtures/fixtures1');
623623

624624
$credentials = ApplicationDefaultCredentials::getCredentials(
625625
null, // $scope
@@ -640,7 +640,7 @@ public function testGetCredentialsUtilizesQuotaProjectParameterOverEnvVar()
640640
public function testGetCredentialsUtilizesQuotaProjectEnvVarOverKeyFile()
641641
{
642642
$quotaProject = 'quota-project-from-env-var';
643-
$keyFile = __DIR__ . '/fixtures' . '/private.json';
643+
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
644644
putenv(CredentialsLoader::QUOTA_PROJECT_ENV_VAR . '=' . $quotaProject);
645645
putenv(CredentialsLoader::ENV_VAR . '=' . $keyFile);
646646

@@ -654,7 +654,7 @@ public function testGetCredentialsUtilizesQuotaProjectEnvVarOverKeyFile()
654654

655655
public function testWithFetchAuthTokenCacheAndExplicitQuotaProject()
656656
{
657-
$keyFile = __DIR__ . '/fixtures' . '/private.json';
657+
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
658658
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
659659

660660
$httpHandler = getHandler([
@@ -756,7 +756,7 @@ public function testAppEngineFlexibleIdToken()
756756
*/
757757
public function testExternalAccountCredentials(string $jsonFile, string $expectedCredSource)
758758
{
759-
putenv(sprintf('GOOGLE_APPLICATION_CREDENTIALS=%s/fixtures6/%s', __DIR__, $jsonFile));
759+
putenv(sprintf('GOOGLE_APPLICATION_CREDENTIALS=%s/fixtures/fixtures6/%s', __DIR__, $jsonFile));
760760

761761
$creds = ApplicationDefaultCredentials::getCredentials('a_scope');
762762

@@ -827,19 +827,19 @@ public function provideExternalAccountCredentials()
827827
public function testUniverseDomainInKeyFile()
828828
{
829829
// Test no universe domain in keyfile defaults to "googleapis.com"
830-
$keyFile = __DIR__ . '/fixtures3/service_account_credentials.json';
830+
$keyFile = __DIR__ . '/fixtures/fixtures3/service_account_credentials.json';
831831
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
832832
$creds = ApplicationDefaultCredentials::getCredentials();
833833
$this->assertEquals(CredentialsLoader::DEFAULT_UNIVERSE_DOMAIN, $creds->getUniverseDomain());
834834

835835
// Test universe domain in "service_account" keyfile
836-
$keyFile = __DIR__ . '/fixtures/private.json';
836+
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
837837
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
838838
$creds = ApplicationDefaultCredentials::getCredentials();
839839
$this->assertEquals('example-universe.com', $creds->getUniverseDomain());
840840

841841
// Test universe domain in "authenticated_user" keyfile is not read.
842-
$keyFile = __DIR__ . '/fixtures2/private.json';
842+
$keyFile = __DIR__ . '/fixtures/fixtures2/private.json';
843843
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
844844
$creds2 = ApplicationDefaultCredentials::getCredentials();
845845
$this->assertEquals(CredentialsLoader::DEFAULT_UNIVERSE_DOMAIN, $creds2->getUniverseDomain());

tests/Credentials/GCECredentialsTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ public function testOnWindowsGceWithResidencyWithNoCom()
138138
$method = (new ReflectionClass(GCECredentials::class))
139139
->getMethod('detectResidencyWindows');
140140

141-
142141
$this->assertFalse($method->invoke(null, 'thisShouldBeFalse'));
143142
}
144143

tests/Credentials/ServiceAccountCredentialsTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private function createTestJson()
4141
'client_id' => 'client123',
4242
'type' => 'service_account',
4343
'project_id' => 'example_project',
44-
'private_key' => file_get_contents(__DIR__ . '/../fixtures/private.pem'),
44+
'private_key' => file_get_contents(__DIR__ . '/../fixtures/fixtures1/private.pem'),
4545
];
4646
}
4747

@@ -138,13 +138,13 @@ public function testFailsToInitalizeFromANonExistentFile()
138138
{
139139
$this->expectException(InvalidArgumentException::class);
140140

141-
$keyFile = __DIR__ . '/../fixtures' . '/does-not-exist-private.json';
141+
$keyFile = __DIR__ . '/../fixtures/fixtures1/does-not-exist-private.json';
142142
new ServiceAccountCredentials('scope/1', $keyFile);
143143
}
144144

145145
public function testInitalizeFromAFile()
146146
{
147-
$keyFile = __DIR__ . '/../fixtures' . '/private.json';
147+
$keyFile = __DIR__ . '/../fixtures/fixtures1/private.json';
148148
$this->assertNotNull(
149149
new ServiceAccountCredentials('scope/1', $keyFile)
150150
);
@@ -176,15 +176,15 @@ public function testIsNullIfEnvVarIsNotSet()
176176
public function testFailsIfEnvSpecifiesNonExistentFile()
177177
{
178178
$this->expectException(DomainException::class);
179-
$keyFile = __DIR__ . '/../fixtures' . '/does-not-exist-private.json';
179+
$keyFile = __DIR__ . '/../fixtures/fixtures1/does-not-exist-private.json';
180180
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
181181
ApplicationDefaultCredentials::getCredentials('a scope');
182182
}
183183

184184
/** @runInSeparateProcess */
185185
public function testSucceedIfFileExists()
186186
{
187-
$keyFile = __DIR__ . '/../fixtures' . '/private.json';
187+
$keyFile = __DIR__ . '/../fixtures/fixtures1/private.json';
188188
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
189189
$this->assertNotNull(ApplicationDefaultCredentials::getCredentials('a scope'));
190190
}
@@ -201,7 +201,7 @@ public function testIsNullIfFileDoesNotExist()
201201
/** @runInSeparateProcess */
202202
public function testSucceedIfFileIsPresent()
203203
{
204-
setHomeEnv(__DIR__ . '/../fixtures');
204+
setHomeEnv(__DIR__ . '/../fixtures/fixtures1');
205205
$this->assertNotNull(
206206
ApplicationDefaultCredentials::getCredentials('a scope')
207207
);
@@ -420,7 +420,7 @@ public function testGetProjectId()
420420

421421
public function testGetQuotaProject()
422422
{
423-
$keyFile = __DIR__ . '/../fixtures' . '/private.json';
423+
$keyFile = __DIR__ . '/../fixtures/fixtures1/private.json';
424424
$sa = new ServiceAccountCredentials('scope/1', $keyFile);
425425
$this->assertEquals('test_quota_project', $sa->getQuotaProject());
426426
}

tests/Credentials/ServiceAccountJwtAccessCredentialsTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ private function createTestJson()
4040
'client_id' => 'client123',
4141
'type' => 'service_account',
4242
'project_id' => 'example_project',
43-
'private_key' => file_get_contents(__DIR__ . '/../fixtures' . '/private.pem'),
43+
'private_key' => file_get_contents(__DIR__ . '/../fixtures/fixtures1/private.pem'),
4444
];
4545
}
4646

4747
public function testFailsToInitalizeFromANonExistentFile()
4848
{
4949
$this->expectException(InvalidArgumentException::class);
5050

51-
$keyFile = __DIR__ . '/../fixtures' . '/does-not-exist-private.json';
51+
$keyFile = __DIR__ . '/../fixtures/fixtures1/does-not-exist-private.json';
5252
new ServiceAccountJwtAccessCredentials($keyFile);
5353
}
5454

5555
public function testInitalizeFromAFile()
5656
{
57-
$keyFile = __DIR__ . '/../fixtures' . '/private.json';
57+
$keyFile = __DIR__ . '/../fixtures/fixtures1/private.json';
5858
$this->assertNotNull(
5959
new ServiceAccountJwtAccessCredentials($keyFile)
6060
);
@@ -392,7 +392,7 @@ public function testFetchAuthTokenWithScopeAndUseJwtAccessWithScopeParameterAndA
392392
/** @runInSeparateProcess */
393393
public function testAccessFromApplicationDefault()
394394
{
395-
$keyFile = __DIR__ . '/../fixtures3/service_account_credentials.json';
395+
$keyFile = __DIR__ . '/../fixtures/fixtures3/service_account_credentials.json';
396396
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
397397
$creds = ApplicationDefaultCredentials::getCredentials(
398398
null, // $scope
@@ -408,7 +408,7 @@ public function testAccessFromApplicationDefault()
408408

409409
$this->assertArrayHasKey('authorization', $metadata);
410410
$token = str_replace('Bearer ', '', $metadata['authorization'][0]);
411-
$key = file_get_contents(__DIR__ . '/../fixtures3/key.pub');
411+
$key = file_get_contents(__DIR__ . '/../fixtures/fixtures3/key.pub');
412412
$result = JWT::decode($token, new Key($key, 'RS256'));
413413

414414
$this->assertEquals($authUri, $result->aud);
@@ -509,7 +509,7 @@ public function testGetProjectId()
509509

510510
public function testGetQuotaProject()
511511
{
512-
$keyFile = __DIR__ . '/../fixtures' . '/private.json';
512+
$keyFile = __DIR__ . '/../fixtures/fixtures1/private.json';
513513
$sa = new ServiceAccountJwtAccessCredentials($keyFile);
514514
$this->assertEquals('test_quota_project', $sa->getQuotaProject());
515515
}

0 commit comments

Comments
 (0)