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
*/
2023-02-14 16:31:03 -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 ;
2024-01-31 08:10:26 -07:00
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 );
}
2024-06-07 06:52:09 -07:00
2024-10-24 06:36:50 -07:00
// 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 " );
}
2024-06-07 06:52:09 -07:00
trait TestableReadline {
function testable_readline ( $prompt )
{
global $LINES ;
if ( $LINES && count ( $LINES ) > 0 ) {
return array_shift ( $LINES );
}
return readline ( $prompt );
}
}