/** * @param string $name * * @return Element * * @throws \RuntimeException */ public function getElement($name) { if (null === $this->pageObjectFactory) { throw new \RuntimeException('To create elements you need to pass a factory with setPageObjectFactory()'); } return $this->pageObjectFactory->createElement($name); }
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)); }
/** * {@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->create($parameterClassName); } } return $arguments; }
/** * @param string $name * * @return Element */ protected function createElement($name) { if (isset($this->elements[$name])) { return $this->factory->createInlineElement($this->elements[$name]); } return $this->factory->createElement($name); }
/** * {@inheritdoc} */ public function create($pageObjectClass) { try { return $this->instantiatePage($pageObjectClass); } catch (\InvalidArgumentException $exception) { return $this->decoratedFactory->create($pageObjectClass); } }
function it_delegates_instantiation_to_the_decorated_factory(AbstractLazyFactory $proxyFactory, LazyLoadingInterface $proxy, PageObject $pageObject, Factory $decoratedFactory) { $decoratedFactory->create('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->create('Acme\\Page'); }
function it_creates_a_page(Factory $factory, Page $page) { $factory->createPage('Home')->willReturn($page); $this->callGetPage('Home')->shouldReturn($page); }
/** * @param string|array * * @return InlineElement */ public function createInlineElement($selector) { return $this->decoratedFactory->createInlineElement($selector); }
/** * @param string $name * * @return Page */ protected function getPage($name) { return $this->factory->createPage($name); }
/** * @param string $pageObjectClass * * @return PageObject */ public function create($pageObjectClass) { return $this->defaultFactory->create($pageObjectClass); }
function it_should_create_an_element(PageObjectFactory $pageObjectFactory, Element $element) { $pageObjectFactory->createElement('Search box')->willReturn($element); $this->setPageObjectFactory($pageObjectFactory); $this->getElement('Search box')->shouldReturn($element); }