-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-test.php
75 lines (62 loc) · 1.97 KB
/
run-test.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
<?php
/**
* Lanceur CLI
*/
use Touchweb\Waftest\MainTester;
require 'vendor/autoload.php';
if (PHP_SAPI != "cli") {
echo "Not in CLI\n";
exit;
}
if ($argc != 3) {
displayUsage();
}
$homeURL = trim($argv[1]);
if(! str_starts_with($homeURL, 'http://') && ! str_starts_with($homeURL, 'https://')){
echo "Bad URL format\n\n";
displayUsage();
}
if(str_ends_with($homeURL, "/")){
echo "PLEASE READ THE DOCUMENTATION CAREFULLY:\n\n";
displayUsage();
}
$tester = new MainTester();
$tester->setHomeURL($homeURL);
if($argv[2] !== 'ALL'){
// Lancement d'un seul test
runOneTest($tester, $homeURL, $argv[2]);
} else {
// Lancement successif de tous les tests
$testNames = $tester->getAllTestNames();
foreach ($testNames as $testName) {
runOneTest($tester, $homeURL, $testName);
}
}
/**
* Utilitaire; lance un test et affiche le résultat sur la console.
*/
function runOneTest(MainTester $tester, string $homeUrl, string $testName){
echo "Running test $testName on website $homeUrl... ";
$res = $tester->run($testName);
if($res['pass']){
echo "PASS (http ".$res['http_status'].")\n";
} else {
echo "FAIL (";
if($res['timeout']) echo "timeout";
else if(isset($res['http_status'])) echo $res['http_status'];
else if(isset($res['error_msg'])) echo $res['error_msg'];
else echo "failed silently";
echo ")\n";
}
}
/**
* Utilitaire; affiche comment utiliser le lanceur, et stoppe l'exécution.
*/
function displayUsage(){
echo "USAGE:\n";
echo " php run-test URL TESTCLASS-TESTNAME\n\n";
echo "WITH:\n";
echo " URL = Homepage URL of the website you want to test (WITH protocol but WITHOUT trailing slash)\n";
echo " TESTCLASS-TESTNAME = Name of the test to run (class name followed by function name in the definition class). Use ALL to launch all the tests successively\n\n";
exit;
}