Last active
August 29, 2015 14:10
-
-
Save gggeek/d71b10e21e0480a562cf to your computer and use it in GitHub Desktop.
Injecting Symfony services into Behat PageObjects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Kaliop\AProject\PageObjects\Pages; | |
use SensioLabs\Behat\PageObjectExtension\PageObject\Page; | |
use Behat\Mink\Session; | |
use SensioLabs\Behat\PageObjectExtension\PageObject\Factory; | |
abstract class BasePage extends Page | |
{ | |
protected $aService; | |
public function __construct(Session $session, Factory $factory, array $parameters = array()) | |
{ | |
parent::__construct($session, $factory, $parameters); | |
// The parameters arriving here come from behat.yml, but the Factory class from KTools adds some services | |
$this->aService = $parameters['services']['a_service']; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extensions: | |
Kaliop\Behat\KToolsExtension: ~ | |
SensioLabs\Behat\PageObjectExtension: | |
factory: | |
id: kaliop.ktools_extension.page_factory.serviceaware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Kaliop\Behat\KToolsExtension\PageObject\Factory; | |
use SensioLabs\Behat\PageObjectExtension\PageObject\Factory\DefaultFactory; | |
use Behat\Mink\Mink; | |
use SensioLabs\Behat\PageObjectExtension\PageObject\Factory\ClassNameResolver; | |
/** | |
* Allows us to pass Symfony services into PageObjects | |
*/ | |
class ServiceAwareFactory extends DefaultFactory | |
{ | |
public function __construct(Mink $mink, ClassNameResolver $classNameResolver, array $pageParameters, $services = array()) | |
{ | |
$pageParameters['services'] = $services; | |
parent::__construct($mink, $classNameResolver, $pageParameters); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
kaliop.ktools_extension.page_factory.serviceaware: | |
class: "%kaliop.ktools_extension.page_factory.serviceaware.class%" | |
arguments: [@mink, @sensio_labs.page_object_extension.class_name_resolver, %sensio_labs.page_object_extension.page_factory.page_parameters%, {a_service: @kaliop.ktools_extension.a.service}] | |
kaliop.ktools_extension.a.service | |
etc: ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment