/**
  * {@inheritdoc}
  *
  * @return Group
  */
 protected function createEntity(array $data)
 {
     $group = new Group();
     $group->setCode($data['code']);
     $type = new GroupType();
     $type->setCode($data['type']);
     $type->setVariant($data['type'] === 'VARIANT');
     $group->setType($type);
     foreach ($this->getLabels($data) as $locale => $label) {
         $translation = $group->getTranslation($locale);
         $translation->setLabel($label);
         $group->addTranslation($translation);
     }
     foreach ($this->getAttributes($data) as $attribute) {
         $group->addAttribute($attribute);
     }
     return $group;
 }
 function it_skips_a_group_when_object_is_invalid($groupConverter, $repository, $groupUpdater, $validator, GroupInterface $group, ConstraintViolationListInterface $violationList)
 {
     $repository->getIdentifierProperties()->willReturn(['code']);
     $repository->findOneByIdentifier(Argument::any())->willReturn($group);
     $groupType = new GroupType();
     $groupType->setVariant(false);
     $group->getType()->willReturn($groupType);
     $group->getId()->willReturn(42);
     $group->getProductTemplate()->willReturn(null);
     $values = $this->getValues();
     $groupConverter->convert($values['original_values'])->willReturn($values['converted_values']);
     $groupUpdater->update($group, $values['converted_values'])->shouldBeCalled();
     $validator->validate($group)->willReturn($violationList);
     $this->process($values['original_values'])->shouldReturn($group);
     $groupUpdater->update($group, $values['converted_values'])->willThrow(new \InvalidArgumentException());
     $violation = new ConstraintViolation('Error', 'foo', [], 'bar', 'code', 'mycode');
     $violations = new ConstraintViolationList([$violation]);
     $validator->validate($group)->willReturn($violations);
     $this->shouldThrow('Akeneo\\Bundle\\BatchBundle\\Item\\InvalidItemException')->during('process', [$values['original_values']]);
 }
 function it_skips_a_variant_group_when_object_is_invalid($repository, $variantUpdater, $validator, GroupInterface $variantGroup, ProductTemplateInterface $productTemplate, ConstraintViolationListInterface $violationList)
 {
     $repository->getIdentifierProperties()->willReturn(['code']);
     $repository->findOneByIdentifier(Argument::any())->willReturn($variantGroup);
     $groupType = new GroupType();
     $groupType->setVariant(true);
     $productTemplate->getValues()->willReturn(new ArrayCollection());
     $variantGroup->getType()->willReturn($groupType);
     $variantGroup->getId()->willReturn(42);
     $variantGroup->getProductTemplate()->willReturn($productTemplate);
     $values = $this->getValues();
     $variantUpdater->update($variantGroup, $values)->shouldBeCalled();
     $validator->validate($variantGroup)->willReturn($violationList);
     $this->process($values)->shouldReturn($variantGroup);
     $variantUpdater->update($variantGroup, $values)->willThrow(new \InvalidArgumentException('Attributes: This property cannot be changed.'));
     $violation = new ConstraintViolation('Error', 'foo', [], 'bar', 'code', 'mycode');
     $violations = new ConstraintViolationList([$violation]);
     $validator->validate($variantGroup)->willReturn($violations);
     $this->shouldThrow('Akeneo\\Component\\Batch\\Item\\InvalidItemException')->during('process', [$values]);
 }
 /**
  * @param string $code
  * @param string $label
  * @param bool   $isVariant
  *
  * @return \Pim\Bundle\CatalogBundle\Model\GroupTypeInterface
  */
 protected function createGroupType($code, $label, $isVariant)
 {
     $type = new GroupType();
     $type->setCode($code);
     $type->setVariant($isVariant);
     $type->setLocale('en_US')->setLabel($label);
     $this->validate($type);
     $this->persist($type);
     return $type;
 }
 /**
  * {@inheritDoc}
  */
 public function setVariant($variant)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setVariant', array($variant));
     return parent::setVariant($variant);
 }
 /**
  * @param string $code
  * @param string $label
  * @param bool   $isVariant
  *
  * @return \Pim\Component\Catalog\Model\GroupTypeInterface
  */
 protected function createGroupType($code, $label, $isVariant)
 {
     $type = new GroupType();
     $type->setCode($code);
     $type->setVariant($isVariant);
     $type->setLocale('en_US')->setLabel($label);
     $this->validate($type);
     $this->getContainer()->get('pim_catalog.saver.group_type')->save($type);
     return $type;
 }