Inheritance: implements Nelmio\Alice\ObjectInterface
Beispiel #1
0
 public function testNamedConstructor()
 {
     $reference = 'user0';
     $instance = StdClassFactory::create(['original' => true]);
     $originalInstance = clone $instance;
     $object = new SimpleObject($reference, $instance);
     $newInstance = StdClassFactory::create(['original' => false]);
     $originalNewInstance = clone $newInstance;
     $newObject = $object->withInstance($newInstance);
     $this->assertEquals(new SimpleObject($reference, $originalInstance), $object);
     $this->assertEquals(new SimpleObject($reference, $originalNewInstance), $newObject);
 }
Beispiel #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);
 }