|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ValueValidators\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use ValueValidators\Error; |
|
7
|
|
|
use ValueValidators\Result; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @covers \ValueValidators\Result |
|
11
|
|
|
* |
|
12
|
|
|
* @group ValueValidators |
|
13
|
|
|
* @group DataValueExtensions |
|
14
|
|
|
* |
|
15
|
|
|
* @license GPL-2.0+ |
|
16
|
|
|
* @author Daniel Kinzler |
|
17
|
|
|
*/ |
|
18
|
|
|
class ResultTest extends TestCase { |
|
19
|
|
|
|
|
20
|
|
|
public function testNewSuccess() { |
|
21
|
|
|
$result = Result::newSuccess(); |
|
22
|
|
|
|
|
23
|
|
|
$this->assertTrue( $result->isValid() ); |
|
24
|
|
|
$this->assertEmpty( $result->getErrors() ); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testNewError() { |
|
28
|
|
|
$result = Result::newError( [ |
|
29
|
|
|
Error::newError( 'foo' ), |
|
30
|
|
|
Error::newError( 'bar' ), |
|
31
|
|
|
] ); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertFalse( $result->isValid() ); |
|
34
|
|
|
$this->assertCount( 2, $result->getErrors() ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public static function provideMerge() { |
|
38
|
|
|
$errors = [ |
|
39
|
|
|
Error::newError( 'foo' ), |
|
40
|
|
|
Error::newError( 'bar' ), |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
return [ |
|
44
|
|
|
[ |
|
45
|
|
|
Result::newSuccess(), |
|
46
|
|
|
Result::newSuccess(), |
|
47
|
|
|
true, |
|
48
|
|
|
0, |
|
49
|
|
|
'success + success' |
|
50
|
|
|
], |
|
51
|
|
|
[ |
|
52
|
|
|
Result::newSuccess(), |
|
53
|
|
|
Result::newError( $errors ), |
|
54
|
|
|
false, |
|
55
|
|
|
2, |
|
56
|
|
|
'success + error' |
|
57
|
|
|
], |
|
58
|
|
|
[ |
|
59
|
|
|
Result::newSuccess(), |
|
60
|
|
|
Result::newError( $errors ), |
|
61
|
|
|
false, |
|
62
|
|
|
2, |
|
63
|
|
|
'error + success' |
|
64
|
|
|
], |
|
65
|
|
|
[ |
|
66
|
|
|
Result::newError( $errors ), |
|
67
|
|
|
Result::newError( $errors ), |
|
68
|
|
|
false, |
|
69
|
|
|
4, |
|
70
|
|
|
'error + error' |
|
71
|
|
|
], |
|
72
|
|
|
]; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @dataProvider provideMerge |
|
77
|
|
|
*/ |
|
78
|
|
|
public function testMerge( $a, $b, $expectedValid, $expectedErrorCount, $message ) { |
|
79
|
|
|
$result = Result::merge( $a, $b ); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertSame( $expectedValid, $result->isValid(), $message ); |
|
82
|
|
|
$this->assertCount( $expectedErrorCount, $result->getErrors(), $message ); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|