Nelmio\Alice\Definition\SpecificationBag::withConstructor PHP Method

withConstructor() public method

public withConstructor ( Nelmio\Alice\Definition\MethodCallInterface $constructor = null ) : self
$constructor Nelmio\Alice\Definition\MethodCallInterface
return self
    public function withConstructor(MethodCallInterface $constructor = null) : self
    {
        $clone = clone $this;
        $clone->constructor = $constructor;
        return $clone;
    }

Usage Example

Example #1
0
 public function testWithersReturnNewModifiedInstance()
 {
     $constructor = null;
     $properties = new PropertyBag();
     $calls = new MethodCallBag();
     $bag = new SpecificationBag($constructor, $properties, $calls);
     $newConstructor = new FakeMethodCall();
     $newBag = $bag->withConstructor($newConstructor);
     $this->assertInstanceOf(SpecificationBag::class, $newBag);
     $this->assertEquals($constructor, $bag->getConstructor());
     $this->assertEquals($calls, $bag->getMethodCalls());
     $this->assertEquals($properties, $bag->getProperties());
     $this->assertEquals(new FakeMethodCall(), $newBag->getConstructor());
     $this->assertEquals($calls, $newBag->getMethodCalls());
     $this->assertEquals($properties, $newBag->getProperties());
 }