withValue() public method

param ValueInterface|mixed $value
public withValue ( $value ) : self
return self
Ejemplo n.º 1
0
 public function testWithersReturnNewModifiedInstance()
 {
     $name = 'username';
     $definition = new Property($name, 'foo');
     $newDefinition = $definition->withValue(new \stdClass());
     $this->assertEquals(new Property($name, 'foo'), $definition);
     $this->assertEquals(new Property($name, new \stdClass()), $newDefinition);
 }
Ejemplo n.º 2
0
 public function testResolvesAllPropertyValues()
 {
     $object = new SimpleObject('dummy', new \stdClass());
     $set = ResolvedFixtureSetFactory::create(null, $fixtures = (new FixtureBag())->with($fixture = new SimpleFixture('dummy', \stdClass::class, new SpecificationBag(null, (new PropertyBag())->with($username = new Property('username', $usernameValue = new FakeValue()))->with($group = new Property('group', $groupValue = new FakeValue())), new MethodCallBag()))));
     $context = new GenerationContext();
     $context->markIsResolvingFixture('foo');
     $resolverProphecy = $this->prophesize(ValueResolverInterface::class);
     $setAfterFirstResolution = ResolvedFixtureSetFactory::create(new ParameterBag(['iteration' => 1]), $fixtures);
     $resolverProphecy->resolve($usernameValue, $fixture, $set, ['_instances' => $set->getObjects()->toArray()], $context)->willReturn(new ResolvedValueWithFixtureSet('Bob', $setAfterFirstResolution));
     $setAfterSecondResolution = ResolvedFixtureSetFactory::create(new ParameterBag(['iteration' => 2]), $fixtures);
     $resolverProphecy->resolve($groupValue, $fixture, $setAfterFirstResolution, ['_instances' => $set->getObjects()->toArray(), 'username' => 'Bob'], $context)->willReturn(new ResolvedValueWithFixtureSet('Badass', $setAfterSecondResolution));
     /** @var ValueResolverInterface $resolver */
     $resolver = $resolverProphecy->reveal();
     $hydratorProphecy = $this->prophesize(PropertyHydratorInterface::class);
     $newInstance = new \stdClass();
     $newInstance->username = '******';
     $newObject = $object->withInstance($newInstance);
     $hydratorProphecy->hydrate($object, $username->withValue('Bob'), $context)->willReturn($newObject);
     $secondNewInstance = clone $newInstance;
     $secondNewInstance->group = 'Badass';
     $secondNewObject = $object->withInstance($secondNewInstance);
     $hydratorProphecy->hydrate($newObject, $group->withValue('Badass'), $context)->willReturn($secondNewObject);
     /** @var PropertyHydratorInterface $hydrator */
     $hydrator = $hydratorProphecy->reveal();
     $expected = new ResolvedFixtureSet(new ParameterBag(['iteration' => 2]), $fixtures, new ObjectBag(['dummy' => $secondNewObject]));
     $hydrator = new SimpleHydrator($hydrator, $resolver);
     $actual = $hydrator->hydrate($object, $set, $context);
     $this->assertEquals($expected, $actual);
 }