1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace MyTester; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* One job of the test suite |
9
|
|
|
* |
10
|
|
|
* @author Jakub Konečný |
11
|
|
|
* @property-read string $name |
12
|
|
|
* @property-read callable $callback |
13
|
|
|
* @property-read array $params |
14
|
|
|
* @property-read bool|string $skip |
15
|
|
|
* @property-read string $result |
16
|
|
|
* @property-read string $output @internal |
17
|
|
|
*/ |
18
|
|
|
final class Job |
19
|
|
|
{ |
20
|
|
|
use \Nette\SmartObject; |
21
|
|
|
|
22
|
|
|
public const RESULT_PASSED = "passed"; |
23
|
|
|
public const RESULT_SKIPPED = "skipped"; |
24
|
|
|
public const RESULT_FAILED = "failed"; |
25
|
|
|
|
26
|
|
|
protected string $name; |
27
|
|
|
/** @var callable Task */ |
28
|
|
|
protected $callback; |
29
|
|
|
protected array $params = []; |
30
|
|
|
protected bool|string $skip; |
31
|
|
|
protected string $result = self::RESULT_PASSED; |
32
|
|
|
protected string $output = ""; |
33
|
|
|
|
34
|
1 |
|
public function __construct( |
35
|
|
|
string $name, |
36
|
|
|
callable $callback, |
37
|
|
|
array $params = [], |
38
|
|
|
bool|string $skip = false |
39
|
|
|
) { |
40
|
1 |
|
$this->name = $name; |
41
|
1 |
|
$this->callback = $callback; |
42
|
1 |
|
$this->params = $params; |
43
|
1 |
|
$this->skip = $skip; |
44
|
1 |
|
} |
45
|
|
|
|
46
|
1 |
|
protected function getName(): string |
47
|
|
|
{ |
48
|
1 |
|
return $this->name; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function getCallback(): callable |
52
|
|
|
{ |
53
|
|
|
return $this->callback; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function getParams(): array |
57
|
|
|
{ |
58
|
|
|
return $this->params; |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
protected function getSkip(): bool|string |
62
|
|
|
{ |
63
|
1 |
|
return $this->skip; |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
protected function getResult(): string |
67
|
|
|
{ |
68
|
1 |
|
return $this->result; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function getOutput(): string |
72
|
|
|
{ |
73
|
|
|
return $this->output; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Executes the task |
78
|
|
|
*/ |
79
|
1 |
|
public function execute(): void |
80
|
|
|
{ |
81
|
1 |
|
if ($this->skip) { |
82
|
1 |
|
$this->result = static::RESULT_SKIPPED; |
83
|
|
|
} else { |
84
|
1 |
|
ob_start(); |
85
|
1 |
|
call_user_func_array($this->callback, $this->params); |
86
|
|
|
/** @var string $output */ |
87
|
1 |
|
$output = ob_get_clean(); |
88
|
1 |
|
$failed = str_contains($output, " failed. "); |
89
|
1 |
|
if ($failed) { |
90
|
|
|
$this->result = static::RESULT_FAILED; |
91
|
|
|
} |
92
|
1 |
|
$this->output = $output; |
93
|
|
|
} |
94
|
1 |
|
} |
95
|
|
|
} |
96
|
|
|
|