/**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     switch ($operator) {
         case Operators::SINCE_LAST_JOB:
             if (!is_string($value)) {
                 throw InvalidArgumentException::stringExpected($field, 'filter', 'updated', gettype($value));
             }
             $this->addUpdatedSinceLastJob($field, $value);
             break;
         case Operators::SINCE_LAST_N_DAYS:
             if (!is_numeric($value)) {
                 throw InvalidArgumentException::numericExpected($field, 'filter', 'updated', gettype($value));
             }
             $this->addSinceLastNDays($field, $value);
             break;
         case Operators::NOT_BETWEEN:
             $values = $this->formatValues($field, $value);
             $field = current($this->qb->getRootAliases()) . '.' . $field;
             $this->applyNotBetweenFilter($field, $values);
             break;
         default:
             $value = Operators::IS_EMPTY === $operator ? null : $this->formatValues($field, $value);
             $field = current($this->qb->getRootAliases()) . '.' . $field;
             $this->qb->andWhere($this->prepareCriteriaCondition($field, $operator, $value));
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator && Operators::SINCE_LAST_JOB !== $operator && Operators::SINCE_LAST_N_DAYS !== $operator) {
         $value = $this->formatValues($field, $value);
     }
     if (Operators::SINCE_LAST_JOB === $operator) {
         if (!is_string($value)) {
             throw InvalidArgumentException::stringExpected($field, 'filter', 'updated', gettype($value));
         }
         $jobInstance = $this->jobInstanceRepository->findOneBy(['code' => $value]);
         $lastCompletedJobExecution = $this->jobRepository->getLastJobExecution($jobInstance, BatchStatus::COMPLETED);
         if (null === $lastCompletedJobExecution) {
             return $this;
         }
         $lastJobStartTime = $lastCompletedJobExecution->getStartTime()->setTimezone(new \DateTimeZone('UTC'));
         $value = $lastJobStartTime->getTimestamp();
         $operator = Operators::GREATER_THAN;
     }
     if (Operators::SINCE_LAST_N_DAYS === $operator) {
         if (!is_numeric($value)) {
             throw InvalidArgumentException::numericExpected($field, 'filter', 'updated', gettype($value));
         }
         $fromDate = new \DateTime(sprintf('%s days ago', $value), new \DateTimeZone('UTC'));
         $value = $fromDate->getTimestamp();
         $operator = Operators::GREATER_THAN;
     }
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     $this->applyFilter($field, $operator, $value);
     return $this;
 }
 /**
  * Check if data is valid
  *
  * @param AttributeInterface $attribute
  * @param mixed              $data
  */
 protected function checkData(AttributeInterface $attribute, $data)
 {
     if (null === $data) {
         return;
     }
     if (!is_string($data)) {
         throw InvalidArgumentException::stringExpected($attribute->getCode(), 'setter', 'reference data', gettype($data));
     }
 }
 /**
  * Check if value is a valid identifier
  *
  * @param string $field
  * @param mixed  $value
  * @param string $filter
  */
 public static function checkIdentifier($field, $value, $filter)
 {
     $invalidIdField = static::hasProperty($field) && static::getProperty($field) === 'id' && !is_numeric($value);
     $invalidDefaultField = !static::hasProperty($field) && !is_numeric($value);
     if ($invalidIdField || $invalidDefaultField) {
         throw InvalidArgumentException::numericExpected(static::getCode($field), 'filter', $filter, gettype($value));
     }
     $invalidStringField = static::hasProperty($field) && static::getProperty($field) !== 'id' && !is_string($value);
     if ($invalidStringField) {
         throw InvalidArgumentException::stringExpected(static::getCode($field), 'filter', $filter, gettype($value));
     }
 }
 function it_throws_an_exception_if_value_is_not_a_string(AttributeInterface $attribute)
 {
     $attribute->getCode()->willReturn('attributeCode');
     $this->shouldThrow(InvalidArgumentException::stringExpected('attributeCode', 'filter', 'string', gettype(123)))->during('addAttributeFilter', [$attribute, '=', 123, null, null, ['field' => 'attributeCode']]);
 }
 function it_throws_an_exception_if_value_is_not_valid(AttributeInterface $attribute)
 {
     $attribute->getCode()->willReturn('media_code');
     $value = ['data' => 132, 'unit' => 'foo'];
     $this->shouldThrow(InvalidArgumentException::stringExpected('media_code', 'filter', 'media', gettype($value)))->during('addAttributeFilter', [$attribute, '=', $value]);
 }
 /**
  * Check if data are valid
  *
  * @param string $field
  * @param mixed  $data
  */
 protected function checkData($field, $data)
 {
     if (!is_string($data) && null !== $data && '' !== $data) {
         throw InvalidArgumentException::stringExpected($field, 'setter', 'family', gettype($data));
     }
 }
 /**
  * @param AttributeInterface $attribute
  * @param mixed              $value
  */
 protected function checkValue(AttributeInterface $attribute, $value)
 {
     if (!is_string($value)) {
         throw InvalidArgumentException::stringExpected($attribute->getCode(), 'filter', 'media', gettype($value));
     }
 }
 /**
  * @param string $field
  * @param mixed  $value
  */
 protected function checkScalarValue($field, $value)
 {
     if (!is_string($value) && null !== $value) {
         throw InvalidArgumentException::stringExpected($field, 'filter', 'string', gettype($value));
     }
 }
 function it_checks_valid_data_format(ProductInterface $product)
 {
     $this->shouldThrow(InvalidArgumentException::stringExpected('variant_group', 'setter', 'variant_group', 'array'))->during('setFieldData', [$product, 'variant_group', ['not a string']]);
 }
 function it_throws_an_error_if_attribute_data_is_not_a_string_or_null(AttributeInterface $attribute, ProductInterface $product)
 {
     $attribute->getCode()->willReturn('attributeCode');
     $data = ['some', 'random', 'stuff'];
     $this->shouldThrow(InvalidArgumentException::stringExpected('attributeCode', 'setter', 'simple select', gettype($data)))->duringSetAttributeData($product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']);
 }
 function it_throws_an_exception_if_value_is_not_a_string_for_since_last_export()
 {
     $this->shouldThrow(InvalidArgumentException::stringExpected('updated', 'filter', 'updated', 'integer'))->during('addFieldFilter', ['updated', 'SINCE LAST JOB', 42, null, null]);
 }