/** * {@inheritdoc} */ public function resolveArguments(\ReflectionClass $classReflection, array $arguments) { $parameters = $this->getConstructorParameters($classReflection); foreach ($parameters as $i => $parameter) { $parameterClassName = $this->getClassName($parameter); if (null !== $parameterClassName && $this->isPageOrElement($parameterClassName)) { $arguments[$i] = $this->factory->instantiate($parameterClassName); } } return $arguments; }
function it_resolves_an_argument_if_it_is_an_element_type(Factory $factory, \ReflectionClass $class, \ReflectionMethod $constructor, \ReflectionParameter $anyParameter, \ReflectionParameter $elementParameter, \ReflectionClass $elementParameterClass, MyElement $element) { $constructor->getParameters()->willReturn(array($anyParameter, $elementParameter)); $elementParameter->getClass()->willReturn($elementParameterClass); $elementParameterClass->getName()->willReturn('spec\\SensioLabs\\Behat\\PageObjectExtension\\Context\\Argument\\MyElement'); $factory->instantiate('spec\\SensioLabs\\Behat\\PageObjectExtension\\Context\\Argument\\MyElement')->willReturn($element); $this->resolveArguments($class, array())->shouldReturn(array(1 => $element)); }
function it_delegates_instantiation_to_the_decorated_factory(AbstractLazyFactory $proxyFactory, LazyLoadingInterface $proxy, PageObject $pageObject, Factory $decoratedFactory) { $decoratedFactory->instantiate('Acme\\Page')->willReturn($pageObject); $proxyFactory->createProxy(Argument::any(), Argument::that(function ($callback) use($proxy, $pageObject) { $wrappedObject = new \stdClass(); $initializer = function () { }; $result = $callback($wrappedObject, $proxy->getWrappedObject(), null, array(), $initializer); if ($wrappedObject !== $pageObject->getWrappedObject()) { throw new \LogicException('Expected the proxy to be overwritten with the actual object'); } if (null !== $initializer) { throw new \LogicException('Expected the initializer callback to be set to null'); } return $result; }))->shouldBeCalled(); $this->instantiate('Acme\\Page'); }
/** * @param string $class * * @return PageObject */ public function instantiate($class) { return $this->defaultFactory->instantiate($class); }