function it_throws_an_exception_if_value_is_not_an_valid_array(AttributeInterface $attribute)
 {
     $attribute->getCode()->willReturn('metric_code');
     $value = ['unit' => 'foo'];
     $this->shouldThrow(InvalidArgumentException::arrayKeyExpected('metric_code', 'data', 'filter', 'metric', print_r($value, true)))->during('addAttributeFilter', [$attribute, '=', $value]);
     $value = ['data' => 459];
     $this->shouldThrow(InvalidArgumentException::arrayKeyExpected('metric_code', 'unit', 'filter', 'metric', print_r($value, true)))->during('addAttributeFilter', [$attribute, '=', $value]);
     $value = ['data' => 'foo', 'unit' => 'foo'];
     $this->shouldThrow(InvalidArgumentException::arrayNumericKeyExpected('metric_code', 'data', 'filter', 'metric', 'string'))->during('addAttributeFilter', [$attribute, '=', $value]);
     $value = ['data' => 132, 'unit' => 42];
     $this->shouldThrow(InvalidArgumentException::arrayStringKeyExpected('metric_code', 'unit', 'filter', 'metric', 'integer'))->during('addAttributeFilter', [$attribute, '=', $value]);
 }
 /**
  * Check if data is valid
  *
  * @param AttributeInterface $attribute
  * @param mixed              $data
  */
 protected function checkData(AttributeInterface $attribute, $data)
 {
     if (!is_array($data)) {
         throw InvalidArgumentException::arrayExpected($attribute->getCode(), 'setter', 'metric', gettype($data));
     }
     if (!array_key_exists('data', $data)) {
         throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'data', 'setter', 'metric', print_r($data, true));
     }
     if (!array_key_exists('unit', $data)) {
         throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'unit', 'setter', 'metric', print_r($data, true));
     }
 }
 /**
  * Check if data are valid
  *
  * @param AttributeInterface $attribute
  * @param mixed              $data
  *
  * @return mixed
  */
 protected function checkData(AttributeInterface $attribute, $data)
 {
     if (!is_array($data)) {
         throw InvalidArgumentException::arrayExpected($attribute->getCode(), 'setter', 'prices collection', gettype($data));
     }
     foreach ($data as $price) {
         if (!is_array($price)) {
             throw InvalidArgumentException::arrayOfArraysExpected($attribute->getCode(), 'setter', 'prices collection', gettype($data));
         }
         if (!array_key_exists('data', $price)) {
             throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'data', 'setter', 'prices collection', print_r($data, true));
         }
         if (!array_key_exists('currency', $price)) {
             throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'currency', 'setter', 'prices collection', print_r($data, true));
         }
     }
 }
 /**
  * Check if data are valid
  *
  * @param AttributeInterface $attribute
  * @param mixed              $data
  *
  * @return mixed
  */
 protected function checkData(AttributeInterface $attribute, $data)
 {
     if (!is_array($data)) {
         throw InvalidArgumentException::arrayExpected($attribute->getCode(), 'adder', 'prices collection', gettype($data));
     }
     foreach ($data as $price) {
         if (!is_array($price)) {
             throw InvalidArgumentException::arrayOfArraysExpected($attribute->getCode(), 'adder', 'prices collection', gettype($data));
         }
         if (!array_key_exists('data', $price)) {
             throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'data', 'adder', 'prices collection', print_r($data, true));
         }
         if (!array_key_exists('currency', $price)) {
             throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'currency', 'adder', 'prices collection', print_r($data, true));
         }
         if (!is_numeric($price['data']) && null !== $price['data']) {
             throw InvalidArgumentException::arrayNumericKeyExpected($attribute->getCode(), 'data', 'adder', 'prices collection', gettype($price['data']));
         }
         if (!in_array($price['currency'], $this->currencyRepository->getActivatedCurrencyCodes())) {
             throw InvalidArgumentException::arrayInvalidKey($attribute->getCode(), 'currency', 'The currency does not exist', 'adder', 'prices collection', $price['currency']);
         }
     }
 }
 /**
  * @param AttributeInterface $attribute
  * @param mixed              $data
  */
 protected function checkData(AttributeInterface $attribute, $data)
 {
     if (null === $data) {
         return;
     }
     if (!is_array($data)) {
         throw InvalidArgumentException::arrayExpected($attribute->getCode(), 'setter', 'media', gettype($data));
     }
     if (!array_key_exists('originalFilename', $data)) {
         throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'originalFilename', 'setter', 'media', print_r($data, true));
     }
     if (!array_key_exists('filePath', $data)) {
         throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'filePath', 'setter', 'media', print_r($data, true));
     }
 }
 function it_throws_an_error_if_attribute_data_value_does_not_contain_currency_key(AttributeInterface $attribute, ProductInterface $product)
 {
     $attribute->getCode()->willReturn('attributeCode');
     $data = [['data' => 123, 'not the currency key' => 'euro']];
     $this->shouldThrow(InvalidArgumentException::arrayKeyExpected('attributeCode', 'currency', 'remover', 'prices collection', print_r($data, true)))->during('removeAttributeData', [$product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']]);
 }
示例#7
0
 /**
  * @param AttributeInterface $attribute
  * @param mixed              $data
  */
 protected function checkValue(AttributeInterface $attribute, $data)
 {
     if (!is_array($data)) {
         throw InvalidArgumentException::arrayExpected($attribute->getCode(), 'filter', 'price', gettype($data));
     }
     if (!array_key_exists('data', $data)) {
         throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'data', 'filter', 'price', print_r($data, true));
     }
     if (!array_key_exists('currency', $data)) {
         throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'currency', 'filter', 'price', print_r($data, true));
     }
     if (null !== $data['data'] && !is_numeric($data['data'])) {
         throw InvalidArgumentException::arrayNumericKeyExpected($attribute->getCode(), 'data', 'filter', 'price', gettype($data['data']));
     }
     if (!is_string($data['currency'])) {
         throw InvalidArgumentException::arrayStringKeyExpected($attribute->getCode(), 'currency', 'filter', 'price', gettype($data['currency']));
     }
     if (!in_array($data['currency'], $this->currencyRepository->getActivatedCurrencyCodes())) {
         throw InvalidArgumentException::arrayInvalidKey($attribute->getCode(), 'currency', 'The currency does not exist', 'filter', 'price', $data['currency']);
     }
 }
 function it_throws_an_error_if_there_is_no_unit_key_in_array(AttributeInterface $attribute, ProductInterface $product)
 {
     $attribute->getCode()->willReturn('attributeCode');
     $data = ['data' => 'data value'];
     $this->shouldThrow(InvalidArgumentException::arrayKeyExpected('attributeCode', 'unit', 'setter', 'metric', print_r($data, true)))->during('setAttributeData', [$product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']]);
 }
 /**
  * Check if value is valid
  *
  * @param AttributeInterface $attribute
  * @param mixed              $data
  */
 protected function checkValue(AttributeInterface $attribute, $data)
 {
     if (!is_array($data)) {
         throw InvalidArgumentException::arrayExpected($attribute->getCode(), 'filter', 'metric', gettype($data));
     }
     if (!array_key_exists('data', $data)) {
         throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'data', 'filter', 'metric', print_r($data, true));
     }
     if (!array_key_exists('unit', $data)) {
         throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'unit', 'filter', 'metric', print_r($data, true));
     }
     if (null !== $data['data'] && !is_numeric($data['data'])) {
         throw InvalidArgumentException::arrayNumericKeyExpected($attribute->getCode(), 'data', 'filter', 'metric', gettype($data['data']));
     }
     if (!is_string($data['unit'])) {
         throw InvalidArgumentException::arrayStringKeyExpected($attribute->getCode(), 'unit', 'filter', 'metric', gettype($data['unit']));
     }
     if (!array_key_exists($data['unit'], $this->measureManager->getUnitSymbolsForFamily($attribute->getMetricFamily()))) {
         throw InvalidArgumentException::arrayInvalidKey($attribute->getCode(), 'unit', sprintf('The unit does not exist in the attribute\'s family "%s"', $attribute->getMetricFamily()), 'filter', 'metric', $data['unit']);
     }
 }
 function it_throws_an_error_if_attribute_data_original_filename_is_missing(AttributeInterface $attribute, ProductInterface $product)
 {
     $attribute->getCode()->willReturn('attributeCode');
     $data = ['filePath' => realpath(__DIR__ . '/../../../../../../../features/Context/fixtures/akeneo.jpg')];
     $this->shouldThrow(InvalidArgumentException::arrayKeyExpected('attributeCode', 'originalFilename', 'setter', 'media', print_r($data, true)))->during('setAttributeData', [$product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']]);
 }
 function it_throws_an_exception_if_options_are_not_set_correctly()
 {
     $this->shouldThrow(InvalidArgumentException::arrayKeyExpected('completeness', 'locales', 'filter', 'completeness', print_r([], true)))->during('addFieldFilter', ['completeness', 'LOWER THAN ON ALL LOCALES', 100, null, 'mobile', []]);
     $this->shouldThrow(InvalidArgumentException::arrayOfArraysExpected('completeness', 'filter', 'completeness', print_r(['locales' => 'fr_FR'], true)))->during('addFieldFilter', ['completeness', 'LOWER THAN ON ALL LOCALES', 100, null, 'mobile', ['locales' => 'fr_FR']]);
 }
 /**
  * Check if options are valid for complex operators
  *      GREATER_OR_EQUALS_THAN_ON_ALL_LOCALES
  *      GREATER_THAN_ON_ALL_LOCALES
  *      LOWER_OR_EQUALS_THAN_ON_ALL_LOCALES
  *      LOWER_THAN_ON_ALL_LOCALES
  *
  * @param string $field
  * @param array  $options
  */
 protected function checkOptions($field, array $options)
 {
     if (!array_key_exists('locales', $options)) {
         throw InvalidArgumentException::arrayKeyExpected($field, 'locales', 'filter', 'completeness', print_r($options, true));
     }
     if (!isset($options['locales']) || !is_array($options['locales'])) {
         throw InvalidArgumentException::arrayOfArraysExpected($field, 'filter', 'completeness', print_r($options, true));
     }
 }
 /**
  * Check if data are valid
  * "data": doesn't need value
  *
  * @param AttributeInterface $attribute
  * @param mixed              $data
  *
  * @return mixed
  */
 protected function checkData(AttributeInterface $attribute, $data)
 {
     if (!is_array($data)) {
         throw InvalidArgumentException::arrayExpected($attribute->getCode(), 'remover', 'prices collection', gettype($data));
     }
     foreach ($data as $price) {
         if (!is_array($price)) {
             throw InvalidArgumentException::arrayOfArraysExpected($attribute->getCode(), 'remover', 'prices collection', gettype($data));
         }
         if (!array_key_exists('data', $price)) {
             throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'data', 'remover', 'prices collection', print_r($data, true));
         }
         if (!array_key_exists('currency', $price)) {
             throw InvalidArgumentException::arrayKeyExpected($attribute->getCode(), 'currency', 'remover', 'prices collection', print_r($data, true));
         }
         if (!in_array($price['currency'], $this->currencyManager->getActiveCodes())) {
             throw InvalidArgumentException::arrayInvalidKey($attribute->getCode(), 'currency', 'The currency does not exist', 'remover', 'prices collection', $price['currency']);
         }
     }
 }