-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestDocs.php
More file actions
84 lines (70 loc) · 1.92 KB
/
TestDocs.php
File metadata and controls
84 lines (70 loc) · 1.92 KB
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
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace ProcessMaker\Package\DockerExecutorNode;
use Illuminate\Console\Command;
use ProcessMaker\Models\Script;
use ProcessMaker\Models\User;
class TestDocs extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'docker-executor-node:test-docs {file} {--last}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Test examples in SDK docs';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$file = $fileContents = file_get_contents(
__DIR__ . '/../docs/sdk/' . $this->argument('file') . '.md'
);
if (preg_match_all('/```javascript[\r\n]+(.*?)```/s', $fileContents, $matches)) {
$codes = $matches[1];
}
if ($this->option('last')) {
$codes = array_slice($codes, -1);
}
try {
foreach ($codes as $code) {
$this->runCode($code);
}
} catch (\ProcessMaker\Exception\ScriptException $e) {
$stack = $e->getMessage();
$stack = explode("\n", $stack);
$stack = array_slice($stack, 0, 15);
$stack = implode("\n", $stack);
$this->info($stack);
}
}
private function runCode($code)
{
$script = Script::create([
'code' => $code,
'title' => '_temp',
'language' => 'javascript',
'run_as_user_id' => User::where('is_administrator', true)->first()->id,
'timeout' => 60,
]);
$result = $script->runScript([], []);
$script->delete();
$this->info(print_r($result, true));
}
}