Nelmio\Alice\Generator\Hydrator\SimpleHydratorTest::testResolvesAllPropertyValues PHP Метод

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

    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 = 'Bob';
        $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);
    }