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]]]]); }
/** * @param string $field * @param array $data * @param array $items * * @throws InvalidArgumentException */ protected function checkAssociationItems($field, array $data, array $items) { foreach ($items as $code) { if (!is_string($code)) { throw InvalidArgumentException::associationFormatExpected($field, $data); } } }