Completed
Push — master ( 93e4df...65b5d6 )
by Jeroen De
01:49
created

ProcessingResultTest::testGetParameterArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 );
0 ignored issues
show
Documentation introduced by
$processedParams is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Par...cessor\ProcessedParam>>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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 );
0 ignored issues
show
Documentation introduced by
$errors is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Par...essor\ProcessingError>>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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
}