Skip to content

Commit 22ada70

Browse files
author
Tibor Kotosz
authored
Add support for sensiolabs/behat-page-object-extension (#5)
1 parent 11a4701 commit 22ada70

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/Bex/Behat/Magento2Extension/HelperContainer/DelegatingSymfonyServiceContainer.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(array $symfonyServiceContainers)
2121

2222
public function has($id)
2323
{
24-
if (is_null($id)) {
24+
if (!$this->isSupportedServiceId($id)) {
2525
return false;
2626
}
2727

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

4141
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
4242
{
43+
if (!$this->isSupportedServiceId($id)) {
44+
return null;
45+
}
46+
4347
try {
4448
return parent::get($id);
4549
} catch (ServiceNotFoundException $e) {
@@ -84,4 +88,27 @@ public function compile(bool $resolveEnvPlaceholders = false)
8488

8589
parent::compile($resolveEnvPlaceholders);
8690
}
91+
92+
private function isSupportedServiceId($id)
93+
{
94+
if (is_null($id)) {
95+
return false;
96+
}
97+
98+
// If the Page Object Extension is used then let it handle the autowiring
99+
// @see \SensioLabs\Behat\PageObjectExtension\Context\Argument\PageObjectArgumentResolver::resolveArguments
100+
if ($this->isPageObject($id)) {
101+
return false;
102+
}
103+
104+
return true;
105+
}
106+
107+
private function isPageObject($id)
108+
{
109+
return (
110+
is_subclass_of($id, '\SensioLabs\Behat\PageObjectExtension\PageObject\Page') ||
111+
is_subclass_of($id, '\SensioLabs\Behat\PageObjectExtension\PageObject\Element')
112+
);
113+
}
87114
}

0 commit comments

Comments
 (0)