Nelmio\Alice\Definition\SpecificationBag::mergeWith PHP Метод

mergeWith() публичный Метод

Creates a new instance to which the given specs have been merged. In case of conflicts, the existing values are kept.
public mergeWith ( self $specs ) : self
$specs self
Результат self
    public function mergeWith(self $specs) : self
    {
        $clone = clone $this;
        if (null === $clone->constructor) {
            $clone->constructor = $specs->constructor;
        }
        $clone->properties = $this->properties->mergeWith($specs->properties);
        $clone->calls = $this->calls->mergeWith($specs->calls);
        return $clone;
    }

Usage Example

Пример #1
0
 /**
  * @testdox Merging a bag that has a constructor method with a new one that has one as well, the result will kept its constructor method.
  */
 public function testMergeTwoBags2()
 {
     $constructorA = new SimpleMethodCall('childCreate', []);
     $constructorB = new SimpleMethodCall('parentCreate', []);
     $bagA = new SpecificationBag($constructorA, new PropertyBag(), new MethodCallBag());
     $bagB = new SpecificationBag($constructorB, new PropertyBag(), new MethodCallBag());
     $bag = $bagA->mergeWith($bagB);
     $this->assertEquals($constructorA, $bagA->getConstructor());
     $this->assertEquals($constructorB, $bagB->getConstructor());
     $this->assertEquals($constructorA, $bag->getConstructor());
 }