Nelmio\Alice\Definition\Fixture\SimpleFixtureWithFlags::withSpecs PHP Method

withSpecs() public method

public withSpecs ( SpecificationBag $specs ) : self
$specs Nelmio\Alice\Definition\SpecificationBag
return self
    public function withSpecs(SpecificationBag $specs) : self
    {
        $clone = clone $this;
        $clone->fixture = $this->fixture->withSpecs($specs);
        return $clone;
    }

Usage Example

 public function testWithersReturnNewModifiedInstance()
 {
     $reference = 'user0';
     $specs = SpecificationBagFactory::create();
     $newSpecs = SpecificationBagFactory::create(new FakeMethodCall());
     $newDecoratedFixtureProphecy = $this->prophesize(FixtureInterface::class);
     $newDecoratedFixtureProphecy->getSpecs()->willReturn($newSpecs);
     /** @var FixtureInterface $newDecoratedFixture */
     $newDecoratedFixture = $newDecoratedFixtureProphecy->reveal();
     $decoratedFixtureProphecy = $this->prophesize(FixtureInterface::class);
     $decoratedFixtureProphecy->getId()->willReturn($reference);
     $decoratedFixtureProphecy->withSpecs($newSpecs)->willReturn($newDecoratedFixture);
     $decoratedFixtureProphecy->getSpecs()->willReturn($specs);
     /** @var FixtureInterface $decoratedFixture */
     $decoratedFixture = $decoratedFixtureProphecy->reveal();
     $flags = new FlagBag('user0');
     $fixture = new SimpleFixtureWithFlags($decoratedFixture, $flags);
     $newFixture = $fixture->withSpecs($newSpecs);
     $this->assertInstanceOf(SimpleFixtureWithFlags::class, $newFixture);
     $this->assertNotSame($fixture, $newFixture);
     $this->assertEquals($specs, $fixture->getSpecs());
     $this->assertEquals($flags, $fixture->getFlags());
     $this->assertEquals($newSpecs, $newFixture->getSpecs());
     $this->assertEquals($flags, $newFixture->getFlags());
 }