-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuimaker
48 lines (38 loc) · 1.23 KB
/
uimaker
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
43
44
45
46
47
48
<?php
/**
* REPL `uitest`
*
*
* @package UITesting
* @version 1.0.0
* @author Rafael Moran <ralphmoran2003@gmail.com>
*/
// Only works in terminal mode.
if ( ! defined('STDIN') )
exit("REPL uitest only works on terminal mode.");
require_once 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();
// Extract options: make|m, name|n, path|p from CLI
extract( getopt("m:n::p::", [
"make:", // TODO: Add support for different types of creations.
"name::",
"path::",
]
)
);
$name = ( isset($name) ) ? $name : ( isset($n) ? $n : "" ) ;
$path_tests = ( isset($path) ) ? $path : ( isset($p) ? $p : $_ENV['PATH_TESTS'] ) ;
$test_name = trim( $name ) . $_ENV['TEST_CASE_PREFIX'] . time() . mt_rand(0, 100);
// Clean test name
$test_name = preg_replace('/[^A-Za-z0-9\_]/', '', $test_name);
// Validate path
if( ! is_dir($path_tests) )
exit('ERROR: Path does not exist.');
// Replace tags in template
$new_test_case = str_replace(
"<%test_name%>",
$test_name,
file_get_contents($_ENV['TEST_CASE_TEMPLATE'])
);
file_put_contents(rtrim($path_tests, "/") . "/" . $test_name . ".php", $new_test_case, LOCK_EX);