Project

General

Profile

Download (1.28 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
		} else {
12
			$fileInTestResources = str_replace("/", DIRECTORY_SEPARATOR, $fileInTestResources);
13
		}
14

    
15
		$absoluteFilePath = TEST_RESOURCES_FOLDER .  $fileInTestResources;
16
	   if(!is_file($absoluteFilePath)){
17
	   	TestUtils::stderr ("ERROR: File '$absoluteFilePath' does not exist.");
18
	   }
19
	   if(!is_readable($absoluteFilePath)){
20
	   	TestUtils::stderr ("ERROR: File '$absoluteFilePath' is not readable");
21
	   }
22

    
23
		$datastr = file_get_contents($absoluteFilePath);
24
		if(!is_string($datastr)){
25
			TestUtils::stderr ("ERROR: File '$absoluteFilePath' is empty: $datastr");
26
		}
27

    
28
		$obj = json_decode($datastr);
29

    
30
		if(!$obj){
31
      TestUtils::stderr ("ERROR: File '$absoluteFilePath' contains invalid json");
32
    }
33
	  return $obj;
34
  }
35

    
36
  static function stdout($string){
37
  	file_put_contents("php://stdout", $string);
38
  }
39

    
40
  static function stderr($string){
41
    file_put_contents("php://stderr", $string);
42
  }
43
}
(1-1/4)