-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.php
77 lines (63 loc) · 1.55 KB
/
run.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
if (count($argv) == 1)
{
echo "\nrun.php -u <api url> -t <test dir> -m <mock dir>\n\n";
exit(1);
}
// check user request help
if (isset($argv[1]) && $argv[1] == '-h')
{
echo "\n-------------------------------------------------\n\n";
echo "Welcome to our php api test engine!\n\n";
echo "Easy run a script with:\n\n";
echo "\trun.php -u <api url> -t <test dir> -m <mock dir>\n\n";
echo "Add some additinal information for benchmarking and multi requests:\n\n";
echo "\t-u <string>\t URL string of the API\n";
echo "\t-t <string>\t Directory of the tests JSON files\n";
echo "\t-m <number>\t Directory of the mock JSON files\n";
echo "\t-n <number>\t number of test rounds\n";
echo "\t-c <number>\t number of concurrency requests running at the same time\n";
echo "\n\n";
exit(0);
}
// load the class
require_once __DIR__.DIRECTORY_SEPARATOR.'test.class.php';
// setup a instance
$engine = new com\bp\APITestEngine();
$options = getopt("u:t:m:n:c:");
// set default API URL
if (isset($options['u']))
{
$engine->setAPIUrl($options['u']);
}
else
{
echo " - API URL missing \n";
}
// set mock direcotry
if (isset($options['m']))
{
$engine->setMockDir($options['m']);
}
if (isset($options['t']))
{
$n = isset($options['n']) ? (int)$options['n'] : 1;
$c = isset($options['c']) ? (int)$options['c'] : 1;
// read all tests inside the folder and do
$engine->run($options['t'], $n, $c);
// display the result
$engine->printResult();
if ($engine->fails() === 0)
{
exit(0);
}
else
{
exit(1);
}
}
else
{
echo " - Tests-Path missing \n";
exit(1);
}