コード例 #1
0
 /**
  * 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(), 'remover', 'multi select', gettype($data));
     }
     foreach ($data as $key => $value) {
         if (!is_string($value)) {
             throw InvalidArgumentException::arrayStringValueExpected($attribute->getCode(), $key, 'remover', 'multi select', gettype($value));
         }
     }
 }
コード例 #2
0
 /**
  * Check if data are valid
  *
  * @param string $field
  * @param mixed  $data
  */
 protected function checkData($field, $data)
 {
     if (!is_array($data)) {
         throw InvalidArgumentException::arrayExpected($field, 'adder', 'groups', gettype($data));
     }
     foreach ($data as $key => $value) {
         if (!is_string($value)) {
             throw InvalidArgumentException::arrayStringValueExpected($field, $key, 'adder', 'groups', gettype($value));
         }
     }
 }
コード例 #3
0
 function it_checks_valid_data_format(ProductInterface $product)
 {
     $this->shouldThrow(InvalidArgumentException::arrayExpected('categories', 'adder', 'category', 'string'))->during('addFieldData', [$product, 'categories', 'not an array']);
     $this->shouldThrow(InvalidArgumentException::arrayStringValueExpected('categories', 0, 'adder', 'category', 'array'))->during('addFieldData', [$product, 'categories', [['array of array']]]);
 }
コード例 #4
0
 function it_throws_an_error_if_attribute_data_is_not_an_array_of_option_codes(AttributeInterface $attribute, ProductInterface $product)
 {
     $attribute->getCode()->willReturn('attributeCode');
     $data = ['foo' => ['bar' => 'baz']];
     $this->shouldThrow(InvalidArgumentException::arrayStringValueExpected('attributeCode', 'foo', 'setter', 'multi select', 'array'))->during('setAttributeData', [$product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']]);
 }
コード例 #5
0
 function it_should_throws_an_error_if_attribute_data_value_array_is_not_string(AttributeInterface $attribute, ProductInterface $product)
 {
     $attribute->getCode()->willReturn('attributeCode');
     $data = [0];
     $this->shouldThrow(InvalidArgumentException::arrayStringValueExpected('attributeCode', 0, 'remover', 'multi select', gettype($data[0])))->during('removeAttributeData', [$product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']]);
 }