-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathTestableReadline.php
42 lines (37 loc) · 1.39 KB
/
TestableReadline.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/**
* 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:
use function AwsUtilities\testable_readline;
* 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.
*/
namespace AwsUtilities;
function testable_readline($prompt)
{
global $LINES;
if ($LINES && count($LINES) > 0) {
return array_shift($LINES);
}
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);
}
}