Example #1
0
 /**
  * (Required) Country code.
  * Character length and limitations: 2 single-byte characters
  *
  * @param $country
  * @throws Exception
  */
 public function setCountry($country)
 {
     if (strlen($country) > 2) {
         $country = CountryCodes::getCodeByName($country);
     }
     if (!CountryCodes::isValid($country)) {
         /*
          * @todo create Exception class for InvalidCountry
          */
         throw new \Exception('Invalid country specified in ' . get_class($this));
     }
     $this->setCountryCode($country);
     return $this;
 }
 public function testCountryIsValid()
 {
     $this->assertTrue(CountryCodes::isValid('US'));
     $this->assertTrue(CountryCodes::isValid('UNITED STATES'));
     $this->assertFalse(CountryCodes::isValid('California'));
 }