append(new Result(['foo' => 'bar'])); // You can provide a function to invoke; here we throw a mock exception $mock->append(function (CommandInterface $cmd, RequestInterface $req) { return new AwsException('Mock exception', $cmd); }); // Create a client with the mock handler $client = new DynamoDbClient([ 'region' => 'us-west-2', 'version' => 'latest', 'handler' => $mock ]); // Result object response will contain ['foo' => 'bar'] $result = $client->listTables(); // This will throw the exception that was enqueued $client->listTables(); // snippet-end:[dynamodb.php.mock_handler.main] // snippet-end:[dynamodb.php.mock_handler.complete] // snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.] // snippet-sourcedescription:[MockHandler.php demonstrates how to list tables in an Amazon DynamoDB database.] // snippet-keyword:[PHP] // snippet-sourcesyntax:[php] // snippet-keyword:[AWS SDK for PHP v3] // snippet-keyword:[Code Sample] // snippet-keyword:[Amazon DynamoDB] // snippet-keyword:[MockHandler] // snippet-service:[dynamodb] // snippet-sourcetype:[full-example] // snippet-sourcedate:[] // snippet-sourceauthor:[jschwarzwalder (AWS)]