public get_pro_suffix ( string $name ) : mixed | ||
$name | string | the name you wish to test |
Résultat | mixed | returns the suffix if exists, false otherwise |
public function get_pro_suffix($name)
{
$found_suffix_arr = array();
foreach ($this->dict['suffixes']['prof'] as $suffix) {
if (preg_match('/[,\\s]+' . preg_quote($suffix) . '\\b/i', $name, $matches)) {
$found_suffix = trim($matches[0]);
$found_suffix = rtrim($found_suffix, ',');
$found_suffix = ltrim($found_suffix, ',');
$found_suffix_arr[] = trim($found_suffix);
}
}
return $found_suffix_arr;
}
/** @test */ public function testProSuffix() { $parser = new FullNameParser(); $tests = ['Smarty Pants Phd' => 'Phd', 'Smarty Pants PHD' => 'PHD', 'OLD MACDONALD, PHD' => 'PHD']; $tests_no_match = ['OLD MACDONALD', 'OLD PHDMACDONALDPHD', 'Prof. Ron Brown']; foreach ($tests as $test => $expected_result) { $suffixes = $parser->get_pro_suffix($test); // $this->assertTrue(false !== array_search($expected_result, $suffixes)); $this->assertContains($expected_result, $suffixes); } foreach ($tests_no_match as $test) { $suffixes = $parser->get_pro_suffix($test); // Should get empty array $this->assertSame($suffixes, []); } }