Passed
Push — master ( d7fd6a...9124ff )
by Robbie
11:58
created

SynonymValidatorTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 82
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testItAllowsValidValues() 0 6 1
A tearDown() 0 4 1
A testItDisallowsInvalidValues() 0 6 1
A invalidValuesProvider() 0 4 1
A validValuesProvider() 0 12 1
1
<?php
2
3
class SynonymValidatorTest extends PHPUnit_Framework_TestCase {
4
	/**
5
	 * @var SynonymValidator
6
	 */
7
	protected $validator;
8
9
	/**
10
	 * @inheritdoc
11
	 */
12
	public function setUp() {
13
		parent::setUp();
14
15
		$this->validator = new SynonymValidator(array(
16
			'Synonyms',
17
		));
18
	}
19
20
	/**
21
	 * @inheritdoc
22
	 */
23
	public function tearDown() {
24
		$this->validator = null;
25
26
		parent::tearDown();
27
	}
28
29
	/**
30
	 * @dataProvider validValuesProvider
31
	 */
32
	public function testItAllowsValidValues($value) {
33
		$this->validator->php(array(
34
			'Synonyms' => $value,
35
		));
36
37
		$this->assertEmpty($this->validator->getErrors());
38
	}
39
40
	/**
41
	 * @return array
42
	 */
43
	public function validValuesProvider() {
44
		return array(
45
			array('foo'),
46
			array('foo,bar,baz'),
47
			array('foo, bar, baz'),
48
			array('
49
				foo
50
				bar
51
				baz
52
			'),
53
			array('foo => bar, baz'),
54
			array('
55
				# this is a comment, it should be ignored!
56
57
				foo, bar, baz
58
				foo => bar, baz
59
60
				# ...as should this.
61
			'),
62
		);
63
	}
64
65
	/**
66
	 * @dataProvider invalidValuesProvider
67
	 *
68
	 * @param string $value
69
	 */
70
	public function testItDisallowsInvalidValues($value) {
71
		$this->validator->php(array(
72
			'Synonyms' => $value,
73
		));
74
75
		$this->assertNotEmpty($this->validator->getErrors());
76
	}
77
78
	/**
79
	 * @return array
80
	 */
81
	public function invalidValuesProvider() {
82
		return array(
83
			array('foo, bar baz, qux'),
84
			array('foo => bar baz, qux')
85
		);
86
	}
87
}
88