/**
  * {@inheritdoc}
  */
 public function guessConstraints(AbstractAttribute $attribute)
 {
     $constraints = array();
     if ('regexp' === $attribute->getValidationRule() && ($pattern = $attribute->getValidationRegexp())) {
         $constraints[] = new Assert\Regex(array('pattern' => $pattern));
     }
     return $constraints;
 }
 /**
  * {@inheritdoc}
  */
 public function guessConstraints(AbstractAttribute $attribute)
 {
     $constraints = array();
     if ('email' === $attribute->getValidationRule()) {
         $constraints[] = new Assert\Email();
     }
     return $constraints;
 }
 /**
  * Test getter/setter for validationRule property
  */
 public function testGetSetValidationRule()
 {
     $this->assertNull($this->attribute->getValidationRule());
     // Change value and assert new
     $rule = 'email';
     $this->assertEntity($this->attribute->setValidationRule($rule));
     $this->assertEquals($rule, $this->attribute->getValidationRule());
 }
 /**
  * Generate a varchar product value data
  *
  * @param AbstractAttribute attribute
  *
  * @return string
  */
 protected function generateVarcharData(AbstractAttribute $attribute)
 {
     $validationRule = $attribute->getValidationRule();
     switch ($validationRule) {
         case 'url':
             $varchar = $this->faker->url();
             break;
         default:
             $varchar = $this->faker->sentence();
             break;
     }
     return $varchar;
 }
 /**
  * Generate value content based on backend type
  *
  * @param AbstractAttribute $attribute
  * @param string            $key
  *
  * @return string
  */
 protected function generateValueData(AbstractAttribute $attribute, $key)
 {
     $data = "";
     if (isset($this->forcedValues[$attribute->getCode()])) {
         return $this->forcedValues[$attribute->getCode()];
     }
     switch ($attribute->getBackendType()) {
         case "varchar":
             $validationRule = $attribute->getValidationRule();
             switch ($validationRule) {
                 case 'url':
                     $data = $this->faker->url();
                     break;
                 default:
                     $data = $this->faker->sentence();
                     break;
             }
             break;
         case "text":
             $data = $this->faker->sentence();
             break;
         case "date":
             $data = $this->faker->dateTimeBetween($attribute->getDateMin(), $attribute->getDateMax());
             $data = $data->format('Y-m-d');
             break;
         case "metric":
         case "decimal":
         case "prices":
             if ($attribute->getBackendType() && preg_match('/-' . self::METRIC_UNIT . '$/', $key)) {
                 $data = $attribute->getDefaultMetricUnit();
             } else {
                 $min = $attribute->getNumberMin() != null ? $attribute->getNumberMin() : self::DEFAULT_NUMBER_MIN;
                 $max = $attribute->getNumberMax() != null ? $attribute->getNumberMax() : self::DEFAULT_NUMBER_MAX;
                 $decimals = $attribute->isDecimalsAllowed() ? self::DEFAULT_NB_DECIMALS : 0;
                 $data = $this->faker->randomFloat($decimals, $min, $max);
             }
             break;
         case "boolean":
             $data = $this->faker->boolean() ? "1" : "0";
             break;
         case "option":
         case "options":
             $options = [];
             foreach ($attribute->getOptions() as $option) {
                 $options[] = $option;
             }
             $option = $this->faker->randomElement($options);
             if (is_object($option)) {
                 $data = $option->getCode();
             }
             break;
         default:
             $data = '';
             break;
     }
     return (string) $data;
 }