SIGN IN SIGN UP

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.

0 0 1 Java
2022-06-30 08:58:16 -07:00
<?php
2022-07-05 15:19:01 -07:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
2022-06-30 08:58:16 -07:00
/**
2022-07-06 08:51:23 -07:00
* This is a helper function for command line programs to receive prefab input from a test.
* To use this function, place the following line at the beginning of your class:
2022-06-30 08:58:16 -07:00
use function AwsUtilities\testable_readline;
2022-07-06 08:51:23 -07:00
* Alternatively, add the following to your composer.json file:
"files": ["../../aws_utilities/TestableReadline.php"]
* Then, use testable_readline instead of readline. It will function the same as readline during command line
* interactions. To automate testing, add values to the global $argv array in the same order that they would be entered
* in the command line. They will be consumed and passed as the return value instead of requiring a user to manually
* type the values.
2022-06-30 08:58:16 -07:00
*/
namespace AwsUtilities;
2022-06-30 08:58:16 -07:00
function testable_readline($prompt)
{
2022-07-18 08:54:58 -07:00
global $LINES;
if ($LINES && count($LINES) > 0) {
2022-07-18 08:54:58 -07:00
return array_shift($LINES);
2022-06-30 08:58:16 -07:00
}
return readline($prompt);
}
// This is a helper function which makes it easy to ask the user to press enter to continue.
function pressEnter(){
testable_readline("Press enter to continue.\n");
}
trait TestableReadline {
function testable_readline($prompt)
{
global $LINES;
if ($LINES && count($LINES) > 0) {
return array_shift($LINES);
}
return readline($prompt);
}
}