No Description

IAMCredentialsTest.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /*
  3. * Copyright 2015 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. namespace Google\Auth\Tests;
  18. use Google\Auth\Credentials\IAMCredentials;
  19. use PHPUnit\Framework\TestCase;
  20. class IAMConstructorTest extends TestCase
  21. {
  22. /**
  23. * @expectedException InvalidArgumentException
  24. */
  25. public function testShouldFailIfSelectorIsNotString()
  26. {
  27. $notAString = new \stdClass();
  28. $iam = new IAMCredentials(
  29. $notAString,
  30. ''
  31. );
  32. }
  33. /**
  34. * @expectedException InvalidArgumentException
  35. */
  36. public function testShouldFailIfTokenIsNotString()
  37. {
  38. $notAString = new \stdClass();
  39. $iam = new IAMCredentials(
  40. '',
  41. $notAString
  42. );
  43. }
  44. public function testInitializeSuccess()
  45. {
  46. $this->assertNotNull(
  47. new IAMCredentials('iam-selector', 'iam-token')
  48. );
  49. }
  50. }
  51. class IAMUpdateMetadataCallbackTest extends TestCase
  52. {
  53. public function testUpdateMetadataFunc()
  54. {
  55. $selector = 'iam-selector';
  56. $token = 'iam-token';
  57. $iam = new IAMCredentials(
  58. $selector,
  59. $token
  60. );
  61. $update_metadata = $iam->getUpdateMetadataFunc();
  62. $this->assertInternalType('callable', $update_metadata);
  63. $actual_metadata = call_user_func($update_metadata,
  64. $metadata = array('foo' => 'bar'));
  65. $this->assertArrayHasKey(IAMCredentials::SELECTOR_KEY, $actual_metadata);
  66. $this->assertEquals(
  67. $actual_metadata[IAMCredentials::SELECTOR_KEY],
  68. $selector);
  69. $this->assertArrayHasKey(IAMCredentials::TOKEN_KEY, $actual_metadata);
  70. $this->assertEquals(
  71. $actual_metadata[IAMCredentials::TOKEN_KEY],
  72. $token);
  73. }
  74. }