function it_checks_valid_association_data_format(ProductInterface $product) { $this->shouldThrow(InvalidArgumentException::arrayExpected('associations', 'setter', 'association', 'string'))->during('setFieldData', [$product, 'associations', 'not an array']); $this->shouldThrow(InvalidArgumentException::associationFormatExpected('associations', [0 => []]))->during('setFieldData', [$product, 'associations', [0 => []]]); $this->shouldThrow(InvalidArgumentException::associationFormatExpected('associations', ['assoc_type_code' => []]))->during('setFieldData', [$product, 'associations', ['assoc_type_code' => []]]); $this->shouldThrow(InvalidArgumentException::associationFormatExpected('associations', ['assoc_type_code' => ['products' => [1], 'groups' => []]]))->during('setFieldData', [$product, 'associations', ['assoc_type_code' => ['products' => [1], 'groups' => []]]]); $this->shouldThrow(InvalidArgumentException::associationFormatExpected('associations', ['assoc_type_code' => ['products' => [], 'groups' => [2]]]))->during('setFieldData', [$product, 'associations', ['assoc_type_code' => ['products' => [], 'groups' => [2]]]]); }
function it_throws_an_exception_if_value_is_not_a_valid_array(AttributeInterface $attribute) { $attribute->getId()->willReturn(1); $attribute->getCode()->willReturn('color'); $value = 'string'; $this->shouldThrow(InvalidArgumentException::arrayExpected('color', 'filter', 'reference_data', $value))->during('addAttributeFilter', [$attribute, '=', $value, null, null, ['field' => 'color']]); $value = ['foo']; $this->shouldThrow(InvalidArgumentException::numericExpected('color', 'filter', 'reference_data', 'string'))->during('addAttributeFilter', [$attribute, '=', $value, null, null, ['field' => 'color']]); }
/** * Check if data are valid * * @param string $field * @param mixed $data */ protected function checkData($field, $data) { if (!is_array($data)) { throw InvalidArgumentException::arrayExpected($field, 'remover', 'category', gettype($data)); } foreach ($data as $key => $value) { if (!is_string($value)) { throw InvalidArgumentException::arrayStringValueExpected($field, $key, 'remover', 'category', gettype($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', 'reference data collection', gettype($data)); } foreach ($data as $key => $value) { if (!is_string($value)) { throw InvalidArgumentException::arrayStringKeyExpected($attribute->getCode(), $key, 'setter', 'reference data collection', gettype($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(), 'adder', 'multi select', gettype($data)); } foreach ($data as $key => $value) { if (!is_string($value)) { throw InvalidArgumentException::arrayStringValueExpected($attribute->getCode(), $key, 'adder', 'multi select', gettype($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 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)); } if (!is_string($data['unit'])) { throw InvalidArgumentException::arrayStringValueExpected($attribute->getCode(), 'unit', 'setter', 'metric', $data['unit']); } if (!array_key_exists($data['unit'], $this->measureManager->getUnitSymbolsForFamily($attribute->getMetricFamily()))) { throw InvalidArgumentException::arrayInvalidKey($attribute->getCode(), 'unit', 'The unit does not exist', 'setter', 'metric', $data['unit']); } }
/** * 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']); } } }
/** * 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 (!is_numeric($data['data']) && null !== $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_checks_valid_data_format(ProductInterface $product) { $this->shouldThrow(InvalidArgumentException::arrayExpected('categories', 'setter', 'category', 'string'))->during('setFieldData', [$product, 'categories', 'not an array']); $this->shouldThrow(InvalidArgumentException::arrayStringValueExpected('categories', 0, 'setter', 'category', 'array'))->during('setFieldData', [$product, 'categories', [['array of array']]]); }
function it_throws_an_error_if_data_is_not_an_array(AttributeInterface $attribute, ProductInterface $product) { $attribute->getCode()->willReturn('attributeCode'); $data = 'not an array'; $this->shouldThrow(InvalidArgumentException::arrayExpected('attributeCode', 'setter', 'prices collection', gettype($data)))->during('setAttributeData', [$product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']]); }
function it_throws_an_error_if_data_is_not_an_array_or_null(AttributeInterface $attribute) { $attribute->getCode()->willReturn('attributeCode'); $data = new \stdClass(); $this->shouldThrow(InvalidArgumentException::arrayExpected('attributeCode', 'setter', 'media', gettype($data)))->during('setValue', [[], $attribute, $data, 'fr_FR', 'mobile']); }
function it_throws_an_exception_if_value_is_not_an_array(AttributeInterface $attribute) { $attribute->getCode()->willReturn('options_code'); $this->shouldThrow(InvalidArgumentException::arrayExpected('options_code', 'filter', 'options', gettype('WRONG')))->during('addAttributeFilter', [$attribute, 'IN', 'WRONG', null, null, ['field' => 'options_code.id']]); }
function it_throws_an_exception_if_values_in_array_are_not_integers() { $this->shouldThrow(InvalidArgumentException::arrayExpected('groups', 'filter', 'groups', gettype('WRONG')))->during('addFieldFilter', ['groups', 'IN', 'WRONG']); }
/** * Check if data are valid * * @param string $field * @param mixed $data * * @throws InvalidArgumentException */ protected function checkData($field, $data) { if (!is_array($data)) { throw InvalidArgumentException::arrayExpected($field, 'adder', 'association', gettype($data)); } foreach ($data as $assocTypeCode => $items) { $this->checkAssociationData($field, $data, $assocTypeCode, $items); } }
/** * @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 (!is_numeric($data['data']) && null !== $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->currencyManager->getActiveCodes())) { throw InvalidArgumentException::arrayInvalidKey($attribute->getCode(), 'currency', 'The currency does not exist', 'filter', 'price', $data['currency']); } }
/** * Check if value is an array * * @param string $field * @param mixed $value * @param string $filter */ public static function checkArray($field, $value, $filter) { if (!is_array($value)) { throw InvalidArgumentException::arrayExpected(static::getCode($field), 'filter', $filter, gettype($value)); } }
/** * @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_exception_if_value_is_not_an_array() { $this->shouldThrow(InvalidArgumentException::arrayExpected('family', 'filter', 'family', gettype('not an array')))->during('addFieldFilter', ['family', 'IN', 'not an array']); }