Nelmio\Alice\Generator\Resolver\Value\ValueResolverRegistryTest::testPicksTheFirstSuitableResolverToResolveTheGivenValue PHP Method

testPicksTheFirstSuitableResolverToResolveTheGivenValue() public method

    public function testPicksTheFirstSuitableResolverToResolveTheGivenValue()
    {
        $value = new FakeValue();
        $fixture = new FakeFixture();
        $set = ResolvedFixtureSetFactory::create();
        $scope = ['scope' => 'epocs'];
        $context = new GenerationContext();
        $context->markIsResolvingFixture('foo');
        $expected = new ResolvedValueWithFixtureSet(10, ResolvedFixtureSetFactory::create(null, null, (new ObjectBag())->with(new SimpleObject('dummy', new \stdClass()))));
        $instantiator1Prophecy = $this->prophesize(ChainableValueResolverInterface::class);
        $instantiator1Prophecy->canResolve($value)->willReturn(false);
        /* @var ChainableValueResolverInterface $instantiator1 */
        $instantiator1 = $instantiator1Prophecy->reveal();
        $instantiator2Prophecy = $this->prophesize(ChainableValueResolverInterface::class);
        $instantiator2Prophecy->canResolve($value)->willReturn(true);
        $instantiator2Prophecy->resolve($value, $fixture, $set, $scope, $context)->willReturn($expected);
        /* @var ChainableValueResolverInterface $instantiator2 */
        $instantiator2 = $instantiator2Prophecy->reveal();
        $instantiator3Prophecy = $this->prophesize(ChainableValueResolverInterface::class);
        $instantiator3Prophecy->canResolve(Argument::any())->shouldNotBeCalled();
        /* @var ChainableValueResolverInterface $instantiator3 */
        $instantiator3 = $instantiator3Prophecy->reveal();
        $registry = new ValueResolverRegistry([$instantiator1, $instantiator2, $instantiator3]);
        $actual = $registry->resolve($value, $fixture, $set, $scope, $context);
        $this->assertSame($expected, $actual);
        $instantiator1Prophecy->canResolve(Argument::any())->shouldHaveBeenCalledTimes(1);
        $instantiator2Prophecy->canResolve(Argument::any())->shouldHaveBeenCalledTimes(1);
        $instantiator2Prophecy->resolve(Argument::cetera())->shouldHaveBeenCalledTimes(1);
    }