forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorTestStorageEngine.php
54 lines (42 loc) · 1.12 KB
/
PhabricatorTestStorageEngine.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
<?php
/**
* Test storage engine. Does not actually store files. Used for unit tests.
*/
final class PhabricatorTestStorageEngine
extends PhabricatorFileStorageEngine {
private static $storage = array();
private static $nextHandle = 1;
public function getEngineIdentifier() {
return 'unit-test';
}
public function getEnginePriority() {
return 1000;
}
public function isTestEngine() {
return true;
}
public function canWriteFiles() {
return true;
}
public function hasFilesizeLimit() {
return false;
}
public function writeFile($data, array $params) {
AphrontWriteGuard::willWrite();
self::$storage[self::$nextHandle] = $data;
return (string)self::$nextHandle++;
}
public function readFile($handle) {
if (isset(self::$storage[$handle])) {
return self::$storage[$handle];
}
throw new Exception(pht("No such file with handle '%s'!", $handle));
}
public function deleteFile($handle) {
AphrontWriteGuard::willWrite();
unset(self::$storage[$handle]);
}
public function tamperWithFile($handle, $data) {
self::$storage[$handle] = $data;
}
}