| 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 |
|
| 18 |
namespace Google\Auth\Tests; |
| 19 |
|
| 20 |
use Google\Auth\Credentials\IAMCredentials; |
| 21 |
|
| 22 |
class IAMConstructorTest extends \PHPUnit_Framework_TestCase |
| 23 |
{ |
| 24 |
/** |
| 25 |
* @expectedException InvalidArgumentException |
| 26 |
*/ |
| 27 |
public function testShouldFailIfSelectorIsNotString() |
| 28 |
{ |
| 29 |
$notAString = new \stdClass(); |
| 30 |
$iam = new IAMCredentials( |
| 31 |
$notAString, |
| 32 |
"" |
| 33 |
); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* @expectedException InvalidArgumentException |
| 38 |
*/ |
| 39 |
public function testShouldFailIfTokenIsNotString() |
| 40 |
{ |
| 41 |
$notAString = new \stdClass(); |
| 42 |
$iam = new IAMCredentials( |
| 43 |
"", |
| 44 |
$notAString |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
public function testInitializeSuccess() |
| 49 |
{ |
| 50 |
$this->assertNotNull( |
| 51 |
new IAMCredentials("iam-selector", "iam-token") |
| 52 |
); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
class IAMUpdateMetadataCallbackTest extends \PHPUnit_Framework_TestCase |
| 57 |
{ |
| 58 |
public function testUpdateMetadataFunc() |
| 59 |
{ |
| 60 |
$selector = 'iam-selector'; |
| 61 |
$token = 'iam-token'; |
| 62 |
$iam = new IAMCredentials( |
| 63 |
$selector, |
| 64 |
$token |
| 65 |
); |
| 66 |
|
| 67 |
$update_metadata = $iam->getUpdateMetadataFunc(); |
| 68 |
$this->assertTrue(is_callable($update_metadata)); |
| 69 |
|
| 70 |
$actual_metadata = call_user_func($update_metadata, |
| 71 |
$metadata = array('foo' => 'bar')); |
| 72 |
$this->assertTrue( |
| 73 |
isset($actual_metadata[IAMCredentials::SELECTOR_KEY])); |
| 74 |
$this->assertEquals( |
| 75 |
$actual_metadata[IAMCredentials::SELECTOR_KEY], |
| 76 |
$selector); |
| 77 |
$this->assertTrue( |
| 78 |
isset($actual_metadata[IAMCredentials::TOKEN_KEY])); |
| 79 |
$this->assertEquals( |
| 80 |
$actual_metadata[IAMCredentials::TOKEN_KEY], |
| 81 |
$token); |
| 82 |
} |
| 83 |
} |
| 84 |
|