1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Valkyrja Framework package. |
7
|
|
|
* |
8
|
|
|
* (c) Melech Mizrachi <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Valkyrja\Test\Testers; |
15
|
|
|
|
16
|
|
|
use Closure; |
17
|
|
|
use Throwable; |
18
|
|
|
use Valkyrja\Test\Assert\Assert; |
19
|
|
|
use Valkyrja\Test\Output\Output; |
20
|
|
|
use Valkyrja\Test\Output\Results\Results; |
21
|
|
|
use Valkyrja\Test\Test as Contract; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class Test. |
25
|
|
|
* |
26
|
|
|
* @author Melech Mizrachi |
27
|
|
|
*/ |
28
|
|
|
class Test implements Contract |
29
|
|
|
{ |
30
|
|
|
public function __construct( |
31
|
|
|
protected string|null $name = null, |
32
|
|
|
protected Output|null $output = null, |
33
|
|
|
protected Assert $assert = new \Valkyrja\Test\Assert\Asserters\Assert(), |
34
|
|
|
protected bool $shouldSkip = false, |
35
|
|
|
) { |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @inheritDoc |
40
|
|
|
*/ |
41
|
|
|
public function getAssert(): Assert |
42
|
|
|
{ |
43
|
|
|
return $this->assert; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @inheritDoc |
48
|
|
|
*/ |
49
|
|
|
public function getName(): string |
50
|
|
|
{ |
51
|
|
|
return $this->name ?? ''; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @inheritDoc |
56
|
|
|
*/ |
57
|
|
|
public function shouldSkip(): bool |
58
|
|
|
{ |
59
|
|
|
return $this->shouldSkip; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @inheritDoc |
64
|
|
|
*/ |
65
|
|
|
public function run(Closure $closure, array $data = []): void |
66
|
|
|
{ |
67
|
|
|
$assert = $this->assert; |
68
|
|
|
$exception = null; |
69
|
|
|
|
70
|
|
|
try { |
71
|
|
|
$closure($assert, ...$data); |
72
|
|
|
} catch (Throwable $exception) { |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$assert->exceptions()->verify($exception); |
76
|
|
|
|
77
|
|
|
$this->output?->full(new Results([$this])); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|