Google\Cloud\Iam\Iam::policy PHP Method

policy() public method

If a policy has already been retrieved from the API, it will be returned. To fetch a fresh copy of the policy, use {@see \Google\Cloud\Iam\Iam::reload()}. Example: $policy = $iam->policy();
public policy ( array $options = [] ) : array
$options array Configuration Options
return array An array of policy data
    public function policy(array $options = [])
    {
        if (!$this->policy) {
            $this->reload($options);
        }
        return $this->policy;
    }

Usage Example

 public function testSetPolicy()
 {
     $policies = $this->policies();
     $this->connection->getPolicy(Argument::any())->willReturn($policies[0]);
     $this->connection->setPolicy(Argument::withEntry('policy', $policies[1]))->willReturn($policies[1]);
     $iam = new Iam($this->connection->reveal(), self::RESOURCE);
     $oldPolicy = $iam->policy();
     $oldPolicy['bindings'][0]['members'][] = 'user:[email protected]';
     $iam->setPolicy($oldPolicy);
     $this->assertEquals($iam->policy(), $policies[1]);
 }