Skip to content

Commit

Permalink
Add support for sensiolabs/behat-page-object-extension (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibor Kotosz authored Apr 4, 2020
1 parent 11a4701 commit 22ada70
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(array $symfonyServiceContainers)

public function has($id)
{
if (is_null($id)) {
if (!$this->isSupportedServiceId($id)) {
return false;
}

Expand All @@ -40,6 +40,10 @@ public function has($id)

public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
{
if (!$this->isSupportedServiceId($id)) {
return null;
}

try {
return parent::get($id);
} catch (ServiceNotFoundException $e) {
Expand Down Expand Up @@ -84,4 +88,27 @@ public function compile(bool $resolveEnvPlaceholders = false)

parent::compile($resolveEnvPlaceholders);
}

private function isSupportedServiceId($id)
{
if (is_null($id)) {
return false;
}

// If the Page Object Extension is used then let it handle the autowiring
// @see \SensioLabs\Behat\PageObjectExtension\Context\Argument\PageObjectArgumentResolver::resolveArguments
if ($this->isPageObject($id)) {
return false;
}

return true;
}

private function isPageObject($id)
{
return (
is_subclass_of($id, '\SensioLabs\Behat\PageObjectExtension\PageObject\Page') ||
is_subclass_of($id, '\SensioLabs\Behat\PageObjectExtension\PageObject\Element')
);
}
}

0 comments on commit 22ada70

Please sign in to comment.