1 | <?php |
||
14 | class Saveonfailure implements \PHPUnit\Framework\TestListener { |
||
15 | |||
16 | /** |
||
17 | * Convert an attribute strigng from a relative to absolute, by providing a base_url |
||
18 | * @param string $attribute name of the attribute, e.g. src, href |
||
19 | * @param string $content the string where to do the change |
||
20 | * @param string $base_url |
||
21 | * @return string |
||
22 | */ |
||
23 | 8 | public static function to_absolute_attribute($attribute, $content, $base_url = NULL) |
|
27 | |||
28 | /** |
||
29 | * Check if a directory does not exist, create it, otherwise check if it is writable |
||
30 | * @param string $directory |
||
31 | * @throws Exception If directory is not writable |
||
32 | */ |
||
33 | 2 | public static function autocreate_directory($directory) |
|
34 | { |
||
35 | 2 | if ( ! file_exists($directory)) |
|
36 | { |
||
37 | 2 | mkdir($directory, 0777, TRUE); |
|
38 | } |
||
39 | |||
40 | 2 | if ( ! is_writable($directory)) |
|
41 | throw new \Exception("Directory \"{$directory}\" is not writable"); |
||
42 | 2 | } |
|
43 | |||
44 | /** |
||
45 | * Delete all the files from a directory |
||
46 | * @param string $directory |
||
47 | */ |
||
48 | 2 | public static function clear_directory($directory) |
|
49 | { |
||
50 | 2 | foreach (scandir($directory) as $file) |
|
51 | { |
||
52 | 2 | if ($file !== '.' AND $file !== '..') |
|
53 | { |
||
54 | 1 | unlink($directory.$file); |
|
55 | } |
||
56 | } |
||
57 | 2 | } |
|
58 | |||
59 | /** |
||
60 | * Execute a php script and get the output of that script as a string, optionally pass variables as an associative array to be converted to local variables inside of the file |
||
61 | * @param string $filename |
||
62 | * @param array $data |
||
63 | * @return string |
||
64 | */ |
||
65 | 1 | public static function render_file($filename, array $data = array()) |
|
73 | |||
74 | protected $_directory; |
||
75 | protected $_base_url; |
||
76 | |||
77 | 1 | function __construct($directory, $base_url) |
|
88 | |||
89 | /** |
||
90 | * Save the current content of the driver into an html file. Add javascript errors, messages and a title to the html content |
||
91 | * @param \Openbuildings\Spiderling\Driver $driver |
||
92 | * @param string $filename |
||
93 | * @param string $title |
||
94 | */ |
||
95 | 1 | public function save_driver_content(\Openbuildings\Spiderling\Driver $driver, $filename, $title) |
|
121 | |||
122 | /** |
||
123 | * Implement PHPUnit\Framework\TestListener, save driver content if there was an error |
||
124 | * @param \PHPUnit\Framework\Test $test |
||
125 | * @param \Exception $exception |
||
126 | * @param integer $time |
||
127 | */ |
||
128 | 1 | public function addError(\PHPUnit\Framework\Test $test, \Exception $exception, $time) |
|
139 | |||
140 | /** |
||
141 | * Implement PHPUnit\Framework\TestListener, save driver content if there was an error |
||
142 | * @param \PHPUnit\Framework\Test $test |
||
143 | * @param \PHPUnit\Framework\AssertionFailedError $failure |
||
144 | * @param integer $time |
||
145 | */ |
||
146 | 1 | public function addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\AssertionFailedError $failure, $time) |
|
158 | |||
159 | // @codeCoverageIgnoreStart |
||
160 | public function addWarning(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, $time) {} |
||
168 | // @codeCoverageIgnoreEnd |
||
169 | } |
||
170 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.