/** * {@inheritdoc} */ public function getAttributes() { if (!$this->hasParent()) { return $this->attributes; } return new ArrayCollection(array_merge($this->parent->getAttributes()->toArray(), $this->attributes->toArray())); }
/** * @param ArchetypeInterface $archetype * @param AttributeSubjectInterface $subject */ private function createAndAssignAttributes(ArchetypeInterface $archetype, AttributeSubjectInterface $subject) { foreach ($archetype->getAttributes() as $attribute) { if (null === $subject->getAttributeByName($attribute->getName())) { /** @var AttributeValueInterface $attributeValue */ $attributeValue = $this->attributeValueRepository->createNew(); $attributeValue->setAttribute($attribute); $subject->addAttribute($attributeValue); } } }
function it_creates_new_values_only_for_non_existing_attributes($attributeValueFactory, ArchetypeInterface $archetype, ArchetypeSubjectInterface $subject, AttributeInterface $attribute, AttributeValueInterface $attributeValue, OptionInterface $option) { $archetype->getAttributes()->willReturn(array($attribute))->shouldBeCalled(); $archetype->getOptions()->willReturn(array($option))->shouldBeCalled(); $attribute->getCode()->willReturn('test'); $subject->getAttributeByCode('test')->shouldBeCalled()->willReturn($attributeValue); $attributeValueFactory->createNew()->shouldNotBeCalled(); $attributeValue->setAttribute($attribute)->shouldNotBeCalled(); $subject->getArchetype()->willReturn($archetype); $subject->addAttribute(Argument::any())->shouldNotBeCalled(); $subject->addOption($option)->shouldBeCalled(); $this->build($subject); }