/** * @param string|array $nameOrNames * @param string $country * @param string $language * @param int $hydration * @param array $apiResponse * @param string $expectedExceptionName * * @dataProvider recognizeProvider */ public function testRecognize($nameOrNames, $country, $language, $hydration, $apiResponse, $expectedExceptionName) { if ($expectedExceptionName) { $this->setExpectedException($expectedExceptionName); } $genderizerClientMock = m::mock('Jhg\\GenderizeIoClient\\HttpClient\\GenderizeClient'); $genderizerClientMock->shouldReceive('genderize')->andReturn($apiResponse); $genderizer = new Genderizer($genderizerClientMock); $returnedResults = $genderizer->recognize($nameOrNames, $country, $language, $hydration); if (is_array($nameOrNames)) { $this->assertEquals(sizeof($nameOrNames), sizeof($returnedResults)); } else { $returnedResults = [$returnedResults]; $apiResponse = [$apiResponse]; } foreach ($returnedResults as $i => $result) { switch ($hydration) { case Genderizer::HYDRATE_OBJECT: $this->assertNameObject($apiResponse[$i], $result); break; case Genderizer::HYDRATE_ARRAY: $this->assertEquals($apiResponse[$i], $result); break; default: $this->fail('Invalid hydration mode'); } } }
/** * @param string $name * @param string|null $country * @param string|null $language * * @return bool * @throws \Jhg\GenderizeIoClient\Exception\CountryNotValidException * @throws \Jhg\GenderizeIoClient\Exception\LanguageNotValidException */ public function isFemale($name, $country = null, $language = null) { $nameObj = $this->genderizer->recognize($name, $country, $language); return $nameObj->isFemale(); }