public function testWorkingWithRoles()
 {
     $roleName = 'php-integ-iam-test-role';
     self::log('Create an IAM Role.');
     $result = $this->iam->getCommand('CreateRole', array('RoleName' => $roleName, 'AssumeRolePolicyDocument' => self::IAM_POLICY_ASSUME_ROLE))->getResult();
     $roleArn = $result->getPath('Role/Arn');
     self::log('Put a policy on the IAM Role.');
     $result = $this->iam->getCommand('PutRolePolicy', array('PolicyName' => self::$policies[0], 'RoleName' => $roleName, 'PolicyDocument' => self::IAM_POLICY_ALLOW_S3))->getResult();
     self::log('Put another policy on the IAM Role.');
     $result = $this->iam->getCommand('PutRolePolicy', array('PolicyName' => self::$policies[1], 'RoleName' => $roleName, 'PolicyDocument' => self::IAM_POLICY_ALLOW_S3))->getResult();
     self::log('make sure the IAM Role exists.');
     // @TODO do a ListRoles-related assertion
     self::log('Make sure the policies are there.');
     //print_r($this->iam->listRolePolicies(array('RoleName' => $roleName))->toArray());
     $policies = $this->iam->getIterator('ListRolePolicies', array('RoleName' => $roleName));
     $this->assertEquals(self::$policies, iterator_to_array($policies));
     self::log('Delete the policies from the IAM Role.');
     $commands = array();
     foreach (self::$policies as $policy) {
         $commands[] = $this->iam->getCommand('DeleteRolePolicy', array('PolicyName' => $policy, 'RoleName' => $roleName));
     }
     $this->iam->execute($commands);
     self::log('Delete the IAM Role.');
     $result = $this->iam->getCommand('DeleteRole', array('RoleName' => $roleName))->getResult();
 }
 public function testBasicOperations()
 {
     $inputBucket = 'php-integ-transcoder-test-bucket-input';
     $outputBucket = 'php-integ-transcoder-test-bucket-output';
     $roleName = 'php-integ-transcoder-test-role';
     $policyName = 'php-integ-transcoder-test-policy';
     $pipelineName = 'php-integ-transcoder-test-pipeline';
     self::log('Create input and output buckets for the Elastic Transcoder pipeline.');
     $commands = array();
     $commands[] = $this->s3->getCommand('CreateBucket', array('Bucket' => $inputBucket));
     $commands[] = $this->s3->getCommand('CreateBucket', array('Bucket' => $outputBucket));
     $this->s3->execute($commands);
     self::log('Create an IAM Role for the Elastic Transcoder pipeline.');
     $result = $this->iam->getCommand('CreateRole', array('RoleName' => $roleName, 'AssumeRolePolicyDocument' => self::DUMMY_IAM_POLICY_ASSUME_ROLE))->getResult();
     $roleArn = $result->getPath('Role/Arn');
     self::log('Put a policy on the IAM Role for the Elastic Transcoder pipeline.');
     $result = $this->iam->getCommand('PutRolePolicy', array('PolicyName' => $policyName, 'RoleName' => $roleName, 'PolicyDocument' => self::DUMMY_IAM_POLICY_ALLOW_S3))->getResult();
     self::log('Use TestRole to validate our pipeline inputs. NOTE: Ours are not valid on purpose.');
     $result = $this->transcoder->getCommand('TestRole', array('InputBucket' => $inputBucket, 'OutputBucket' => $outputBucket, 'Role' => $roleArn, 'Topics' => array()))->getResult();
     $this->assertEquals('false', $result['Success']);
     self::log('Create an Elastic Transcoder pipeline.');
     $result = $this->transcoder->getCommand('CreatePipeline', array('Name' => $pipelineName, 'InputBucket' => $inputBucket, 'OutputBucket' => $outputBucket, 'Role' => $roleArn, 'Notifications' => array_fill_keys(array('Progressing', 'Completed', 'Warning', 'Error'), '')))->getResult();
     $pipelineId = $result->getPath('Pipeline/Id');
     self::log('Make sure created Elastic Transcoder pipeline is in the list of pipelines.');
     $result = $this->transcoder->getCommand('ListPipelines')->getResult();
     $pipelineNames = $result->getPath('Pipelines/*/Name');
     $this->assertContains($pipelineName, $pipelineNames);
     self::log('Make sure ListPipelines iterator works.');
     $found = false;
     foreach ($this->transcoder->getIterator('ListPipelines') as $pipeline) {
         if ($pipeline['Name'] == $pipelineName) {
             $found = true;
             break;
         }
     }
     if (!$found) {
         $this->fail('Did not find the pipeline in the iterator results.');
     }
     self::log('Make sure created Elastic Transcoder pipeline can be read.');
     $result = $this->transcoder->getCommand('ReadPipeline', array('Id' => $pipelineId))->getResult();
     $this->assertEquals($pipelineName, $result->getPath('Pipeline/Name'));
     self::log('Delete the Elastic Transcoder pipeline.');
     $response = $this->transcoder->getCommand('DeletePipeline', array('Id' => $pipelineId))->getResponse();
     $this->assertEquals(202, $response->getStatusCode());
     self::log('Delete the policy from the IAM Role for the Elastic Transcoder pipeline.');
     $result = $this->iam->getCommand('DeleteRolePolicy', array('PolicyName' => $policyName, 'RoleName' => $roleName))->getResult();
     self::log('Delete the IAM Role for the Elastic Transcoder pipeline.');
     $result = $this->iam->getCommand('DeleteRole', array('RoleName' => $roleName))->getResult();
     self::log('Delete the input and output buckets for the Elastic Transcoder pipeline.');
     $commands = array();
     $commands[] = $this->s3->getCommand('DeleteBucket', array('Bucket' => $inputBucket));
     $commands[] = $this->s3->getCommand('DeleteBucket', array('Bucket' => $outputBucket));
     $this->s3->execute($commands);
 }