public function testUtilities() { $data = []; $data['iso3'] = 'TST'; $data['iso2'] = 'TS'; $data['countryName'] = 'TEST'; $newCountry = new Country(); $newCountry->populate($data); $this->assertEquals($data['iso3'], $newCountry->getIso3()); $this->assertEquals($data['iso2'], $newCountry->getIso2()); $this->assertEquals($data['countryName'], $newCountry->getCountryName()); $secCountry = new Country(); $secCountry->populateFromObject($newCountry); $this->assertEquals($newCountry->getIso3(), $secCountry->getIso3()); $this->assertEquals($newCountry->getIso2(), $secCountry->getIso2()); $this->assertEquals($newCountry->getCountryName(), $secCountry->getCountryName()); $json = json_encode($secCountry); $this->assertJson($json); $iterator = $secCountry->getIterator(); $this->assertInstanceOf('\\ArrayIterator', $iterator); $array = $secCountry->toArray(); $this->assertEquals($data['iso3'], $array['iso3']); $this->assertEquals($data['iso2'], $array['iso2']); $this->assertEquals($data['countryName'], $array['countryName']); }
/** * populate @todo some properties are missing * * @param array $data * @param array $ignore * * @return void */ public function populate(array $data, array $ignore = []) { if (!empty($data['siteId']) && !in_array('siteId', $ignore)) { $this->setSiteId($data['siteId']); } if (!empty($data['domain']) && $data['domain'] instanceof Domain && !in_array('domain', $ignore)) { $this->setDomain($data['domain']); } if (!empty($data['domain']) && is_array($data['domain']) && !in_array('domain', $ignore)) { // is this right? $domain = new Domain(); $domain->populate($data['domain']); $this->setDomain($domain); } if (!empty($data['theme']) && !in_array('theme', $ignore)) { $this->setTheme($data['theme']); } if (!empty($data['siteLayout']) && !in_array('siteLayout', $ignore)) { $this->setSiteLayout($data['siteLayout']); } if (!empty($data['siteTitle']) && !in_array('siteTitle', $ignore)) { $this->setSiteTitle($data['siteTitle']); } if (!empty($data['language']) && $data['language'] instanceof Language && !in_array('language', $ignore)) { $this->setLanguage($data['language']); } if (!empty($data['language']) && is_array($data['language']) && !in_array('language', $ignore)) { $language = new Language(); $language->populate($data['language']); $this->setLanguage($language); } if (!empty($data['country']) && $data['country'] instanceof Country && !in_array('country', $ignore)) { $this->setCountry($data['country']); } if (!empty($data['country']) && is_array($data['country']) && !in_array('country', $ignore)) { $country = new Country(); $country->populate($data['country']); $this->setCountry($country); } if (!empty($data['status']) && !in_array('status', $ignore)) { $this->setStatus($data['status']); } if (!empty($data['favIcon']) && !in_array('favIcon', $ignore)) { $this->setFavIcon($data['favIcon']); } if (!empty($data['loginPage']) && !in_array('loginPage', $ignore)) { $this->setLoginPage($data['loginPage']); } if (!empty($data['notAuthorizedPage']) && !in_array('notAuthorizedPage', $ignore)) { $this->setNotAuthorizedPage($data['notAuthorizedPage']); } if (!empty($data['notFoundPage']) && !in_array('notFoundPage', $ignore)) { $this->setNotFoundPage($data['notFoundPage']); } if (!empty($data['supportedPageTypes']) && !in_array('supportedPageTypes', $ignore)) { $this->setSupportedPageTypes($data['supportedPageTypes']); } }