/** * @test */ public function merge_should_merge_all_attributes() { $class_ = new ClassForMetadata(); $subclass_ = new SubClassForMetadata(); $metadata = new ClassMetadata(new \ReflectionClass($class_)); $submetadata = new ClassMetadata(new \ReflectionClass($subclass_)); $metadata->addAttributeMetadata(new PropertyMetadata(get_class($class_), 'attributeFirst')); $metadata->addAttributeMetadata(new PropertyMetadata(get_class($class_), 'attributeSecond')); $metadata->addAttributeMetadata(new MethodMetadata(get_class($class_), 'methodOne')); $submetadata->addAttributeMetadata(new MethodMetadata(get_class($subclass_), 'methodOne')); $submetadata->merge($metadata); $attributes = $submetadata->getAttributesMetadata(); $this->assertCount(3, $attributes); }
public function merge(MetadataInterface $object) { if (!$object instanceof self) { throw new InvalidArgumentException('$object must be an instance of ClassMetadata.'); } parent::merge($object); $this->preSerializeMethods = array_merge($object->preSerializeMethods, $this->preSerializeMethods); $this->postSerializeMethods = array_merge($object->postSerializeMethods, $this->postSerializeMethods); $this->postDeserializeMethods = array_merge($object->postDeserializeMethods, $this->postDeserializeMethods); $this->xmlRootName = $this->xmlRootName ?: $object->xmlRootName; $this->xmlRootNamespace = $this->xmlRootNamespace ?: $object->xmlRootNamespace; $this->xmlNamespaces = array_merge($object->xmlNamespaces, $this->xmlNamespaces); // Handler methods are not inherited if (!$this->accessorOrder && $object->accessorOrder) { $this->accessorOrder = $object->accessorOrder; $this->customOrder = $object->customOrder; } if ($this->discriminatorFieldName && $object->discriminatorFieldName && $this->discriminatorFieldName !== $object->discriminatorFieldName) { throw new \LogicException(sprintf('The discriminator of class "%s" would overwrite the discriminator of the parent class "%s". Please define all possible sub-classes in the discriminator of %s.', $this->getName(), $object->discriminatorBaseClass, $object->discriminatorBaseClass)); } $this->mergeDiscriminatorMap($object); $this->sortProperties(); }