public resolve ( Nelmio\Alice\Definition\ValueInterface $value, Nelmio\Alice\FixtureInterface $fixture, |
||
$value | Nelmio\Alice\Definition\ValueInterface | |
$fixture | Nelmio\Alice\FixtureInterface | |
$fixtureSet | ||
$scope | array | |
$context | ||
return |
public function resolve(ValueInterface $value, FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, array $scope, GenerationContext $context) : ResolvedValueWithFixtureSet
{
if (null === $this->resolver) {
throw ResolverNotFoundExceptionFactory::createUnexpectedCall(__METHOD__);
}
$context->markAsNeedsCompleteGeneration();
$fixtureReferenceResult = $this->resolver->resolve($value->getReference(), $fixture, $fixtureSet, $scope, $context);
$context->unmarkAsNeedsCompleteGeneration();
/** @var ResolvedFixtureSet $fixtureSet */
list($instance, $fixtureSet) = [$fixtureReferenceResult->getValue(), $fixtureReferenceResult->getSet()];
try {
$propertyValue = $this->propertyAccessor->getValue($instance, $value->getProperty());
} catch (SymfonyNoSuchPropertyException $exception) {
throw NoSuchPropertyExceptionFactory::createForFixture($fixture, $value, 0, $exception);
} catch (\Exception $exception) {
throw UnresolvableValueExceptionFactory::create($value, 0, $exception);
}
return new ResolvedValueWithFixtureSet($propertyValue, $fixtureSet);
}
public function testThrowsAnExceptionIfResolvedReferenceHasNoSuchProperty() { try { $value = new FixturePropertyValue($reference = new FakeValue(), $property = 'prop'); $instance = new \stdClass(); $instance->prop = 'foo'; $set = ResolvedFixtureSetFactory::create(); $valueResolverProphecy = $this->prophesize(ValueResolverInterface::class); $valueResolverProphecy->resolve(Argument::cetera())->willReturn(new ResolvedValueWithFixtureSet(new \stdClass(), $set)); /** @var ValueResolverInterface $valueResolver */ $valueResolver = $valueResolverProphecy->reveal(); $resolver = new FixturePropertyReferenceResolver(PropertyAccess::createPropertyAccessor(), $valueResolver); $resolver->resolve($value, new SimpleFixture('dummy', 'Dummy', SpecificationBagFactory::create()), $set, [], new GenerationContext()); $this->fail('Expected exception to be thrown.'); } catch (NoSuchPropertyException $exception) { $this->assertEquals('Could not find the property "prop" of the object "dummy" (class: Dummy).', $exception->getMessage()); $this->assertEquals(0, $exception->getCode()); $this->assertNotNull($exception->getPrevious()); } }