/**
  * Tests isFemale method
  */
 public function testIsFemale()
 {
     $extension = new GenderizeExtension($this->genderizerMock);
     $this->genderizerMock->shouldReceive('recognize')->andReturn(Name::factory(['name' => 'John', 'gender' => 'female']));
     $this->assertTrue($extension->isFemale('John', 'gb', 'en'));
 }
 /**
  * Test factory with all data
  */
 public function testFactoryWithCompleteData()
 {
     $data = ['name' => 'Mery', 'gender' => 'female', 'count' => 40, 'probability' => 0.48, 'country_id' => 'gb', 'language_id' => 'en'];
     $name = Name::factory($data);
     $this->assertEquals('Mery', $name->getName());
     $this->assertEquals('female', $name->getGender());
     $this->assertEquals(40, $name->getCount());
     $this->assertEquals('gb', $name->getCountry());
     $this->assertEquals('en', $name->getLanguage());
     $this->assertEquals(0.48, $name->getProbability());
     $this->assertFalse($name->isMale());
     $this->assertTrue($name->isFemale());
     $this->assertFalse($name->isUnkwown());
 }
 /**
  * @param string|array $nameOrNames
  * @param string|null  $country
  * @param string|null  $language
  * @param int          $hydration
  *
  * @return Name|array
  *
  * @throws CountryNotValidException
  * @throws LanguageNotValidException
  */
 public function recognize($nameOrNames, $country = null, $language = null, $hydration = self::HYDRATE_OBJECT)
 {
     if ($country !== null && !isset($this->validCountries[strtoupper($country)])) {
         throw new CountryNotValidException(sprintf('Country %s is not valid', strtoupper($country)));
     }
     if ($language !== null && !isset($this->validLanguages[strtolower($language)])) {
         throw new LanguageNotValidException(sprintf('Language %s is not valid', strtolower($language)));
     }
     $query = ['name' => $nameOrNames];
     if ($this->apiKey !== null) {
         $query['apikey'] = $this->apiKey;
     }
     if ($country !== null) {
         $query['country_id'] = $country;
     }
     if ($language !== null) {
         $query['language_id'] = $language;
     }
     $data = $this->genderizeClient->genderize($query);
     if ($hydration == self::HYDRATE_OBJECT) {
         if (is_array($nameOrNames)) {
             $collection = [];
             foreach ($data as $nameData) {
                 $collection[] = Name::factory($nameData);
             }
             // multiple query
             return $collection;
         } else {
             // single query
             return Name::factory($data);
         }
     } else {
         // multiple or single query
         return $data;
     }
 }