/**
  * Test getter/setter for dateMin property
  */
 public function testGetSetDateMin()
 {
     $this->assertNull($this->attribute->getDateMin());
     // Change value and assert new
     $date = new \DateTime();
     $this->assertEntity($this->attribute->setDateMin($date));
     $this->assertInstanceOf('DateTime', $this->attribute->getDateMin());
     $this->assertEquals($date, $this->attribute->getDateMin());
 }
 /**
  * {@inheritdoc}
  */
 public function guessConstraints(AbstractAttribute $attribute)
 {
     $constraints = array();
     if ('pim_catalog_date' === $attribute->getAttributeType()) {
         $min = $attribute->getDateMin();
         $max = $attribute->getDateMax();
     } else {
         $min = $attribute->getNumberMin();
         $max = $attribute->getNumberMax();
         if (false === $attribute->isNegativeAllowed() && ($min === null || $min < 0)) {
             $min = 0;
         }
     }
     if (null !== $min || null !== $max) {
         $constraints[] = new Range(array('min' => $min, 'max' => $max));
     }
     return $constraints;
 }
 /**
  * Generate a date product value data
  *
  * @param AbstractAttribute attribute
  *
  * @return string
  */
 protected function generateDateData(AbstractAttribute $attribute)
 {
     $date = $this->faker->dateTimeBetween($attribute->getDateMin(), $attribute->getDateMax());
     return $date->format('Y-m-d');
 }
 /**
  * Get extra data to store in version
  *
  * @param AbstractAttribute $attribute
  *
  * @return array
  */
 protected function getVersionedData(AbstractAttribute $attribute)
 {
     $dateMin = is_null($attribute->getDateMin()) ? '' : $attribute->getDateMin()->format(\DateTime::ISO8601);
     $dateMax = is_null($attribute->getDateMax()) ? '' : $attribute->getDateMax()->format(\DateTime::ISO8601);
     return array('available_locales' => $this->normalizeAvailableLocales($attribute), 'localizable' => $attribute->isLocalizable(), 'scope' => $attribute->isScopable() ? self::CHANNEL_SCOPE : self::GLOBAL_SCOPE, 'options' => $this->normalizeOptions($attribute), 'default_options' => $this->normalizeDefaultOptions($attribute), 'sort_order' => (int) $attribute->getSortOrder(), 'required' => (int) $attribute->isRequired(), 'default_value' => $this->normalizeDefaultValue($attribute), 'max_characters' => (string) $attribute->getMaxCharacters(), 'validation_rule' => (string) $attribute->getValidationRule(), 'validation_regexp' => (string) $attribute->getValidationRegexp(), 'wysiwyg_enabled' => (string) $attribute->isWysiwygEnabled(), 'number_min' => (string) $attribute->getNumberMin(), 'number_max' => (string) $attribute->getNumberMax(), 'decimals_allowed' => (string) $attribute->isDecimalsAllowed(), 'negative_allowed' => (string) $attribute->isNegativeAllowed(), 'date_min' => $dateMin, 'date_max' => $dateMax, 'metric_family' => (string) $attribute->getMetricFamily(), 'default_metric_unit' => (string) $attribute->getDefaultMetricUnit(), 'max_file_size' => (string) $attribute->getMaxFileSize());
 }
 /**
  * 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;
 }