JaCompoundGroupTokenizerTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 75
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testUnknownOption() 0 7 1
A testTokenize() 0 15 2
B testTokenizeWithOption() 0 34 2
A stringProvider() 0 9 1
1
<?php
2
3
namespace Onoi\Tesa\Tests;
4
5
use Onoi\Tesa\Tokenizer\JaCompoundGroupTokenizer;
6
7
/**
8
 * @covers \Onoi\Tesa\Tokenizer\JaCompoundGroupTokenizer
9
 * @group onoi-tesa
10
 *
11
 * @license GNU GPL v2+
12
 * @since 0.1
13
 *
14
 * @author mwjames
15
 */
16
class JaCompoundGroupTokenizerTest extends \PHPUnit_Framework_TestCase {
17
18
	public function testUnknownOption() {
19
20
		$this->assertInstanceOf(
21
			'\Onoi\Tesa\Tokenizer\JaCompoundGroupTokenizer',
22
			new JaCompoundGroupTokenizer()
23
		);
24
	}
25
26
	/**
27
	 * @dataProvider stringProvider
28
	 */
29
	public function testTokenize( $string, $expected ) {
30
31
		if ( version_compare( phpversion(), '5.4', '<' ) ) {
32
			$this->markTestSkipped(
33
				"Boo, PHP 5.3 returns with unexpected results"
34
			);
35
		}
36
37
		$instance = new JaCompoundGroupTokenizer();
38
39
		$this->assertEquals(
40
			$expected,
41
			$instance->tokenize( $string )
42
		);
43
	}
44
45
	public function testTokenizeWithOption() {
46
47
		if ( version_compare( phpversion(), '5.4', '<' ) ) {
48
			$this->markTestSkipped(
49
				"Ehh, PHP 5.3 returns with unexpected results"
50
			);
51
		}
52
53
		$string = 'と歓声を上げていました';
54
55
		$tokenizer = $this->getMockBuilder( '\Onoi\Tesa\Tokenizer\Tokenizer' )
56
			->disableOriginalConstructor()
57
			->getMockForAbstractClass();
58
59
		$tokenizer->expects( $this->once() )
60
			->method( 'setOption' );
61
62
		$tokenizer->expects( $this->once() )
63
			->method( 'tokenize' )
64
			->with( $this->equalTo( $string ) )
65
			->will( $this->returnValue( array( $string ) ) );
66
67
		$instance = new JaCompoundGroupTokenizer( $tokenizer );
68
69
		$instance->setOption(
70
			JaCompoundGroupTokenizer::REGEX_EXEMPTION,
71
			array( 'Foo' )
72
		);
73
74
		$this->assertEquals(
75
			array( '歓声', '上' ),
76
			$instance->tokenize( $string )
77
		);
78
	}
79
80
	public function stringProvider() {
81
82
		$provider[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$provider was never initialized. Although not strictly required by PHP, it is generally a good practice to add $provider = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
83
			'と歓声を上げていました。 十勝農業改良普及センターによりますと',
84
			array( '歓声', '上', '十勝農業改良普及', 'センター' )
85
		);
86
87
		return $provider;
88
	}
89
90
}
91