-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestUtils.php
73 lines (65 loc) · 1.3 KB
/
TestUtils.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
<?php
namespace core;
use core\Cli;
use core\Curl;
use core\Helper;
trait TestUtils
{
// Get cURL instance
private function curl()
{
$c = new Curl();
$c->setJsonDecoder(function ($val) {
$res = json_decode($val, true);
return $res;
});
return $c;
}
private function exec_worker($name, array $args = [])
{
$param = array_merge([ROOT . "/workers/index.php", $name, "-i=1"], $args);
return Cli::exec("php", $param);
}
private function exec_cli($name, array $args = [])
{
$args = array_merge([$name], $args);
return Cli::exec("./run.sh", $args);
}
private static function pending($queue)
{
try {
$queue = Helper::prefix($queue);
return self::$queue->statsTube($queue)["current-jobs-ready"];
} catch (\Exception $e) {
return 0;
}
}
private static function buried($queue)
{
try {
$queue = Helper::prefix($queue);
return self::$queue->statsTube($queue)["current-jobs-buried"];
} catch (\Exception $e) {
return 0;
}
}
private static function verbose($task, $text, $iswrite = false)
{
$a = [
"test" => true,
"task" => $task,
"args" => [],
"flags" => [],
"today" => "2015-09-01"
];
if ($iswrite) {
$a["flags"]["w"] = true;
}
ob_start();
{
var_dump($a);
}
$txt = ob_get_clean();
return sprintf("%s%s\n", $txt, $text);
}
}