1 |
6657531f
|
Andreas Kohlbecker
|
<?php
|
2 |
|
|
|
3 |
|
|
define("TEST_BASE_FOLDER", getcwd());
|
4 |
|
|
define("TEST_RESOURCES_FOLDER", TEST_BASE_FOLDER . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR);
|
5 |
|
|
|
6 |
|
|
class TestUtils {
|
7 |
|
|
static function load_from_json_resource($fileInTestResources) {
|
8 |
|
|
|
9 |
|
|
if (DIRECTORY_SEPARATOR == '/') {
|
10 |
|
|
$fileInTestResources = str_replace("\\", DIRECTORY_SEPARATOR, $fileInTestResources);
|
11 |
|
|
}
|
12 |
|
|
else {
|
13 |
|
|
$fileInTestResources = str_replace("/", DIRECTORY_SEPARATOR, $fileInTestResources);
|
14 |
|
|
}
|
15 |
|
|
|
16 |
|
|
$absoluteFilePath = TEST_RESOURCES_FOLDER . $fileInTestResources;
|
17 |
|
|
if (!is_file($absoluteFilePath)) {
|
18 |
|
|
TestUtils::stderr("ERROR: File '$absoluteFilePath' does not exist.");
|
19 |
|
|
}
|
20 |
|
|
if (!is_readable($absoluteFilePath)) {
|
21 |
|
|
TestUtils::stderr("ERROR: File '$absoluteFilePath' is not readable");
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
$datastr = file_get_contents($absoluteFilePath);
|
25 |
|
|
if (!is_string($datastr)) {
|
26 |
|
|
TestUtils::stderr("ERROR: File '$absoluteFilePath' is empty: $datastr");
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
$obj = json_decode($datastr);
|
30 |
|
|
|
31 |
|
|
if (!$obj) {
|
32 |
|
|
TestUtils::stderr("ERROR: File '$absoluteFilePath' contains invalid json");
|
33 |
|
|
}
|
34 |
|
|
return $obj;
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
static function stdout($string) {
|
38 |
|
|
file_put_contents("php://stdout", $string);
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
static function stderr($string) {
|
42 |
|
|
file_put_contents("php://stderr", $string);
|
43 |
|
|
}
|
44 |
|
|
}
|