|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the daikon-cqrs/validize project. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Daikon\Tests\Validize\ValueObject; |
|
10
|
|
|
|
|
11
|
|
|
use Daikon\Interop\InvalidArgumentException; |
|
12
|
|
|
use Daikon\Validize\ValueObject\Severity; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
|
|
15
|
|
|
final class SeverityTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
1 |
|
public function testUnprocessed(): void |
|
18
|
|
|
{ |
|
19
|
1 |
|
$severity = Severity::fromNative(Severity::UNPROCESSED); |
|
20
|
1 |
|
$this->assertEquals(-1, $severity->toNative()); |
|
21
|
1 |
|
$this->assertEquals('-1', (string)$severity); |
|
22
|
1 |
|
$this->assertTrue($severity->isUnprocessed()); |
|
23
|
1 |
|
$this->assertEquals(Severity::unprocessed(), $severity); |
|
24
|
1 |
|
} |
|
25
|
|
|
|
|
26
|
1 |
|
public function testSuccess(): void |
|
27
|
|
|
{ |
|
28
|
1 |
|
$severity = Severity::fromNative(Severity::SUCCESS); |
|
29
|
1 |
|
$this->assertEquals(0, $severity->toNative()); |
|
30
|
1 |
|
$this->assertEquals('0', (string)$severity); |
|
31
|
1 |
|
$this->assertTrue($severity->isSuccess()); |
|
32
|
1 |
|
$this->assertEquals(Severity::success(), $severity); |
|
33
|
1 |
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
public function testSilent(): void |
|
36
|
|
|
{ |
|
37
|
1 |
|
$severity = Severity::fromNative(Severity::SILENT); |
|
38
|
1 |
|
$this->assertEquals(100, $severity->toNative()); |
|
39
|
1 |
|
$this->assertEquals('100', (string)$severity); |
|
40
|
1 |
|
$this->assertTrue($severity->isSilent()); |
|
41
|
1 |
|
$this->assertEquals(Severity::silent(), $severity); |
|
42
|
1 |
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
public function testNotice(): void |
|
45
|
|
|
{ |
|
46
|
1 |
|
$severity = Severity::fromNative(Severity::NOTICE); |
|
47
|
1 |
|
$this->assertEquals(200, $severity->toNative()); |
|
48
|
1 |
|
$this->assertEquals('200', (string)$severity); |
|
49
|
1 |
|
$this->assertTrue($severity->isNotice()); |
|
50
|
1 |
|
$this->assertEquals(Severity::notice(), $severity); |
|
51
|
1 |
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
public function testError(): void |
|
54
|
|
|
{ |
|
55
|
1 |
|
$severity = Severity::fromNative(Severity::ERROR); |
|
56
|
1 |
|
$this->assertEquals(300, $severity->toNative()); |
|
57
|
1 |
|
$this->assertEquals('300', (string)$severity); |
|
58
|
1 |
|
$this->assertTrue($severity->isError()); |
|
59
|
1 |
|
$this->assertEquals(Severity::error(), $severity); |
|
60
|
1 |
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
public function testCritical(): void |
|
63
|
|
|
{ |
|
64
|
1 |
|
$severity = Severity::fromNative(Severity::CRITICAL); |
|
65
|
1 |
|
$this->assertEquals(400, $severity->toNative()); |
|
66
|
1 |
|
$this->assertEquals('400', (string)$severity); |
|
67
|
1 |
|
$this->assertTrue($severity->isCritical()); |
|
68
|
1 |
|
$this->assertEquals(Severity::critical(), $severity); |
|
69
|
1 |
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
public function testFromNativeWithNull(): void |
|
72
|
|
|
{ |
|
73
|
1 |
|
$this->expectException(InvalidArgumentException::class); |
|
74
|
|
|
/** @psalm-suppress NullArgument */ |
|
75
|
1 |
|
Severity::fromNative(null); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
1 |
|
public function testFromNativeWithInvalidString(): void |
|
79
|
|
|
{ |
|
80
|
1 |
|
$this->expectException(InvalidArgumentException::class); |
|
81
|
1 |
|
Severity::fromNative('hello'); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|