1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ParamProcessor\Tests\Unit; |
4
|
|
|
|
5
|
|
|
use ParamProcessor\ProcessedParam; |
6
|
|
|
use ParamProcessor\ProcessingError; |
7
|
|
|
use ParamProcessor\ProcessingResult; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers \ParamProcessor\ProcessingResult |
12
|
|
|
* |
13
|
|
|
* @licence GNU GPL v2+ |
14
|
|
|
* @author Jeroen De Dauw < [email protected] > |
15
|
|
|
*/ |
16
|
|
|
class ProcessingResultTest extends TestCase { |
17
|
|
|
|
18
|
|
|
public function testGetParameters() { |
19
|
|
|
$processedParams = [ |
20
|
|
|
$this->createMock( ProcessedParam::class ) |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
$result = new ProcessingResult( $processedParams ); |
|
|
|
|
24
|
|
|
|
25
|
|
|
$this->assertEquals( $processedParams, $result->getParameters() ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testGetErrors() { |
29
|
|
|
$errors = [ |
30
|
|
|
$this->createMock( ProcessingError::class ) |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
$result = new ProcessingResult( [], $errors ); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$this->assertEquals( $errors, $result->getErrors() ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testGivenNoErrors_HasNoFatal() { |
39
|
|
|
$this->assertNoFatalForErrors( [] ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
private function assertNoFatalForErrors( array $errors ) { |
43
|
|
|
$result = new ProcessingResult( [], $errors ); |
44
|
|
|
|
45
|
|
|
$this->assertFalse( $result->hasFatal() ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testGivenNonfatalErrors_HasNoFatal() { |
49
|
|
|
$this->assertNoFatalForErrors( [ |
50
|
|
|
new ProcessingError( '', ProcessingError::SEVERITY_HIGH ), |
51
|
|
|
new ProcessingError( '', ProcessingError::SEVERITY_LOW ), |
52
|
|
|
new ProcessingError( '', ProcessingError::SEVERITY_MINOR ), |
53
|
|
|
new ProcessingError( '', ProcessingError::SEVERITY_NORMAL ), |
54
|
|
|
] ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testGivenFatalError_HasFatal() { |
58
|
|
|
$result = new ProcessingResult( [], [ |
59
|
|
|
new ProcessingError( '', ProcessingError::SEVERITY_HIGH ), |
60
|
|
|
new ProcessingError( '', ProcessingError::SEVERITY_LOW ), |
61
|
|
|
new ProcessingError( '', ProcessingError::SEVERITY_FATAL ), |
62
|
|
|
new ProcessingError( '', ProcessingError::SEVERITY_MINOR ), |
63
|
|
|
new ProcessingError( '', ProcessingError::SEVERITY_NORMAL ), |
64
|
|
|
] ); |
65
|
|
|
|
66
|
|
|
$this->assertTrue( $result->hasFatal() ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGetParameterArrayWithNoParameters() { |
70
|
|
|
$this->assertSame( |
71
|
|
|
[], |
72
|
|
|
( new ProcessingResult( [] ) )->getParameterArray() |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testGetParameterArray() { |
77
|
|
|
$this->assertSame( |
78
|
|
|
[ |
79
|
|
|
'first' => 42, |
80
|
|
|
'second' => 23, |
81
|
|
|
], |
82
|
|
|
( new ProcessingResult( [ |
83
|
|
|
new ProcessedParam( 'first', 42, false ), |
84
|
|
|
new ProcessedParam( 'second', 23, true ) |
85
|
|
|
] ) )->getParameterArray() |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: