Completed
Push — master ( ffb9d5...53fd21 )
by Jeroen De
01:42
created

IntegerTypeTest::testNegativeWithoutDefault()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace ParamProcessor\Tests\Integration\Types;
6
7
use ParamProcessor\ParameterTypes;
8
9
class IntegerTypeTest extends TypeTestBase {
10
11
	public function testPhpInteger() {
12
		$this->assertIntegerValidation( 42, 42 );
13
	}
14
15
	private function assertIntegerValidation( $expected, $input, array $definitionExtras = [] ) {
16
		$parameters = $this->process(
17
			[
18
				'amount' => array_merge(
19
					[
20
						'type' => ParameterTypes::INTEGER,
21
						'message' => 'test-message'
22
					],
23
					$definitionExtras
24
				)
25
			],
26
			[
27
				'amount' => $input,
28
			]
29
		)->getParameterArray();
30
31
		$this->assertSame( $expected, $parameters['amount'] );
32
	}
33
34
	public function testPhpIntegerDefaultsWhenExceedingUpperBound() {
35
		$this->assertIntegerValidation( 7, 42, [ 'upperbound' => 20, 'default' => 7 ] );
36
	}
37
38
	public function testPhpIntegerDefault() {
39
		$this->assertIntegerValidation( '7', 'NAN', [ 'default' => '7' ] );
40
	}
41
42
	public function testLowerBound() {
43
		$this->assertIntegerValidation( 7, '-1', [ 'lowerbound' => 0, 'default' => 7 ] );
44
	}
45
46
	public function testNegativeWithoutDefault() {
47
		$this->assertIntegerValidation( -1, '-1' );
48
	}
49
50
	public function testNegativeWithDefault() {
51
		$this->assertIntegerValidation( -1, '-1', [ 'default' => 7 ] );
52
	}
53
54
	public function testPhpIntegerWithDefault() {
55
		$this->assertIntegerValidation( 7, 42, [ 'default' => 7 ] );
56
	}
57
58
	public function testSmwOffsetDefinition() {
59
		$this->assertIntegerValidation(
60
			0,
61
			42,
62
			[
63
				'default' => 0,
64
				'negatives' => false,
65
				'upperbound' => 5000,
66
			]
67
		);
68
	}
69
70
}
71