Completed
Push — master ( 1895e8...30a208 )
by Jeroen De
02:49
created

CompoundQueryProcessorTest::testSeparateParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SCQ\Tests;
4
5
use SCQ\CompoundQueryProcessor;
6
7
/**
8
 * @covers \SCQ\CompoundQueryProcessor
9
 * @group semantic-compound-queries
10
 *
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author Peter Grassberger < [email protected] >
15
 */
16
class CompoundQueryProcessorTest extends \PHPUnit_Framework_TestCase {
17
18
	/**
19
	 * Call protected/private method of a class.
20
	 *
21
	 * @param object &$object    Instantiated object that we will run method on.
22
	 * @param string $methodName Method name to call
23
	 * @param array  $parameters Array of parameters to pass into method.
24
	 *
25
	 * @return mixed Method return.
26
	 */
27
	public function invokeMethod( &$object, $methodName, array $parameters = [] ) {
28
29
		$reflection = new \ReflectionClass( get_class( $object ) );
30
		$method = $reflection->getMethod( $methodName );
31
		$method->setAccessible( true );
32
33
		return $method->invokeArgs( $object, $parameters );
34
	}
35
36
	public function testSeparateParams() {
37
		$params = [
38
			'[[Something in Square Brackets]]',
39
			'   [[More in Square Brackets with whitespace]]   ',
40
			'[[Square Brackets]]=with equals',
41
			'not in=square brackets',
42
			'   trim   =this',
43
			'don\'t trim=   this   ',
44
			'TOLOWERCASE=this',
45
		];
46
		$expected = [
47
			[
48
				'[[Something in Square Brackets]]',
49
				'   [[More in Square Brackets with whitespace]]   ',
50
				'[[Square Brackets]]=with equals',
51
			],
52
			[
53
				'not in' => 'square brackets',
54
				'trim'=> 'this',
55
				'don\'t trim' => '   this   ',
56
				'tolowercase' => 'this',
57
			]
58
		];
59
60
		$this->assertEquals( $expected, CompoundQueryProcessor::separateParams( $params ) );
61
	}
62
63
	public function testGetSubParams() {
64
		$param = 'split; trimsplit ;split;[don\'t;split];split;[[[don\'t;split]]];split;[[don\'t;split';
65
		$expected = [
66
			'split',
67
			'trimsplit',
68
			'split',
69
			'[don\'t;split]',
70
			'split',
71
			'[[[don\'t;split]]]',
72
			'split',
73
			'[[don\'t;split',
74
		];
75
76
		$processor = new CompoundQueryProcessor();
77
		$actual = $this->invokeMethod( $processor, 'getSubParams', [ $param ] );
78
		$this->assertEquals( $expected, $actual );
79
	}
80
81
}
82