|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Azine\HybridAuthBundle\Tests\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Azine\HybridAuthBundle\Services\AzineGenderGuesser; |
|
6
|
|
|
use Azine\HybridAuthBundle\Tests\AzineTestCase; |
|
7
|
|
|
|
|
8
|
|
|
class AzineGenderGuesserTest extends AzineTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function testGuess() |
|
11
|
|
|
{ |
|
12
|
|
|
$guesser = new AzineGenderGuesser(); |
|
13
|
|
|
$result = $guesser->guess('Patrick'); |
|
|
|
|
|
|
14
|
|
|
$this->assertSame('m', $result['gender']); |
|
15
|
|
|
$result = $guesser->guess('Tom'); |
|
|
|
|
|
|
16
|
|
|
$this->assertSame('m', $result['gender']); |
|
17
|
|
|
|
|
18
|
|
|
$result = $guesser->guess('Sonja'); |
|
|
|
|
|
|
19
|
|
|
$this->assertSame('f', $result['gender']); |
|
20
|
|
|
$result = $guesser->guess('Petra'); |
|
|
|
|
|
|
21
|
|
|
$this->assertSame('f', $result['gender']); |
|
22
|
|
|
|
|
23
|
|
|
$this->assertNull($guesser->guess(null)); |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testGender() |
|
27
|
|
|
{ |
|
28
|
|
|
$guesser = new AzineGenderGuesser(); |
|
29
|
|
|
$this->assertSame('m', $guesser->gender('Patrick')); |
|
|
|
|
|
|
30
|
|
|
$this->assertSame('m', $guesser->gender('Tom')); |
|
|
|
|
|
|
31
|
|
|
$this->assertSame('f', $guesser->gender('Sonja')); |
|
|
|
|
|
|
32
|
|
|
$this->assertSame('f', $guesser->gender('Petra')); |
|
|
|
|
|
|
33
|
|
|
$this->assertSame('', $guesser->gender('ertwerqwrfas')); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testGuesserWithOptions() |
|
37
|
|
|
{ |
|
38
|
|
|
$females = array('lkjlkjlkj' => 1); |
|
39
|
|
|
$males = array('oiuoiuoui' => 1); |
|
40
|
|
|
$matchList = array('one_only', |
|
41
|
|
|
'either_weight', |
|
42
|
|
|
'one_only_metaphone', |
|
43
|
|
|
'either_weight_metaphone', |
|
44
|
|
|
'v2_rules', |
|
45
|
|
|
'v1_rules', ); |
|
46
|
|
|
|
|
47
|
|
|
// use with extra names supplied via constructor |
|
48
|
|
|
$guesser = new AzineGenderGuesser($females, $males, true, $matchList); |
|
49
|
|
|
|
|
50
|
|
|
$result = $guesser->guess('oiuoiuoui'); |
|
|
|
|
|
|
51
|
|
|
$this->assertSame('m', $result['gender']); |
|
52
|
|
|
$result = $guesser->guess('Patrick'); |
|
|
|
|
|
|
53
|
|
|
$this->assertSame('m', $result['gender']); |
|
54
|
|
|
$result = $guesser->guess('Tom'); |
|
|
|
|
|
|
55
|
|
|
$this->assertSame('m', $result['gender']); |
|
56
|
|
|
|
|
57
|
|
|
$result = $guesser->guess('lkjlkjlkj'); |
|
|
|
|
|
|
58
|
|
|
$this->assertSame('f', $result['gender']); |
|
59
|
|
|
$result = $guesser->guess('Sonja'); |
|
|
|
|
|
|
60
|
|
|
$this->assertSame('f', $result['gender']); |
|
61
|
|
|
$result = $guesser->guess('Petra'); |
|
|
|
|
|
|
62
|
|
|
$this->assertSame('f', $result['gender']); |
|
63
|
|
|
|
|
64
|
|
|
// use only names supplied via constructor |
|
65
|
|
|
$guesser = new AzineGenderGuesser($females, $males, false, array('one_only')); |
|
66
|
|
|
|
|
67
|
|
|
$result = $guesser->guess('oiuoiuoui'); |
|
|
|
|
|
|
68
|
|
|
$this->assertSame('m', $result['gender']); |
|
69
|
|
|
|
|
70
|
|
|
$result = $guesser->guess('Patrick'); |
|
|
|
|
|
|
71
|
|
|
$this->assertNull($result); |
|
72
|
|
|
$result = $guesser->guess('Tom'); |
|
|
|
|
|
|
73
|
|
|
$this->assertNull($result); |
|
74
|
|
|
|
|
75
|
|
|
$result = $guesser->guess('lkjlkjlkj'); |
|
|
|
|
|
|
76
|
|
|
$this->assertSame('f', $result['gender']); |
|
77
|
|
|
|
|
78
|
|
|
$result = $guesser->guess('Sonja'); |
|
|
|
|
|
|
79
|
|
|
$this->assertNull($result); |
|
80
|
|
|
$result = $guesser->guess('Petra'); |
|
|
|
|
|
|
81
|
|
|
$this->assertNull($result); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testGuesserWithEitherWeight() |
|
85
|
|
|
{ |
|
86
|
|
|
$females = array(); |
|
87
|
|
|
$males = array(); |
|
88
|
|
|
$matchList = array('either_weight'); |
|
89
|
|
|
|
|
90
|
|
|
// use with extra names supplied via constructor |
|
91
|
|
|
$guesser = new AzineGenderGuesser($females, $males, false, $matchList); |
|
92
|
|
|
|
|
93
|
|
|
$result = $guesser->guess('Randy'); |
|
|
|
|
|
|
94
|
|
|
$this->assertSame('m', $result['gender']); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testGuesserWithRules1() |
|
98
|
|
|
{ |
|
99
|
|
|
$females = array(); |
|
100
|
|
|
$males = array(); |
|
101
|
|
|
$matchList = array('v1_rules'); |
|
102
|
|
|
|
|
103
|
|
|
// use with extra names supplied via constructor |
|
104
|
|
|
$guesser = new AzineGenderGuesser($females, $males, false, $matchList); |
|
105
|
|
|
|
|
106
|
|
|
$result = $guesser->guess('Randy'); |
|
|
|
|
|
|
107
|
|
|
$this->assertSame('m', $result['gender']); |
|
108
|
|
|
|
|
109
|
|
|
$result = $guesser->guess('Lois'); |
|
|
|
|
|
|
110
|
|
|
$this->assertSame('f', $result['gender']); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function testGuesserWithRules2() |
|
114
|
|
|
{ |
|
115
|
|
|
$females = array(); |
|
116
|
|
|
$males = array(); |
|
117
|
|
|
$matchList = array('v2_rules'); |
|
118
|
|
|
|
|
119
|
|
|
// use with extra names supplied via constructor |
|
120
|
|
|
$guesser = new AzineGenderGuesser($females, $males, false, $matchList); |
|
121
|
|
|
|
|
122
|
|
|
$result = $guesser->guess('John'); |
|
|
|
|
|
|
123
|
|
|
$this->assertSame('m', $result['gender']); |
|
124
|
|
|
$result = $guesser->guess('Anfernee'); |
|
|
|
|
|
|
125
|
|
|
$this->assertSame('m', $result['gender']); |
|
126
|
|
|
|
|
127
|
|
|
$result = $guesser->guess('Trish'); |
|
|
|
|
|
|
128
|
|
|
$this->assertSame('f', $result['gender']); |
|
129
|
|
|
$result = $guesser->guess('Ellie'); |
|
|
|
|
|
|
130
|
|
|
$this->assertSame('f', $result['gender']); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
View Code Duplication |
public function testGuesserWithMetaPhone() |
|
134
|
|
|
{ |
|
135
|
|
|
$females = array(); |
|
136
|
|
|
$males = array(); |
|
137
|
|
|
$matchList = array('one_only_metaphone'); |
|
138
|
|
|
|
|
139
|
|
|
// use with extra names supplied via constructor |
|
140
|
|
|
$guesser = new AzineGenderGuesser($females, $males, true, $matchList); |
|
141
|
|
|
|
|
142
|
|
|
$result = $guesser->guess('Patric'); |
|
|
|
|
|
|
143
|
|
|
$this->assertSame('m', $result['gender']); |
|
144
|
|
|
$result = $guesser->guess('Tomàs'); |
|
|
|
|
|
|
145
|
|
|
$this->assertSame('m', $result['gender']); |
|
146
|
|
|
|
|
147
|
|
|
$result = $guesser->guess('Sonja'); |
|
|
|
|
|
|
148
|
|
|
$this->assertSame('f', $result['gender']); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
View Code Duplication |
public function testGuesserWithMetaPhone2() |
|
152
|
|
|
{ |
|
153
|
|
|
$females = array(); |
|
154
|
|
|
$males = array(); |
|
155
|
|
|
$matchList = array('either_weight_metaphone'); |
|
156
|
|
|
|
|
157
|
|
|
// use with extra names supplied via constructor |
|
158
|
|
|
$guesser = new AzineGenderGuesser($females, $males, true, $matchList); |
|
159
|
|
|
|
|
160
|
|
|
$result = $guesser->guess('Patric'); |
|
|
|
|
|
|
161
|
|
|
$this->assertSame('m', $result['gender']); |
|
162
|
|
|
$result = $guesser->guess('Tomàs'); |
|
|
|
|
|
|
163
|
|
|
$this->assertSame('m', $result['gender']); |
|
164
|
|
|
|
|
165
|
|
|
$result = $guesser->guess('Sonja'); |
|
|
|
|
|
|
166
|
|
|
$this->assertSame('f', $result['gender']); |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: