Completed
Push — master ( 83b1b2...0f3bb4 )
by mw
02:04
created

testTransliterationWithoutOptionFlag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Onoi\Tesa\Tests;
4
5
use Onoi\Tesa\Transliterator;
6
7
/**
8
 * @covers \Onoi\Tesa\Transliterator
9
 * @group onoi-tesa
10
 *
11
 * @license GNU GPL v2+
12
 * @since 0.1
13
 *
14
 * @author mwjames
15
 */
16
class TransliteratorTest extends \PHPUnit_Framework_TestCase {
17
18
	/**
19
	 * @dataProvider characterProvider
20
	 */
21
	public function testTransliteration( $input, $flag, $expected ) {
22
23
		$this->assertEquals(
24
			$expected,
25
			Transliterator::transliterate( $input, $flag )
26
		);
27
	}
28
29
	public function testTransliterationWithoutOptionFlag() {
30
31
		$this->assertEquals(
32
			'aaaaaea',
33
			Transliterator::transliterate( 'àáâãäå' )
34
		);
35
	}
36
37
	public function characterProvider() {
38
39
		$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...
40
			'Foo',
41
			'unknownFlag',
42
			'Foo',
43
		);
44
45
		$provider[] = array(
46
			'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž',
47
			Transliterator::NONE,
48
			'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž',
49
		);
50
51
		$provider[] = array(
52
			'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž',
53
			Transliterator::DIACRITICS,
54
			'AAAAAEAaaaaaeaOOOOOOEOoooooeoEEEEeeeeðCcÐIIIIiiiiUUUUEuuuueNnSsYyyZz'
55
		);
56
57
		$provider[] = array(
58
			'ỆᶍǍᶆṔƚÉ áéíóúýčďěňřšťžů',
59
			Transliterator::DIACRITICS,
60
			'ExAmPlE aeiouycdenrstzu'
61
		);
62
63
		$provider[] = array(
64
			'àáâãäå',
65
			Transliterator::DIACRITICS,
66
			'aaaaaea'
67
		);
68
69
		$provider[] = array(
70
			'èéêë',
71
			Transliterator::DIACRITICS,
72
			'eeee'
73
		);
74
75
		$provider[] = array(
76
			'òóôõö',
77
			Transliterator::DIACRITICS,
78
			'oooooe'
79
		);
80
81
		$provider[] = array(
82
			'ùúûü',
83
			Transliterator::DIACRITICS,
84
			'uuuue'
85
		);
86
87
		$provider[] = array(
88
			'ç',
89
			Transliterator::DIACRITICS,
90
			'c'
91
		);
92
93
		$provider[] = array(
94
			'æ',
95
			Transliterator::DIACRITICS,
96
			'ae'
97
		);
98
99
		$provider[] = array(
100
			'ñ',
101
			Transliterator::DIACRITICS,
102
			'n'
103
		);
104
105
		$provider[] = array(
106
			'œ',
107
			Transliterator::DIACRITICS,
108
			'oe'
109
		);
110
111
		$provider[] = array(
112
			'ýÿ',
113
			Transliterator::DIACRITICS,
114
			'yy'
115
		);
116
117
		$provider[] = array(
118
			'ß',
119
			Transliterator::DIACRITICS,
120
			'ss'
121
		);
122
123
		$provider[] = array(
124
			'Vilʹândimaa',
125
			Transliterator::DIACRITICS,
126
			'Vilʹandimaa'
127
		);
128
129
		$provider[] = array(
130
			'Ελληνική Δημοκρατία',
131
			Transliterator::GREEK,
132
			'Ellīnikī́ Dīmokratía'
133
		);
134
135
		$provider[] = array(
136
			'Ελληνική Δημοκρατία',
137
			Transliterator::DIACRITICS | Transliterator::GREEK,
138
			'Ellinikí Dimokratia'
139
		);
140
141
		$provider[] = array(
142
			'Γκ γκ γξ Ει ει Ηυ Μπ μπ',
143
			Transliterator::GREEK,
144
			'Gk gk gx Ei ei Īy Mp mp'
145
		);
146
147
		$provider[] = array(
148
			'Μετατροπή του ελληνικού αλφαβήτου με λατινικούς χαρακτήρες',
149
			Transliterator::GREEK,
150
			'Metatropī́ tou ellīnikoú alfavī́tou me latinikoús charaktī́res',
151
		);
152
153
		$provider[] = array(
154
			'Ελληνικός Οργανισμός Τυποποίησης',
155
			Transliterator::GREEK,
156
			'Ellīnikós Organismós Typopoíīsīs',
157
		);
158
159
		return $provider;
160
	}
161
162
}
163