I need to add and later from context retrieve extra options/configuration from behat.yml file.
Behat is not allowing me to add some random parameters into behat.yml file, so I created new custom extension. This extension is allowing me to pass specific config values
extensions:
App\Behat\DevToolsExtension:
api_url: "https://api.example.com"
So now behat is not complaining about new configuration in behat.yml file.
Now I'm stuck. How can I retrieve this configuration from my extension in runtime?
I'm setting existing parameters in my extension within public function load(ContainerBuilder $container, array $config) method like so:
$container->setParameter($configKey . $key, $config[$key]);
Again, is there a way to retrieve this ContainerBuilder object or DevToolsExtension object in Context?
Edit
Solution was to create service container and pass behats ContainerBuilder into it like so:
class AppExtension implements ExtensionInterface
{
// ...
public function load(ContainerBuilder $container, array $config)
{
$configKey = $this->getConfigKey() . '.';
foreach ($this->keys as $key) {
$keyValue = $configKey . $key;
$container->setParameter($keyValue, $config[$key]);
}
$this->getServiceLocator()->setBehatContainer($container);
}
And then use service locator to retrieve config parameters
$value = $this->getBehatContainer()->getParameter($key);