-
Notifications
You must be signed in to change notification settings - Fork 0
/
CliMultiProcess.php
86 lines (70 loc) · 2.26 KB
/
CliMultiProcess.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
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* JBZoo Toolbox - Cli
*
* This file is part of the JBZoo Toolbox project.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Cli
* @license MIT
* @copyright Copyright (C) JBZoo.com, All rights reserved.
* @link https://github.com/JBZoo/Cli
*/
declare(strict_types=1);
namespace JBZoo\PHPUnit;
use JBZoo\Utils\Env;
use function JBZoo\Data\json;
/**
* Class CliMultiProcess
* @package JBZoo\PHPUnit
*/
class CliMultiProcess extends PHPUnit
{
public function testAsRealExecution()
{
$start = microtime(true);
$result = Helper::executeReal('test:sleep-multi 123 " qwerty "', [
'sleep' => 1
], 'JBZOO_TEST_VAR=123456');
$time = microtime(true) - $start;
$outputAsArray = json($result[1])->getArrayCopy();
$expectecContent = implode("\n", [
'Sleep : 1',
'Arg #1: 123',
'Arg #2: qwerty ',
'Arg #3: QWERTY-3',
'Env Var: 123456',
]);
isSame([
"Started: 1\n{$expectecContent}\nFinished: 1",
"Started: 2\n{$expectecContent}\nFinished: 2",
"Started: 3\n{$expectecContent}\nFinished: 3",
"Started: 4\n{$expectecContent}\nFinished: 4",
"Started: 5\n{$expectecContent}\nFinished: 5",
], $outputAsArray);
isTrue($time < 5);
}
public function testAsVirtalExecution()
{
$start = microtime(true);
$result = Helper::executeVirtaul('test:sleep-multi', ['sleep' => 1]);
$time = microtime(true) - $start;
$outputAsArray = json($result)->getArrayCopy();
$expectecContent = implode("\n", [
'Sleep : 1',
'Arg #1: QWERTY-1',
'Arg #2: QWERTY-2',
'Arg #3: QWERTY-3',
'Env Var: ',
]);
isSame([
"Started: 1\n{$expectecContent}\nFinished: 1",
"Started: 2\n{$expectecContent}\nFinished: 2",
"Started: 3\n{$expectecContent}\nFinished: 3",
"Started: 4\n{$expectecContent}\nFinished: 4",
"Started: 5\n{$expectecContent}\nFinished: 5",
], $outputAsArray);
isTrue($time < 5);
}
}