Completed
Push — master ( 9401a4...2cc7a2 )
by mw
13:59
created

JaCompoundGroupTokenizerTest::testTokenize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 2
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
		$instance = new JaCompoundGroupTokenizer();
32
33
		$this->assertEquals(
34
			$expected,
35
			$instance->tokenize( $string )
36
		);
37
	}
38
39
	public function testTokenizeWithOption() {
40
41
		$string = 'と歓声を上げていました';
42
43
		$tokenizer = $this->getMockBuilder( '\Onoi\Tesa\Tokenizer\Tokenizer' )
44
			->disableOriginalConstructor()
45
			->getMockForAbstractClass();
46
47
		$tokenizer->expects( $this->once() )
48
			->method( 'setOption' );
49
50
		$tokenizer->expects( $this->once() )
51
			->method( 'tokenize' )
52
			->with( $this->equalTo( $string ) )
53
			->will( $this->returnValue( array( $string ) ) );
54
55
		$instance = new JaCompoundGroupTokenizer( $tokenizer );
56
57
		$instance->setOption(
58
			JaCompoundGroupTokenizer::REGEX_EXEMPTION,
59
			array( 'Foo' )
60
		);
61
62
		$this->assertEquals(
63
			array( '歓声', '上' ),
64
			$instance->tokenize( $string )
65
		);
66
	}
67
68
	public function stringProvider() {
69
70
		$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...
71
			'と歓声を上げていました。 十勝農業改良普及センターによりますと',
72
			array( '歓声', '上', '十勝農業改良普及', 'センター' )
73
		);
74
75
		return $provider;
76
	}
77
78
}
79