Completed
Push — master ( 039b1a...93e4df )
by Jeroen De
01:39
created

ParameterTypesTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 63
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testAddType_defaultsAreSet() 0 29 1
A testRegisterType_parametersAreUsed() 0 29 1
1
<?php
2
3
namespace ParamProcessor\Tests\Unit;
4
5
use ParamProcessor\ParameterTypes;
6
use PHPUnit\Framework\TestCase;
7
use ValueParsers\NullParser;
8
use ValueValidators\NullValidator;
9
10
/**
11
 * @covers \ParamProcessor\ParameterTypes
12
 */
13
class ParameterTypesTest extends TestCase {
14
15
	public function testAddType_defaultsAreSet() {
16
		$types = new ParameterTypes();
17
18
		$types->addType(
19
			'kitten',
20
			[]
21
		);
22
23
		$type = $types->getType( 'kitten' );
24
25
		$this->assertSame(
26
			NullParser::class,
27
			$type->getStringParserClass()
28
		);
29
30
		$this->assertSame(
31
			NullParser::class,
32
			$type->getTypedParserClass()
33
		);
34
35
		$this->assertSame(
36
			NullValidator::class,
37
			$type->getValidatorClass()
38
		);
39
40
		$this->assertNull(
41
			$type->getValidationCallback()
42
		);
43
	}
44
45
	public function testRegisterType_parametersAreUsed() {
46
		$types = new ParameterTypes();
47
48
		$types->addType(
49
			'kitten',
50
			[
51
				'string-parser' => 'KittenParser',
52
				'validation-callback' => 'is_int',
53
				'validator' => 'KittenValidator',
54
			]
55
		);
56
57
		$type = $types->getType( 'kitten' );
58
59
		$this->assertSame(
60
			'KittenParser',
61
			$type->getStringParserClass()
62
		);
63
64
		$this->assertSame(
65
			'KittenValidator',
66
			$type->getValidatorClass()
67
		);
68
69
		$this->assertSame(
70
			'is_int',
71
			$type->getValidationCallback()
72
		);
73
	}
74
75
}
76